cfg80211: add helper for kfree'ing last_request

This is common code, this reduces the chance of making
a mistake of how we free it.

Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Luis R. Rodriguez 2013-11-05 09:18:08 -08:00 committed by Johannes Berg
parent 2f1c6c572d
commit 5ad6ef5e06
1 changed files with 19 additions and 23 deletions

View File

@ -202,11 +202,20 @@ static char user_alpha2[2];
module_param(ieee80211_regdom, charp, 0444); module_param(ieee80211_regdom, charp, 0444);
MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
static void reg_kfree_last_request(void)
{
struct regulatory_request *lr;
lr = get_last_request();
if (lr != &core_request_world && lr)
kfree_rcu(lr, rcu_head);
}
static void reset_regdomains(bool full_reset, static void reset_regdomains(bool full_reset,
const struct ieee80211_regdomain *new_regdom) const struct ieee80211_regdomain *new_regdom)
{ {
const struct ieee80211_regdomain *r; const struct ieee80211_regdomain *r;
struct regulatory_request *lr;
ASSERT_RTNL(); ASSERT_RTNL();
@ -229,9 +238,7 @@ static void reset_regdomains(bool full_reset,
if (!full_reset) if (!full_reset)
return; return;
lr = get_last_request(); reg_kfree_last_request();
if (lr != &core_request_world && lr)
kfree_rcu(lr, rcu_head);
rcu_assign_pointer(last_request, &core_request_world); rcu_assign_pointer(last_request, &core_request_world);
} }
@ -1353,14 +1360,11 @@ static void reg_set_request_processed(void)
static enum reg_request_treatment static enum reg_request_treatment
reg_process_hint_core(struct regulatory_request *core_request) reg_process_hint_core(struct regulatory_request *core_request)
{ {
struct regulatory_request *lr;
lr = get_last_request();
if (lr != &core_request_world && lr)
kfree_rcu(lr, rcu_head);
core_request->intersect = false; core_request->intersect = false;
core_request->processed = false; core_request->processed = false;
reg_kfree_last_request();
rcu_assign_pointer(last_request, core_request); rcu_assign_pointer(last_request, core_request);
if (call_crda(core_request->alpha2)) if (call_crda(core_request->alpha2))
@ -1417,7 +1421,6 @@ static enum reg_request_treatment
reg_process_hint_user(struct regulatory_request *user_request) reg_process_hint_user(struct regulatory_request *user_request)
{ {
enum reg_request_treatment treatment; enum reg_request_treatment treatment;
struct regulatory_request *lr;
treatment = __reg_process_hint_user(user_request); treatment = __reg_process_hint_user(user_request);
if (treatment == REG_REQ_IGNORE || if (treatment == REG_REQ_IGNORE ||
@ -1426,12 +1429,10 @@ reg_process_hint_user(struct regulatory_request *user_request)
return treatment; return treatment;
} }
lr = get_last_request();
if (lr != &core_request_world && lr)
kfree_rcu(lr, rcu_head);
user_request->intersect = treatment == REG_REQ_INTERSECT; user_request->intersect = treatment == REG_REQ_INTERSECT;
user_request->processed = false; user_request->processed = false;
reg_kfree_last_request();
rcu_assign_pointer(last_request, user_request); rcu_assign_pointer(last_request, user_request);
user_alpha2[0] = user_request->alpha2[0]; user_alpha2[0] = user_request->alpha2[0];
@ -1480,7 +1481,6 @@ reg_process_hint_driver(struct wiphy *wiphy,
{ {
const struct ieee80211_regdomain *regd; const struct ieee80211_regdomain *regd;
enum reg_request_treatment treatment; enum reg_request_treatment treatment;
struct regulatory_request *lr;
treatment = __reg_process_hint_driver(driver_request); treatment = __reg_process_hint_driver(driver_request);
@ -1501,12 +1501,11 @@ reg_process_hint_driver(struct wiphy *wiphy,
rcu_assign_pointer(wiphy->regd, regd); rcu_assign_pointer(wiphy->regd, regd);
} }
lr = get_last_request();
if (lr != &core_request_world && lr)
kfree_rcu(lr, rcu_head);
driver_request->intersect = treatment == REG_REQ_INTERSECT; driver_request->intersect = treatment == REG_REQ_INTERSECT;
driver_request->processed = false; driver_request->processed = false;
reg_kfree_last_request();
rcu_assign_pointer(last_request, driver_request); rcu_assign_pointer(last_request, driver_request);
/* /*
@ -1581,7 +1580,6 @@ reg_process_hint_country_ie(struct wiphy *wiphy,
struct regulatory_request *country_ie_request) struct regulatory_request *country_ie_request)
{ {
enum reg_request_treatment treatment; enum reg_request_treatment treatment;
struct regulatory_request *lr;
treatment = __reg_process_hint_country_ie(wiphy, country_ie_request); treatment = __reg_process_hint_country_ie(wiphy, country_ie_request);
@ -1603,12 +1601,10 @@ reg_process_hint_country_ie(struct wiphy *wiphy,
return REG_REQ_IGNORE; return REG_REQ_IGNORE;
} }
lr = get_last_request();
if (lr != &core_request_world && lr)
kfree_rcu(lr, rcu_head);
country_ie_request->intersect = false; country_ie_request->intersect = false;
country_ie_request->processed = false; country_ie_request->processed = false;
reg_kfree_last_request();
rcu_assign_pointer(last_request, country_ie_request); rcu_assign_pointer(last_request, country_ie_request);
if (call_crda(country_ie_request->alpha2)) if (call_crda(country_ie_request->alpha2))