aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2014-11-12 09:42:39 -0500
committerJohannes Berg <johannes.berg@intel.com>2014-11-19 12:59:32 -0500
commitc449981c4761f16d57db70834bee0380c7c97f18 (patch)
treee218897a692079236c3d20221207ebe22819b160
parent18e5ca65e55da4cacd9deb4e934eb5429bb4b79d (diff)
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>
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index c88a21acda64..3cb825b3ef17 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -2123,36 +2123,26 @@ static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
2123 HWSIM_MCGRP_CONFIG, GFP_KERNEL); 2123 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
2124} 2124}
2125 2125
2126static struct sk_buff *build_radio_msg(int cmd, int id, 2126static int append_radio_msg(struct sk_buff *skb, int id,
2127 struct hwsim_new_radio_params *param) 2127 struct hwsim_new_radio_params *param)
2128{ 2128{
2129 struct sk_buff *skb;
2130 void *data;
2131 int ret; 2129 int ret;
2132 2130
2133 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
2134 if (!skb)
2135 return NULL;
2136
2137 data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, cmd);
2138 if (!data)
2139 goto error;
2140
2141 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id); 2131 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
2142 if (ret < 0) 2132 if (ret < 0)
2143 goto error; 2133 return ret;
2144 2134
2145 if (param->channels) { 2135 if (param->channels) {
2146 ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels); 2136 ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
2147 if (ret < 0) 2137 if (ret < 0)
2148 goto error; 2138 return ret;
2149 } 2139 }
2150 2140
2151 if (param->reg_alpha2) { 2141 if (param->reg_alpha2) {
2152 ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2, 2142 ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
2153 param->reg_alpha2); 2143 param->reg_alpha2);
2154 if (ret < 0) 2144 if (ret < 0)
2155 goto error; 2145 return ret;
2156 } 2146 }
2157 2147
2158 if (param->regd) { 2148 if (param->regd) {
@@ -2165,54 +2155,64 @@ static struct sk_buff *build_radio_msg(int cmd, int id,
2165 if (i < ARRAY_SIZE(hwsim_world_regdom_custom)) { 2155 if (i < ARRAY_SIZE(hwsim_world_regdom_custom)) {
2166 ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i); 2156 ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
2167 if (ret < 0) 2157 if (ret < 0)
2168 goto error; 2158 return ret;
2169 } 2159 }
2170 } 2160 }
2171 2161
2172 if (param->reg_strict) { 2162 if (param->reg_strict) {
2173 ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG); 2163 ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
2174 if (ret < 0) 2164 if (ret < 0)
2175 goto error; 2165 return ret;
2176 } 2166 }
2177 2167
2178 if (param->p2p_device) { 2168 if (param->p2p_device) {
2179 ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE); 2169 ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
2180 if (ret < 0) 2170 if (ret < 0)
2181 goto error; 2171 return ret;
2182 } 2172 }
2183 2173
2184 if (param->use_chanctx) { 2174 if (param->use_chanctx) {
2185 ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX); 2175 ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
2186 if (ret < 0) 2176 if (ret < 0)
2187 goto error; 2177 return ret;
2188 } 2178 }
2189 2179
2190 if (param->hwname) { 2180 if (param->hwname) {
2191 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, 2181 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
2192 strlen(param->hwname), param->hwname); 2182 strlen(param->hwname), param->hwname);
2193 if (ret < 0) 2183 if (ret < 0)
2194 goto error; 2184 return ret;
2195 } 2185 }
2196 2186
2197 genlmsg_end(skb, data); 2187 return 0;
2198
2199 return skb;
2200
2201error:
2202 nlmsg_free(skb);
2203 return NULL;
2204} 2188}
2205 2189
2206static void hswim_mcast_new_radio(int id, struct genl_info *info, 2190static void hwsim_mcast_new_radio(int id, struct genl_info *info,
2207 struct hwsim_new_radio_params *param) 2191 struct hwsim_new_radio_params *param)
2208{ 2192{
2209 struct sk_buff *mcast_skb; 2193 struct sk_buff *mcast_skb;
2194 void *data;
2210 2195
2211 mcast_skb = build_radio_msg(HWSIM_CMD_NEW_RADIO, id, param); 2196 mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
2212 if (!mcast_skb) 2197 if (!mcast_skb)
2213 return; 2198 return;
2214 2199
2200 data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0,
2201 HWSIM_CMD_NEW_RADIO);
2202 if (!data)
2203 goto out_err;
2204
2205 if (append_radio_msg(mcast_skb, id, param) < 0)
2206 goto out_err;
2207
2208 genlmsg_end(mcast_skb, data);
2209
2215 hwsim_mcast_config_msg(mcast_skb, info); 2210 hwsim_mcast_config_msg(mcast_skb, info);
2211 return;
2212
2213out_err:
2214 genlmsg_cancel(mcast_skb, data);
2215 nlmsg_free(mcast_skb);
2216} 2216}
2217 2217
2218static int mac80211_hwsim_new_radio(struct genl_info *info, 2218static int mac80211_hwsim_new_radio(struct genl_info *info,
@@ -2459,7 +2459,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
2459 spin_unlock_bh(&hwsim_radio_lock); 2459 spin_unlock_bh(&hwsim_radio_lock);
2460 2460
2461 if (idx > 0) 2461 if (idx > 0)
2462 hswim_mcast_new_radio(idx, info, param); 2462 hwsim_mcast_new_radio(idx, info, param);
2463 2463
2464 return idx; 2464 return idx;
2465 2465