diff mbox series

[v5] nl80211: reset regdom when reloading regdb

Message ID YaIIZfxHgqc/UTA7@gimli.kloenk.dev (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series [v5] nl80211: reset regdom when reloading regdb | expand

Commit Message

Finn Behrens Nov. 27, 2021, 10:28 a.m. UTC
this reloads the regdom when the regulatory db is reloaded.
Without this patch the user had to change the regulatoy domain to a
different, and then reset it to the one the user is in, to have the new
regulatory db take effect

Signed-off-by: Finn Behrens <fin@nyantec.com>
---
Hi,
I moved the rtnl_unlock into a label, and requested the current domain from inside the lock.
Finn

 include/net/regulatory.h |  1 +
 net/wireless/reg.c       | 27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

Comments

Nathan Chancellor Nov. 30, 2021, 4:02 p.m. UTC | #1
Hi Finn,

On Sat, Nov 27, 2021 at 11:28:53AM +0100, Finn Behrens wrote:
> this reloads the regdom when the regulatory db is reloaded.
> Without this patch the user had to change the regulatoy domain to a
> different, and then reset it to the one the user is in, to have the new
> regulatory db take effect
> 
> Signed-off-by: Finn Behrens <fin@nyantec.com>

This patch as commit 1eda919126b4 ("nl80211: reset regdom when reloading
regdb") in -next causes the following clang warning/error:

net/wireless/reg.c:1137:23: error: implicit conversion from enumeration type 'enum nl80211_user_reg_hint_type' to different enumeration type 'enum nl80211_reg_initiator' [-Werror,-Wenum-conversion]
        request->initiator = NL80211_USER_REG_HINT_USER;
                           ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Should that be NL80211_REGDOM_SET_BY_CORE (same value, 0) or something
different?

Cheers,
Nathan
Finn Behrens Nov. 30, 2021, 4:50 p.m. UTC | #2
> On 30. Nov 2021, at 17:02, Nathan Chancellor <nathan@kernel.org> wrote:
> 
> Hi Finn,
> 
> On Sat, Nov 27, 2021 at 11:28:53AM +0100, Finn Behrens wrote:
>> this reloads the regdom when the regulatory db is reloaded.
>> Without this patch the user had to change the regulatoy domain to a
>> different, and then reset it to the one the user is in, to have the new
>> regulatory db take effect
>> 
>> Signed-off-by: Finn Behrens <fin@nyantec.com>
> 
> This patch as commit 1eda919126b4 ("nl80211: reset regdom when reloading
> regdb") in -next causes the following clang warning/error:
> 
> net/wireless/reg.c:1137:23: error: implicit conversion from enumeration type 'enum nl80211_user_reg_hint_type' to different enumeration type 'enum nl80211_reg_initiator' [-Werror,-Wenum-conversion]
>        request->initiator = NL80211_USER_REG_HINT_USER;
>                           ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
> 
> Should that be NL80211_REGDOM_SET_BY_CORE (same value, 0) or something
> different?
> 
> Cheers,
> Nathan

Hi Nathan,

I think It should have been NL80211_REGDOM_SET_BY_USER, as the reload flag check is currently implemented in the user hint function. But If I see it correctly right now. We could remove the reload flag,
and NL80211_REGDOM_SET_BY_CORE should work as well. As the reg_query_database function is called unconditionally there.

I will prepare a patch that reverts the reload flag, and changes to NL80211_REGDOM_SET_BY_CORE as this already works. Or should it be NL80211_REGDOM_SET_BY_USER, as it’s results from an user
called function?

Cheers,
Finn
Nathan Chancellor Nov. 30, 2021, 6:32 p.m. UTC | #3
On Tue, Nov 30, 2021 at 05:50:58PM +0100, Finn Behrens wrote:
> > On 30. Nov 2021, at 17:02, Nathan Chancellor <nathan@kernel.org> wrote:
> > On Sat, Nov 27, 2021 at 11:28:53AM +0100, Finn Behrens wrote:
> >> this reloads the regdom when the regulatory db is reloaded.
> >> Without this patch the user had to change the regulatoy domain to a
> >> different, and then reset it to the one the user is in, to have the new
> >> regulatory db take effect
> >> 
> >> Signed-off-by: Finn Behrens <fin@nyantec.com>
> > 
> > This patch as commit 1eda919126b4 ("nl80211: reset regdom when reloading
> > regdb") in -next causes the following clang warning/error:
> > 
> > net/wireless/reg.c:1137:23: error: implicit conversion from enumeration type 'enum nl80211_user_reg_hint_type' to different enumeration type 'enum nl80211_reg_initiator' [-Werror,-Wenum-conversion]
> >        request->initiator = NL80211_USER_REG_HINT_USER;
> >                           ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~
> > 1 error generated.
> > 
> > Should that be NL80211_REGDOM_SET_BY_CORE (same value, 0) or something
> > different?
> 
> I think It should have been NL80211_REGDOM_SET_BY_USER, as the reload
> flag check is currently implemented in the user hint function. But If
> I see it correctly right now. We could remove the reload flag, and
> NL80211_REGDOM_SET_BY_CORE should work as well. As the
> reg_query_database function is called unconditionally there.

If you tested the current version of your patch and it worked fine, then
it seems like you should just revert the addition of the reload flag and
change

request->initiator = NL80211_USER_REG_HINT_USER;

to

request->initiator = NL80211_REGDOM_SET_BY_CORE;

given that is what is happening right now. The warning is basically
pointing out that reg_process_hint() is calling reg_process_hint_core()
instead of reg_process_hint_user() because NL80211_USER_REG_HINT_USER =
NL80211_REGDOM_SET_BY_CORE = 0. Hopefully that makes sense.

Cheers,
Nathan
diff mbox series

Patch

diff --git a/include/net/regulatory.h b/include/net/regulatory.h
index 47f06f6f5a67..0cf9335431e0 100644
--- a/include/net/regulatory.h
+++ b/include/net/regulatory.h
@@ -83,6 +83,7 @@  struct regulatory_request {
 	enum nl80211_dfs_regions dfs_region;
 	bool intersect;
 	bool processed;
+	bool reload;
 	enum environment_cap country_ie_env;
 	struct list_head list;
 };
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index df87c7f3a049..61f1bf1bc4a7 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -133,6 +133,7 @@  static u32 reg_is_indoor_portid;
 
 static void restore_regulatory_settings(bool reset_user, bool cached);
 static void print_regdomain(const struct ieee80211_regdomain *rd);
+static void reg_process_hint(struct regulatory_request *reg_request);
 
 static const struct ieee80211_regdomain *get_cfg80211_regdom(void)
 {
@@ -1098,6 +1099,8 @@  int reg_reload_regdb(void)
 	const struct firmware *fw;
 	void *db;
 	int err;
+	const struct ieee80211_regdomain *current_regdomain;
+	struct regulatory_request *request;
 
 	err = request_firmware(&fw, "regulatory.db", &reg_pdev->dev);
 	if (err)
@@ -1118,8 +1121,27 @@  int reg_reload_regdb(void)
 	if (!IS_ERR_OR_NULL(regdb))
 		kfree(regdb);
 	regdb = db;
-	rtnl_unlock();
 
+	/* reset regulatory domain */
+	current_regdomain = get_cfg80211_regdom();
+
+	request = kzalloc(sizeof(*request), GFP_KERNEL);
+	if (!request) {
+		err = -ENOMEM;
+		goto out_unlock;
+	}
+
+	request->wiphy_idx = WIPHY_IDX_INVALID;
+	request->alpha2[0] = current_regdomain->alpha2[0];
+	request->alpha2[1] = current_regdomain->alpha2[1];
+	request->initiator = NL80211_USER_REG_HINT_USER;
+	request->user_reg_hint_type = NL80211_USER_REG_HINT_USER;
+	request->reload = true;
+
+	reg_process_hint(request);
+
+out_unlock:
+	rtnl_unlock();
  out:
 	release_firmware(fw);
 	return err;
@@ -2690,7 +2712,8 @@  reg_process_hint_user(struct regulatory_request *user_request)
 
 	treatment = __reg_process_hint_user(user_request);
 	if (treatment == REG_REQ_IGNORE ||
-	    treatment == REG_REQ_ALREADY_SET)
+	    (treatment == REG_REQ_ALREADY_SET &&
+	     !user_request->reload))
 		return REG_REQ_IGNORE;
 
 	user_request->intersect = treatment == REG_REQ_INTERSECT;