Skip to content

Commit

Permalink
regulatory: clean up reg_copy_regd()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Berg committed Jan 3, 2013
1 parent 74f53cd commit e9763c3
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions net/wireless/reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand All @@ -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);

Expand All @@ -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;
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit e9763c3

Please sign in to comment.