diff options
author | Johannes Berg <johannes.berg@intel.com> | 2012-12-03 10:59:46 -0500 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2013-01-03 07:01:20 -0500 |
commit | e9763c3c295a8b31316e16558b58b226e005b160 (patch) | |
tree | e132203edc7265cb23ace6404c9f8b03ad870d7c /net/wireless/reg.c | |
parent | 74f53cd8d4474f9ba91c7309feabebae80a60089 (diff) |
regulatory: clean up reg_copy_regd()
Use ERR_PTR/IS_ERR to return the result or errors,
also do some code cleanups.
Acked-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/wireless/reg.c')
-rw-r--r-- | net/wireless/reg.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/net/wireless/reg.c b/net/wireless/reg.c index d52ffa2abc3f..52a3598859cd 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c | |||
@@ -311,11 +311,11 @@ static bool is_user_regdom_saved(void) | |||
311 | return true; | 311 | return true; |
312 | } | 312 | } |
313 | 313 | ||
314 | static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, | 314 | static const struct ieee80211_regdomain * |
315 | const struct ieee80211_regdomain *src_regd) | 315 | reg_copy_regd(const struct ieee80211_regdomain *src_regd) |
316 | { | 316 | { |
317 | struct ieee80211_regdomain *regd; | 317 | struct ieee80211_regdomain *regd; |
318 | int size_of_regd = 0; | 318 | int size_of_regd; |
319 | unsigned int i; | 319 | unsigned int i; |
320 | 320 | ||
321 | size_of_regd = | 321 | size_of_regd = |
@@ -324,16 +324,15 @@ static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, | |||
324 | 324 | ||
325 | regd = kzalloc(size_of_regd, GFP_KERNEL); | 325 | regd = kzalloc(size_of_regd, GFP_KERNEL); |
326 | if (!regd) | 326 | if (!regd) |
327 | return -ENOMEM; | 327 | return ERR_PTR(-ENOMEM); |
328 | 328 | ||
329 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); | 329 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); |
330 | 330 | ||
331 | for (i = 0; i < src_regd->n_reg_rules; i++) | 331 | for (i = 0; i < src_regd->n_reg_rules; i++) |
332 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], | 332 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], |
333 | sizeof(struct ieee80211_reg_rule)); | 333 | sizeof(struct ieee80211_reg_rule)); |
334 | 334 | ||
335 | *dst_regd = regd; | 335 | return regd; |
336 | return 0; | ||
337 | } | 336 | } |
338 | 337 | ||
339 | #ifdef CONFIG_CFG80211_INTERNAL_REGDB | 338 | #ifdef CONFIG_CFG80211_INTERNAL_REGDB |
@@ -348,9 +347,8 @@ static DEFINE_MUTEX(reg_regdb_search_mutex); | |||
348 | static void reg_regdb_search(struct work_struct *work) | 347 | static void reg_regdb_search(struct work_struct *work) |
349 | { | 348 | { |
350 | struct reg_regdb_search_request *request; | 349 | struct reg_regdb_search_request *request; |
351 | const struct ieee80211_regdomain *curdom, *regdom; | 350 | const struct ieee80211_regdomain *curdom, *regdom = NULL; |
352 | int i, r; | 351 | int i; |
353 | bool set_reg = false; | ||
354 | 352 | ||
355 | mutex_lock(&cfg80211_mutex); | 353 | mutex_lock(&cfg80211_mutex); |
356 | 354 | ||
@@ -365,10 +363,7 @@ static void reg_regdb_search(struct work_struct *work) | |||
365 | curdom = reg_regdb[i]; | 363 | curdom = reg_regdb[i]; |
366 | 364 | ||
367 | if (!memcmp(request->alpha2, curdom->alpha2, 2)) { | 365 | if (!memcmp(request->alpha2, curdom->alpha2, 2)) { |
368 | r = reg_copy_regd(®dom, curdom); | 366 | regdom = reg_copy_regd(curdom); |
369 | if (r) | ||
370 | break; | ||
371 | set_reg = true; | ||
372 | break; | 367 | break; |
373 | } | 368 | } |
374 | } | 369 | } |
@@ -377,7 +372,7 @@ static void reg_regdb_search(struct work_struct *work) | |||
377 | } | 372 | } |
378 | mutex_unlock(®_regdb_search_mutex); | 373 | mutex_unlock(®_regdb_search_mutex); |
379 | 374 | ||
380 | if (set_reg) | 375 | if (!IS_ERR_OR_NULL(regdom)) |
381 | set_regdom(regdom); | 376 | set_regdom(regdom); |
382 | 377 | ||
383 | mutex_unlock(&cfg80211_mutex); | 378 | mutex_unlock(&cfg80211_mutex); |
@@ -1509,6 +1504,7 @@ static void reg_set_request_processed(void) | |||
1509 | static int __regulatory_hint(struct wiphy *wiphy, | 1504 | static int __regulatory_hint(struct wiphy *wiphy, |
1510 | struct regulatory_request *pending_request) | 1505 | struct regulatory_request *pending_request) |
1511 | { | 1506 | { |
1507 | const struct ieee80211_regdomain *regd; | ||
1512 | bool intersect = false; | 1508 | bool intersect = false; |
1513 | int r = 0; | 1509 | int r = 0; |
1514 | 1510 | ||
@@ -1519,11 +1515,12 @@ static int __regulatory_hint(struct wiphy *wiphy, | |||
1519 | if (r == REG_INTERSECT) { | 1515 | if (r == REG_INTERSECT) { |
1520 | if (pending_request->initiator == | 1516 | if (pending_request->initiator == |
1521 | NL80211_REGDOM_SET_BY_DRIVER) { | 1517 | NL80211_REGDOM_SET_BY_DRIVER) { |
1522 | r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); | 1518 | regd = reg_copy_regd(cfg80211_regdomain); |
1523 | if (r) { | 1519 | if (IS_ERR(regd)) { |
1524 | kfree(pending_request); | 1520 | kfree(pending_request); |
1525 | return r; | 1521 | return PTR_ERR(regd); |
1526 | } | 1522 | } |
1523 | wiphy->regd = regd; | ||
1527 | } | 1524 | } |
1528 | intersect = true; | 1525 | intersect = true; |
1529 | } else if (r) { | 1526 | } else if (r) { |
@@ -1535,12 +1532,13 @@ static int __regulatory_hint(struct wiphy *wiphy, | |||
1535 | if (r == -EALREADY && | 1532 | if (r == -EALREADY && |
1536 | pending_request->initiator == | 1533 | pending_request->initiator == |
1537 | NL80211_REGDOM_SET_BY_DRIVER) { | 1534 | NL80211_REGDOM_SET_BY_DRIVER) { |
1538 | r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); | 1535 | regd = reg_copy_regd(cfg80211_regdomain); |
1539 | if (r) { | 1536 | if (IS_ERR(regd)) { |
1540 | kfree(pending_request); | 1537 | kfree(pending_request); |
1541 | return r; | 1538 | return PTR_ERR(regd); |
1542 | } | 1539 | } |
1543 | r = -EALREADY; | 1540 | r = -EALREADY; |
1541 | wiphy->regd = regd; | ||
1544 | goto new_request; | 1542 | goto new_request; |
1545 | } | 1543 | } |
1546 | kfree(pending_request); | 1544 | kfree(pending_request); |
@@ -2200,6 +2198,7 @@ static void print_regdomain_info(const struct ieee80211_regdomain *rd) | |||
2200 | /* Takes ownership of rd only if it doesn't fail */ | 2198 | /* Takes ownership of rd only if it doesn't fail */ |
2201 | static int __set_regdom(const struct ieee80211_regdomain *rd) | 2199 | static int __set_regdom(const struct ieee80211_regdomain *rd) |
2202 | { | 2200 | { |
2201 | const struct ieee80211_regdomain *regd; | ||
2203 | const struct ieee80211_regdomain *intersected_rd = NULL; | 2202 | const struct ieee80211_regdomain *intersected_rd = NULL; |
2204 | struct wiphy *request_wiphy; | 2203 | struct wiphy *request_wiphy; |
2205 | /* Some basic sanity checks first */ | 2204 | /* Some basic sanity checks first */ |
@@ -2257,8 +2256,6 @@ static int __set_regdom(const struct ieee80211_regdomain *rd) | |||
2257 | } | 2256 | } |
2258 | 2257 | ||
2259 | if (!last_request->intersect) { | 2258 | if (!last_request->intersect) { |
2260 | int r; | ||
2261 | |||
2262 | if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) { | 2259 | if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) { |
2263 | reset_regdomains(false); | 2260 | reset_regdomains(false); |
2264 | cfg80211_regdomain = rd; | 2261 | cfg80211_regdomain = rd; |
@@ -2277,10 +2274,11 @@ static int __set_regdom(const struct ieee80211_regdomain *rd) | |||
2277 | if (request_wiphy->regd) | 2274 | if (request_wiphy->regd) |
2278 | return -EALREADY; | 2275 | return -EALREADY; |
2279 | 2276 | ||
2280 | r = reg_copy_regd(&request_wiphy->regd, rd); | 2277 | regd = reg_copy_regd(rd); |
2281 | if (r) | 2278 | if (IS_ERR(regd)) |
2282 | return r; | 2279 | return PTR_ERR(regd); |
2283 | 2280 | ||
2281 | request_wiphy->regd = regd; | ||
2284 | reset_regdomains(false); | 2282 | reset_regdomains(false); |
2285 | cfg80211_regdomain = rd; | 2283 | cfg80211_regdomain = rd; |
2286 | return 0; | 2284 | return 0; |