@@ -81,7 +81,10 @@ static struct regulatory_request core_request_world = {
8181 .country_ie_env = ENVIRON_ANY ,
8282};
8383
84- /* Receipt of information from last regulatory request */
84+ /*
85+ * Receipt of information from last regulatory request,
86+ * protected by RTNL (and can be accessed with RCU protection)
87+ */
8588static struct regulatory_request __rcu * last_request =
8689 (void __rcu * )& core_request_world ;
8790
@@ -96,39 +99,25 @@ static struct device_type reg_device_type = {
9699 * Central wireless core regulatory domains, we only need two,
97100 * the current one and a world regulatory domain in case we have no
98101 * information to give us an alpha2.
102+ * (protected by RTNL, can be read under RCU)
99103 */
100104const struct ieee80211_regdomain __rcu * cfg80211_regdomain ;
101105
102- /*
103- * Protects static reg.c components:
104- * - cfg80211_regdomain (if not used with RCU)
105- * - cfg80211_world_regdom
106- * - last_request (if not used with RCU)
107- * - reg_num_devs_support_basehint
108- */
109- static DEFINE_MUTEX (reg_mutex );
110-
111106/*
112107 * Number of devices that registered to the core
113108 * that support cellular base station regulatory hints
109+ * (protected by RTNL)
114110 */
115111static int reg_num_devs_support_basehint ;
116112
117- static inline void assert_reg_lock (void )
118- {
119- lockdep_assert_held (& reg_mutex );
120- }
121-
122113static const struct ieee80211_regdomain * get_cfg80211_regdom (void )
123114{
124- return rcu_dereference_protected (cfg80211_regdomain ,
125- lockdep_is_held (& reg_mutex ));
115+ return rtnl_dereference (cfg80211_regdomain );
126116}
127117
128118static const struct ieee80211_regdomain * get_wiphy_regdom (struct wiphy * wiphy )
129119{
130- return rcu_dereference_protected (wiphy -> regd ,
131- lockdep_is_held (& reg_mutex ));
120+ return rtnl_dereference (wiphy -> regd );
132121}
133122
134123static void rcu_free_regdom (const struct ieee80211_regdomain * r )
@@ -140,8 +129,7 @@ static void rcu_free_regdom(const struct ieee80211_regdomain *r)
140129
141130static struct regulatory_request * get_last_request (void )
142131{
143- return rcu_dereference_check (last_request ,
144- lockdep_is_held (& reg_mutex ));
132+ return rcu_dereference_rtnl (last_request );
145133}
146134
147135/* Used to queue up regulatory hints */
@@ -200,6 +188,7 @@ static const struct ieee80211_regdomain world_regdom = {
200188 }
201189};
202190
191+ /* protected by RTNL */
203192static const struct ieee80211_regdomain * cfg80211_world_regdom =
204193 & world_regdom ;
205194
@@ -215,7 +204,7 @@ static void reset_regdomains(bool full_reset,
215204 const struct ieee80211_regdomain * r ;
216205 struct regulatory_request * lr ;
217206
218- assert_reg_lock ();
207+ ASSERT_RTNL ();
219208
220209 r = get_cfg80211_regdom ();
221210
@@ -936,13 +925,7 @@ static bool reg_request_cell_base(struct regulatory_request *request)
936925
937926bool reg_last_request_cell_base (void )
938927{
939- bool val ;
940-
941- mutex_lock (& reg_mutex );
942- val = reg_request_cell_base (get_last_request ());
943- mutex_unlock (& reg_mutex );
944-
945- return val ;
928+ return reg_request_cell_base (get_last_request ());
946929}
947930
948931#ifdef CONFIG_CFG80211_CERTIFICATION_ONUS
@@ -1444,8 +1427,6 @@ static void reg_set_request_processed(void)
14441427 * what it believes should be the current regulatory domain.
14451428 *
14461429 * Returns one of the different reg request treatment values.
1447- *
1448- * Caller must hold ®_mutex
14491430 */
14501431static enum reg_request_treatment
14511432__regulatory_hint (struct wiphy * wiphy ,
@@ -1622,10 +1603,8 @@ static void reg_process_pending_beacon_hints(void)
16221603static void reg_todo (struct work_struct * work )
16231604{
16241605 rtnl_lock ();
1625- mutex_lock (& reg_mutex );
16261606 reg_process_pending_hints ();
16271607 reg_process_pending_beacon_hints ();
1628- mutex_unlock (& reg_mutex );
16291608 rtnl_unlock ();
16301609}
16311610
@@ -1851,8 +1830,6 @@ static void restore_regulatory_settings(bool reset_user)
18511830
18521831 ASSERT_RTNL ();
18531832
1854- mutex_lock (& reg_mutex );
1855-
18561833 reset_regdomains (true, & world_regdom );
18571834 restore_alpha2 (alpha2 , reset_user );
18581835
@@ -1906,8 +1883,6 @@ static void restore_regulatory_settings(bool reset_user)
19061883 list_splice_tail_init (& tmp_reg_req_list , & reg_requests_list );
19071884 spin_unlock (& reg_requests_lock );
19081885
1909- mutex_unlock (& reg_mutex );
1910-
19111886 REG_DBG_PRINT ("Kicking the queue\n" );
19121887
19131888 schedule_work (& reg_work );
@@ -2222,7 +2197,6 @@ int set_regdom(const struct ieee80211_regdomain *rd)
22222197 struct regulatory_request * lr ;
22232198 int r ;
22242199
2225- mutex_lock (& reg_mutex );
22262200 lr = get_last_request ();
22272201
22282202 /* Note that this doesn't update the wiphys, this is done below */
@@ -2232,14 +2206,12 @@ int set_regdom(const struct ieee80211_regdomain *rd)
22322206 reg_set_request_processed ();
22332207
22342208 kfree (rd );
2235- goto out ;
2209+ return r ;
22362210 }
22372211
22382212 /* This would make this whole thing pointless */
2239- if (WARN_ON (!lr -> intersect && rd != get_cfg80211_regdom ())) {
2240- r = - EINVAL ;
2241- goto out ;
2242- }
2213+ if (WARN_ON (!lr -> intersect && rd != get_cfg80211_regdom ()))
2214+ return - EINVAL ;
22432215
22442216 /* update all wiphys now with the new established regulatory domain */
22452217 update_all_wiphy_regulatory (lr -> initiator );
@@ -2250,10 +2222,7 @@ int set_regdom(const struct ieee80211_regdomain *rd)
22502222
22512223 reg_set_request_processed ();
22522224
2253- out :
2254- mutex_unlock (& reg_mutex );
2255-
2256- return r ;
2225+ return 0 ;
22572226}
22582227
22592228int reg_device_uevent (struct device * dev , struct kobj_uevent_env * env )
@@ -2278,22 +2247,17 @@ int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
22782247
22792248void wiphy_regulatory_register (struct wiphy * wiphy )
22802249{
2281- mutex_lock (& reg_mutex );
2282-
22832250 if (!reg_dev_ignore_cell_hint (wiphy ))
22842251 reg_num_devs_support_basehint ++ ;
22852252
22862253 wiphy_update_regulatory (wiphy , NL80211_REGDOM_SET_BY_CORE );
2287-
2288- mutex_unlock (& reg_mutex );
22892254}
22902255
22912256void wiphy_regulatory_deregister (struct wiphy * wiphy )
22922257{
22932258 struct wiphy * request_wiphy = NULL ;
22942259 struct regulatory_request * lr ;
22952260
2296- mutex_lock (& reg_mutex );
22972261 lr = get_last_request ();
22982262
22992263 if (!reg_dev_ignore_cell_hint (wiphy ))
@@ -2306,12 +2270,10 @@ void wiphy_regulatory_deregister(struct wiphy *wiphy)
23062270 request_wiphy = wiphy_idx_to_wiphy (lr -> wiphy_idx );
23072271
23082272 if (!request_wiphy || request_wiphy != wiphy )
2309- goto out ;
2273+ return ;
23102274
23112275 lr -> wiphy_idx = WIPHY_IDX_INVALID ;
23122276 lr -> country_ie_env = ENVIRON_ANY ;
2313- out :
2314- mutex_unlock (& reg_mutex );
23152277}
23162278
23172279static void reg_timeout_work (struct work_struct * work )
@@ -2375,9 +2337,9 @@ void regulatory_exit(void)
23752337 cancel_delayed_work_sync (& reg_timeout );
23762338
23772339 /* Lock to suppress warnings */
2378- mutex_lock ( & reg_mutex );
2340+ rtnl_lock ( );
23792341 reset_regdomains (true, NULL );
2380- mutex_unlock ( & reg_mutex );
2342+ rtnl_unlock ( );
23812343
23822344 dev_set_uevent_suppress (& reg_pdev -> dev , true);
23832345
0 commit comments