From: Johannes Berg Setting the driver's self-managed regulatory domain is currently applied immediately, even if the wiphy isn't actually ever registered, and (for some broken drivers like iwlmld) might not update channels correctly since the regdomain is set before the channels are linked to the wiphy. Regardless of broken drivers though, it doesn't really make sense to apply the regdomain on the spot, if the wiphy never registers we don't need to do this work, nor does it make sense to send a regdomain event for a wiphy userspace doesn't know about. Change it so that a regdomain set before the wiphy is registered doesn't cause any action yet and is just remembered and then apply it correctly when the wiphy is registered. Also WARN if a driver registers a self-managed wiphy without a regdomain, that just leads to confusion in userspace, and a later WARN in nl80211 can be hit if it queries for it quickly enough. Due to locking changes this also removes processing of self-managed hints for all wiphys when one registers, but that never really made much sense anyway. Reviewed-by: Miriam Rachel Korenblit Signed-off-by: Johannes Berg --- net/wireless/core.c | 5 ++++- net/wireless/reg.c | 45 ++++++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/net/wireless/core.c b/net/wireless/core.c index f4153c249599..9d586a3e2b44 100644 --- a/net/wireless/core.c +++ b/net/wireless/core.c @@ -1259,10 +1259,13 @@ int wiphy_register(struct wiphy *wiphy) rdev->wiphy.registered = true; nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY); - wiphy_unlock(&rdev->wiphy); /* set up regulatory info */ wiphy_regulatory_register(wiphy); + /* TODO: make this a hard failure when drivers are fixed? */ + WARN_ON(wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && + !get_wiphy_regdom(wiphy)); + wiphy_unlock(&rdev->wiphy); if (wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) { struct regulatory_request request = { diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 2bf3bcd8809b..c009ecfd15e9 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -3237,6 +3237,10 @@ static void reg_process_self_managed_hint(struct wiphy *wiphy) lockdep_assert_wiphy(wiphy); + /* not registered yet, apply later during registration */ + if (!rdev->wiphy.registered) + return; + spin_lock(®_requests_lock); regd = rdev->requested_regd; rdev->requested_regd = NULL; @@ -4146,7 +4150,8 @@ int regulatory_set_wiphy_regd(struct wiphy *wiphy, if (ret) return ret; - schedule_work(®_work); + if (wiphy->registered) + schedule_work(®_work); return 0; } EXPORT_SYMBOL(regulatory_set_wiphy_regd); @@ -4174,30 +4179,28 @@ void wiphy_regulatory_register(struct wiphy *wiphy) struct regulatory_request *lr = get_last_request(); lockdep_assert_held(&cfg80211_mutex); + lockdep_assert_wiphy(wiphy); - scoped_guard(wiphy, wiphy) { - /* self-managed devices ignore beacon hints and country IE */ - if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { - wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | - REGULATORY_COUNTRY_IE_IGNORE; + /* self-managed devices ignore beacon hints and country IE */ + if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { + wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | + REGULATORY_COUNTRY_IE_IGNORE; - /* - * The last request may have been received before this - * registration call. Call the driver notifier if - * initiator is USER. - */ - if (lr->initiator == NL80211_REGDOM_SET_BY_USER) - reg_call_notifier(wiphy, lr); - } - - if (!reg_dev_ignore_cell_hint(wiphy)) - reg_update_cell_hint_num(wiphy, 1); - - wiphy_update_regulatory(wiphy, lr->initiator); - wiphy_all_share_dfs_chan_state(wiphy); + /* + * The last request may have been received before this + * registration call. Call the driver notifier if + * initiator is USER. + */ + if (lr->initiator == NL80211_REGDOM_SET_BY_USER) + reg_call_notifier(wiphy, lr); } - reg_process_self_managed_hints(); + if (!reg_dev_ignore_cell_hint(wiphy)) + reg_update_cell_hint_num(wiphy, 1); + + wiphy_update_regulatory(wiphy, lr->initiator); + wiphy_all_share_dfs_chan_state(wiphy); + reg_process_self_managed_hint(wiphy); } void wiphy_regulatory_deregister(struct wiphy *wiphy) -- 2.56.0