diff mbox series

[v2] nl80211: reset regdom when reloading regdb

Message ID X7+F/ht8T7aGiIl7@bombur.kloenk.de (mailing list archive)
State Changes Requested
Delegated to: Johannes Berg
Headers show
Series [v2] nl80211: reset regdom when reloading regdb | expand

Commit Message

Finn Behrens Nov. 26, 2020, 10:39 a.m. UTC
reset the regdom when NL80211_CMD_RELOAD_REGDB is send

Signed-off-by: Finn Behrens <fin@nyantec.com>
---
resend, as patchwork showed it malformed.

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

Comments

kernel test robot Nov. 26, 2020, 12:58 p.m. UTC | #1
Hi Finn,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mac80211-next/master]
[also build test WARNING on mac80211/master linus/master v5.10-rc5 next-20201126]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Finn-Behrens/nl80211-reset-regdom-when-reloading-regdb/20201126-184229
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git master
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/60f644b62d0171339bf90cbb65245a171d2edc2a
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Finn-Behrens/nl80211-reset-regdom-when-reloading-regdb/20201126-184229
        git checkout 60f644b62d0171339bf90cbb65245a171d2edc2a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from include/linux/kernel.h:11,
                    from net/wireless/reg.c:50:
   include/linux/scatterlist.h: In function 'sg_set_buf':
   arch/m68k/include/asm/page_mm.h:169:49: warning: ordered comparison of pointer with null pointer [-Wextra]
     169 | #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && (void *)(kaddr) < high_memory)
         |                                                 ^~
   include/linux/compiler.h:78:42: note: in definition of macro 'unlikely'
      78 | # define unlikely(x) __builtin_expect(!!(x), 0)
         |                                          ^
   include/linux/scatterlist.h:143:2: note: in expansion of macro 'BUG_ON'
     143 |  BUG_ON(!virt_addr_valid(buf));
         |  ^~~~~~
   include/linux/scatterlist.h:143:10: note: in expansion of macro 'virt_addr_valid'
     143 |  BUG_ON(!virt_addr_valid(buf));
         |          ^~~~~~~~~~~~~~~
   net/wireless/reg.c: In function 'reg_reload_regdb':
>> net/wireless/reg.c:1109:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    1109 |  const struct ieee80211_regdomain *current_regdomain = NULL;
         |  ^~~~~
   net/wireless/reg.c:1113:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    1113 |  struct regulatory_request *request = NULL;
         |  ^~~~~~
   net/wireless/reg.c: In function 'reg_process_hint_user':
>> net/wireless/reg.c:2686:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    2686 |      treatment == REG_REQ_ALREADY_SET &&
         |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
    2687 |    !user_request->reload)
         |    ~~~~~~~~~~~~~~~~~~~~~               

vim +1109 net/wireless/reg.c

  1077	
  1078	int reg_reload_regdb(void)
  1079	{
  1080		const struct firmware *fw;
  1081		void *db;
  1082		int err;
  1083	
  1084		err = request_firmware(&fw, "regulatory.db", &reg_pdev->dev);
  1085		if (err) {
  1086			pr_info("failed to load regulatory.db\n");
  1087			return err;
  1088		}
  1089	
  1090		if (!valid_regdb(fw->data, fw->size)) {
  1091			pr_info("loaded regulatory.db is malformed or signature is missing/invalid\n");
  1092			err = -ENODATA;
  1093			goto out;
  1094		}
  1095	
  1096		db = kmemdup(fw->data, fw->size, GFP_KERNEL);
  1097		if (!db) {
  1098			err = -ENOMEM;
  1099			goto out;
  1100		}
  1101	
  1102		rtnl_lock();
  1103		if (!IS_ERR_OR_NULL(regdb))
  1104			kfree(regdb);
  1105		regdb = db;
  1106		rtnl_unlock();
  1107	
  1108		// reset regulatory
> 1109		const struct ieee80211_regdomain *current_regdomain = NULL;
  1110	
  1111		current_regdomain = get_cfg80211_regdom();
  1112	
  1113		struct regulatory_request *request = NULL;
  1114	
  1115		request = kzalloc(sizeof(*request), GFP_KERNEL);
  1116		if (!request) {
  1117			err = -ENOMEM;
  1118			goto out;
  1119		}
  1120	
  1121		request->wiphy_idx = WIPHY_IDX_INVALID;
  1122		request->alpha2[0] = current_regdomain->alpha2[0];
  1123		request->alpha2[1] = current_regdomain->alpha2[1];
  1124		request->initiator = NL80211_USER_REG_HINT_USER;
  1125		request->user_reg_hint_type = NL80211_USER_REG_HINT_USER;
  1126		request->reload = true;
  1127	
  1128		queue_regulatory_request(request);
  1129	
  1130	 out:
  1131		release_firmware(fw);
  1132		return err;
  1133	}
  1134	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Johannes Berg Dec. 4, 2020, 11:39 a.m. UTC | #2
On Thu, 2020-11-26 at 11:39 +0100, Finn Behrens wrote:
> reset the regdom when NL80211_CMD_RELOAD_REGDB is send

Please add a bit more commit message, saying why this is needed.

>  	err = request_firmware(&fw, "regulatory.db", &reg_pdev->dev);
> -	if (err)
> +	if (err) {
> +		pr_info("failed to load regulatory.db\n");
>  		return err;
> +	}
>  
>  	if (!valid_regdb(fw->data, fw->size)) {
> +		pr_info("loaded regulatory.db is malformed or signature is missing/invalid\n");
>  		err = -ENODATA;
>  		goto out;
>  	}

These changes seem unrelated.

> @@ -1101,6 +1105,28 @@ int reg_reload_regdb(void)
>  	regdb = db;
>  	rtnl_unlock();
>  
> +	// reset regulatory

For whatever reason, the kernel doesn't use C99 comments.

> +	const struct ieee80211_regdomain *current_regdomain = NULL;

This should've given you a compiler warning that you shouldn't declare
variables in the middle of the code.

> +	current_regdomain = get_cfg80211_regdom();
> +
> +	struct regulatory_request *request = NULL;
> +
> +	request = kzalloc(sizeof(*request), GFP_KERNEL);
> +	if (!request) {
> +		err = -ENOMEM;
> +		goto out;
> +	}
> +
> +	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;
> +
> +	queue_regulatory_request(request);
> 
Why does it even need to be queued - we're in a process context where we
can sleep?

johannes
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 a04fdfb35f07..50314916b020 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -199,6 +199,7 @@  static struct regulatory_request *get_last_request(void)
 /* Used to queue up regulatory hints */
 static LIST_HEAD(reg_requests_list);
 static spinlock_t reg_requests_lock;
+static void queue_regulatory_request(struct regulatory_request *request);
 
 /* Used to queue up beacon hints for review */
 static LIST_HEAD(reg_pending_beacons);
@@ -1081,10 +1082,13 @@  int reg_reload_regdb(void)
 	int err;
 
 	err = request_firmware(&fw, "regulatory.db", &reg_pdev->dev);
-	if (err)
+	if (err) {
+		pr_info("failed to load regulatory.db\n");
 		return err;
+	}
 
 	if (!valid_regdb(fw->data, fw->size)) {
+		pr_info("loaded regulatory.db is malformed or signature is missing/invalid\n");
 		err = -ENODATA;
 		goto out;
 	}
@@ -1101,6 +1105,28 @@  int reg_reload_regdb(void)
 	regdb = db;
 	rtnl_unlock();
 
+	// reset regulatory
+	const struct ieee80211_regdomain *current_regdomain = NULL;
+
+	current_regdomain = get_cfg80211_regdom();
+
+	struct regulatory_request *request = NULL;
+
+	request = kzalloc(sizeof(*request), GFP_KERNEL);
+	if (!request) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	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;
+
+	queue_regulatory_request(request);
+
  out:
 	release_firmware(fw);
 	return err;
@@ -2657,7 +2683,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;