summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2012-12-03 15:59:46 (GMT)
committerJohannes Berg <johannes.berg@intel.com>2013-01-03 12:01:20 (GMT)
commite9763c3c295a8b31316e16558b58b226e005b160 (patch)
treee132203edc7265cb23ace6404c9f8b03ad870d7c
parent74f53cd8d4474f9ba91c7309feabebae80a60089 (diff)
downloadlinux-fsl-qoriq-e9763c3c295a8b31316e16558b58b226e005b160.tar.xz
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>
-rw-r--r--net/wireless/reg.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index d52ffa2..52a3598 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -311,11 +311,11 @@ static bool is_user_regdom_saved(void)
return true;
}
-static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
- const struct ieee80211_regdomain *src_regd)
+static const struct ieee80211_regdomain *
+reg_copy_regd(const struct ieee80211_regdomain *src_regd)
{
struct ieee80211_regdomain *regd;
- int size_of_regd = 0;
+ int size_of_regd;
unsigned int i;
size_of_regd =
@@ -324,16 +324,15 @@ static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
regd = kzalloc(size_of_regd, GFP_KERNEL);
if (!regd)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
for (i = 0; i < src_regd->n_reg_rules; i++)
memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
- sizeof(struct ieee80211_reg_rule));
+ sizeof(struct ieee80211_reg_rule));
- *dst_regd = regd;
- return 0;
+ return regd;
}
#ifdef CONFIG_CFG80211_INTERNAL_REGDB
@@ -348,9 +347,8 @@ static DEFINE_MUTEX(reg_regdb_search_mutex);
static void reg_regdb_search(struct work_struct *work)
{
struct reg_regdb_search_request *request;
- const struct ieee80211_regdomain *curdom, *regdom;
- int i, r;
- bool set_reg = false;
+ const struct ieee80211_regdomain *curdom, *regdom = NULL;
+ int i;
mutex_lock(&cfg80211_mutex);
@@ -365,10 +363,7 @@ static void reg_regdb_search(struct work_struct *work)
curdom = reg_regdb[i];
if (!memcmp(request->alpha2, curdom->alpha2, 2)) {
- r = reg_copy_regd(&regdom, curdom);
- if (r)
- break;
- set_reg = true;
+ regdom = reg_copy_regd(curdom);
break;
}
}
@@ -377,7 +372,7 @@ static void reg_regdb_search(struct work_struct *work)
}
mutex_unlock(&reg_regdb_search_mutex);
- if (set_reg)
+ if (!IS_ERR_OR_NULL(regdom))
set_regdom(regdom);
mutex_unlock(&cfg80211_mutex);
@@ -1509,6 +1504,7 @@ static void reg_set_request_processed(void)
static int __regulatory_hint(struct wiphy *wiphy,
struct regulatory_request *pending_request)
{
+ const struct ieee80211_regdomain *regd;
bool intersect = false;
int r = 0;
@@ -1519,11 +1515,12 @@ static int __regulatory_hint(struct wiphy *wiphy,
if (r == REG_INTERSECT) {
if (pending_request->initiator ==
NL80211_REGDOM_SET_BY_DRIVER) {
- r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
- if (r) {
+ regd = reg_copy_regd(cfg80211_regdomain);
+ if (IS_ERR(regd)) {
kfree(pending_request);
- return r;
+ return PTR_ERR(regd);
}
+ wiphy->regd = regd;
}
intersect = true;
} else if (r) {
@@ -1535,12 +1532,13 @@ static int __regulatory_hint(struct wiphy *wiphy,
if (r == -EALREADY &&
pending_request->initiator ==
NL80211_REGDOM_SET_BY_DRIVER) {
- r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain);
- if (r) {
+ regd = reg_copy_regd(cfg80211_regdomain);
+ if (IS_ERR(regd)) {
kfree(pending_request);
- return r;
+ return PTR_ERR(regd);
}
r = -EALREADY;
+ wiphy->regd = regd;
goto new_request;
}
kfree(pending_request);
@@ -2200,6 +2198,7 @@ static void print_regdomain_info(const struct ieee80211_regdomain *rd)
/* Takes ownership of rd only if it doesn't fail */
static int __set_regdom(const struct ieee80211_regdomain *rd)
{
+ const struct ieee80211_regdomain *regd;
const struct ieee80211_regdomain *intersected_rd = NULL;
struct wiphy *request_wiphy;
/* Some basic sanity checks first */
@@ -2257,8 +2256,6 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
}
if (!last_request->intersect) {
- int r;
-
if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
reset_regdomains(false);
cfg80211_regdomain = rd;
@@ -2277,10 +2274,11 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
if (request_wiphy->regd)
return -EALREADY;
- r = reg_copy_regd(&request_wiphy->regd, rd);
- if (r)
- return r;
+ regd = reg_copy_regd(rd);
+ if (IS_ERR(regd))
+ return PTR_ERR(regd);
+ request_wiphy->regd = regd;
reset_regdomains(false);
cfg80211_regdomain = rd;
return 0;