mac80211-hwsim: Factor out netlink attribute appending
Factor out netlink message attribute appending in order to reuse it with later code. As a result move netlink skb allocation to the calling function. Signed-off-by: Patrik Flykt <patrik.flykt@linux.intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
parent
18e5ca65e5
commit
c449981c47
1 changed files with 30 additions and 30 deletions
|
@ -2123,36 +2123,26 @@ static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
|
||||||
HWSIM_MCGRP_CONFIG, GFP_KERNEL);
|
HWSIM_MCGRP_CONFIG, GFP_KERNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sk_buff *build_radio_msg(int cmd, int id,
|
static int append_radio_msg(struct sk_buff *skb, int id,
|
||||||
struct hwsim_new_radio_params *param)
|
struct hwsim_new_radio_params *param)
|
||||||
{
|
{
|
||||||
struct sk_buff *skb;
|
|
||||||
void *data;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
|
||||||
if (!skb)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, cmd);
|
|
||||||
if (!data)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
|
ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
|
|
||||||
if (param->channels) {
|
if (param->channels) {
|
||||||
ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
|
ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->reg_alpha2) {
|
if (param->reg_alpha2) {
|
||||||
ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
|
ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
|
||||||
param->reg_alpha2);
|
param->reg_alpha2);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->regd) {
|
if (param->regd) {
|
||||||
|
@ -2165,54 +2155,64 @@ static struct sk_buff *build_radio_msg(int cmd, int id,
|
||||||
if (i < ARRAY_SIZE(hwsim_world_regdom_custom)) {
|
if (i < ARRAY_SIZE(hwsim_world_regdom_custom)) {
|
||||||
ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
|
ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->reg_strict) {
|
if (param->reg_strict) {
|
||||||
ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
|
ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->p2p_device) {
|
if (param->p2p_device) {
|
||||||
ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
|
ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->use_chanctx) {
|
if (param->use_chanctx) {
|
||||||
ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
|
ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->hwname) {
|
if (param->hwname) {
|
||||||
ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
|
ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
|
||||||
strlen(param->hwname), param->hwname);
|
strlen(param->hwname), param->hwname);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
genlmsg_end(skb, data);
|
return 0;
|
||||||
|
|
||||||
return skb;
|
|
||||||
|
|
||||||
error:
|
|
||||||
nlmsg_free(skb);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hswim_mcast_new_radio(int id, struct genl_info *info,
|
static void hwsim_mcast_new_radio(int id, struct genl_info *info,
|
||||||
struct hwsim_new_radio_params *param)
|
struct hwsim_new_radio_params *param)
|
||||||
{
|
{
|
||||||
struct sk_buff *mcast_skb;
|
struct sk_buff *mcast_skb;
|
||||||
|
void *data;
|
||||||
|
|
||||||
mcast_skb = build_radio_msg(HWSIM_CMD_NEW_RADIO, id, param);
|
mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
||||||
if (!mcast_skb)
|
if (!mcast_skb)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0,
|
||||||
|
HWSIM_CMD_NEW_RADIO);
|
||||||
|
if (!data)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
if (append_radio_msg(mcast_skb, id, param) < 0)
|
||||||
|
goto out_err;
|
||||||
|
|
||||||
|
genlmsg_end(mcast_skb, data);
|
||||||
|
|
||||||
hwsim_mcast_config_msg(mcast_skb, info);
|
hwsim_mcast_config_msg(mcast_skb, info);
|
||||||
|
return;
|
||||||
|
|
||||||
|
out_err:
|
||||||
|
genlmsg_cancel(mcast_skb, data);
|
||||||
|
nlmsg_free(mcast_skb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mac80211_hwsim_new_radio(struct genl_info *info,
|
static int mac80211_hwsim_new_radio(struct genl_info *info,
|
||||||
|
@ -2459,7 +2459,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
|
||||||
spin_unlock_bh(&hwsim_radio_lock);
|
spin_unlock_bh(&hwsim_radio_lock);
|
||||||
|
|
||||||
if (idx > 0)
|
if (idx > 0)
|
||||||
hswim_mcast_new_radio(idx, info, param);
|
hwsim_mcast_new_radio(idx, info, param);
|
||||||
|
|
||||||
return idx;
|
return idx;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue