[PATCH 1/2] wifi: mwifiex: simplify WPA flags setting

Sascha Hauer posted 2 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH 1/2] wifi: mwifiex: simplify WPA flags setting
Posted by Sascha Hauer 1 year, 5 months ago
The WPA flags setting only depends on the wpa_versions bitfield and not
on the AKM suite, so move it out of the switch/case to simplify the code
a bit. No functional change intended.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/wireless/marvell/mwifiex/uap_cmd.c | 27 +++++++-------------------
 1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
index 491e366119096..8d0cd84d27698 100644
--- a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
+++ b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
@@ -46,31 +46,18 @@ int mwifiex_set_secure_params(struct mwifiex_private *priv,
 
 	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
 
+	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
+		bss_config->protocol = PROTOCOL_WPA;
+	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
+		bss_config->protocol |= PROTOCOL_WPA2;
+
 	for (i = 0; i < params->crypto.n_akm_suites; i++) {
 		switch (params->crypto.akm_suites[i]) {
 		case WLAN_AKM_SUITE_8021X:
-			if (params->crypto.wpa_versions &
-			    NL80211_WPA_VERSION_1) {
-				bss_config->protocol = PROTOCOL_WPA;
-				bss_config->key_mgmt = KEY_MGMT_EAP;
-			}
-			if (params->crypto.wpa_versions &
-			    NL80211_WPA_VERSION_2) {
-				bss_config->protocol |= PROTOCOL_WPA2;
-				bss_config->key_mgmt = KEY_MGMT_EAP;
-			}
+			bss_config->key_mgmt = KEY_MGMT_EAP;
 			break;
 		case WLAN_AKM_SUITE_PSK:
-			if (params->crypto.wpa_versions &
-			    NL80211_WPA_VERSION_1) {
-				bss_config->protocol = PROTOCOL_WPA;
-				bss_config->key_mgmt = KEY_MGMT_PSK;
-			}
-			if (params->crypto.wpa_versions &
-			    NL80211_WPA_VERSION_2) {
-				bss_config->protocol |= PROTOCOL_WPA2;
-				bss_config->key_mgmt = KEY_MGMT_PSK;
-			}
+			bss_config->key_mgmt = KEY_MGMT_PSK;
 			break;
 		default:
 			break;

-- 
2.39.2
Re: [PATCH 1/2] wifi: mwifiex: simplify WPA flags setting
Posted by Francesco Dolcini 1 year, 5 months ago
Hello Sasha,
thanks for your patch.

On Tue, Jul 16, 2024 at 01:33:27PM +0200, Sascha Hauer wrote:
> The WPA flags setting only depends on the wpa_versions bitfield and not
> on the AKM suite, so move it out of the switch/case to simplify the code
> a bit. No functional change intended.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com>

> ---
>  drivers/net/wireless/marvell/mwifiex/uap_cmd.c | 27 +++++++-------------------
>  1 file changed, 7 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> index 491e366119096..8d0cd84d27698 100644
> --- a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> +++ b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> @@ -46,31 +46,18 @@ int mwifiex_set_secure_params(struct mwifiex_private *priv,
>  
>  	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
>  
> +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
> +		bss_config->protocol = PROTOCOL_WPA;
> +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
> +		bss_config->protocol |= PROTOCOL_WPA2;
> +

I am wondering what happens if NL80211_WPA_VERSION_1 is not set, no idea
what's the content of bss_config->protocol ...

in any case this is not something that you introduced, but maybe worth
having a look?

Francesco
Re: [PATCH 1/2] wifi: mwifiex: simplify WPA flags setting
Posted by Sascha Hauer 1 year, 5 months ago
On Tue, Jul 16, 2024 at 09:48:26PM +0200, Francesco Dolcini wrote:
> Hello Sasha,
> thanks for your patch.
> 
> On Tue, Jul 16, 2024 at 01:33:27PM +0200, Sascha Hauer wrote:
> > The WPA flags setting only depends on the wpa_versions bitfield and not
> > on the AKM suite, so move it out of the switch/case to simplify the code
> > a bit. No functional change intended.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com>
> 
> > ---
> >  drivers/net/wireless/marvell/mwifiex/uap_cmd.c | 27 +++++++-------------------
> >  1 file changed, 7 insertions(+), 20 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > index 491e366119096..8d0cd84d27698 100644
> > --- a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > +++ b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > @@ -46,31 +46,18 @@ int mwifiex_set_secure_params(struct mwifiex_private *priv,
> >  
> >  	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
> >  
> > +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
> > +		bss_config->protocol = PROTOCOL_WPA;
> > +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
> > +		bss_config->protocol |= PROTOCOL_WPA2;
> > +
> 
> I am wondering what happens if NL80211_WPA_VERSION_1 is not set, no idea
> what's the content of bss_config->protocol ...
> 
> in any case this is not something that you introduced, but maybe worth
> having a look?

bss_config is kzalloced in the only caller of mwifiex_set_secure_params(),
so bss_config->protocol is zero on entry.

It might be worth setting it to zero explicitly here to make the code
better understandable without having to look at the callers.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
Re: [PATCH 1/2] wifi: mwifiex: simplify WPA flags setting
Posted by Francesco Dolcini 1 year, 5 months ago
On Wed, Jul 17, 2024 at 08:26:22AM +0200, Sascha Hauer wrote:
> On Tue, Jul 16, 2024 at 09:48:26PM +0200, Francesco Dolcini wrote:
> > On Tue, Jul 16, 2024 at 01:33:27PM +0200, Sascha Hauer wrote:
> > > The WPA flags setting only depends on the wpa_versions bitfield and not
> > > on the AKM suite, so move it out of the switch/case to simplify the code
> > > a bit. No functional change intended.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > 
> > Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com>
> > 
> > > ---
> > >  drivers/net/wireless/marvell/mwifiex/uap_cmd.c | 27 +++++++-------------------
> > >  1 file changed, 7 insertions(+), 20 deletions(-)
> > > 
> > > diff --git a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > > index 491e366119096..8d0cd84d27698 100644
> > > --- a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > > +++ b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > > @@ -46,31 +46,18 @@ int mwifiex_set_secure_params(struct mwifiex_private *priv,
> > >  
> > >  	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
> > >  
> > > +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
> > > +		bss_config->protocol = PROTOCOL_WPA;
> > > +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
> > > +		bss_config->protocol |= PROTOCOL_WPA2;
> > > +
> > 
> > I am wondering what happens if NL80211_WPA_VERSION_1 is not set, no idea
> > what's the content of bss_config->protocol ...
> > 
> > in any case this is not something that you introduced, but maybe worth
> > having a look?
> 
> bss_config is kzalloced in the only caller of mwifiex_set_secure_params(),
> so bss_config->protocol is zero on entry.
> 
> It might be worth setting it to zero explicitly here to make the code
> better understandable without having to look at the callers.

Thanks for looking into this, to me the change is fine as it is, up to
you if you want to improve it this way.

Francesco
Re: [PATCH 1/2] wifi: mwifiex: simplify WPA flags setting
Posted by Sascha Hauer 1 year, 5 months ago
On Wed, Jul 17, 2024 at 10:07:23AM +0200, Francesco Dolcini wrote:
> On Wed, Jul 17, 2024 at 08:26:22AM +0200, Sascha Hauer wrote:
> > On Tue, Jul 16, 2024 at 09:48:26PM +0200, Francesco Dolcini wrote:
> > > On Tue, Jul 16, 2024 at 01:33:27PM +0200, Sascha Hauer wrote:
> > > > The WPA flags setting only depends on the wpa_versions bitfield and not
> > > > on the AKM suite, so move it out of the switch/case to simplify the code
> > > > a bit. No functional change intended.
> > > > 
> > > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > > 
> > > Reviewed-by: Francesco Dolcini <francesco.dolcini@toradex.com>
> > > 
> > > > ---
> > > >  drivers/net/wireless/marvell/mwifiex/uap_cmd.c | 27 +++++++-------------------
> > > >  1 file changed, 7 insertions(+), 20 deletions(-)
> > > > 
> > > > diff --git a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > > > index 491e366119096..8d0cd84d27698 100644
> > > > --- a/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > > > +++ b/drivers/net/wireless/marvell/mwifiex/uap_cmd.c
> > > > @@ -46,31 +46,18 @@ int mwifiex_set_secure_params(struct mwifiex_private *priv,
> > > >  
> > > >  	bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
> > > >  
> > > > +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
> > > > +		bss_config->protocol = PROTOCOL_WPA;
> > > > +	if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
> > > > +		bss_config->protocol |= PROTOCOL_WPA2;
> > > > +
> > > 
> > > I am wondering what happens if NL80211_WPA_VERSION_1 is not set, no idea
> > > what's the content of bss_config->protocol ...
> > > 
> > > in any case this is not something that you introduced, but maybe worth
> > > having a look?
> > 
> > bss_config is kzalloced in the only caller of mwifiex_set_secure_params(),
> > so bss_config->protocol is zero on entry.
> > 
> > It might be worth setting it to zero explicitly here to make the code
> > better understandable without having to look at the callers.
> 
> Thanks for looking into this, to me the change is fine as it is, up to
> you if you want to improve it this way.

I just sent a v2 including this change.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |