Skip to contentSkip to conversation

Staging: rtl8192e: rtllib_wx

PATCH In review Felix Schlepper 2 participants 14 messages Jul 1, 2022 – Jul 2, 2022 Staging

lore
Share & tools
lore
#0 lore raw

v3 cover Staging: rtl8192e: rtllib_wx

This series addresses some issues raised by chechpatch.pl and some very minor refactoring.

v2:
- The first version, only addressed coding style issues. Now, I additionally refactored rtllib_modes and its uses, since there is no need to use string formatting.
- Logically separated one assignement into two. So we dont have 'fixed' = 'disabled', which was silly.

v3:
- Fixed a checkpatch.pl warning, which was introduced with patch 1/6.

Felix Schlepper (6):
Staging: rtl8192e: Refactored rtllib_modes
Staging: rtl8192e: Avoid multiple assignments
Staging: rtl8192e: Remove unnecessary parentheses
Staging: rtl8192e: Added braces around else
Staging: rtl8192e: Remove unnecessary blank line
Staging: rtl8192e: Added spaces around '+'

 drivers/staging/rtl8192e/rtllib_wx.c | 37 +++++++++++-----------------
 1 file changed, 15 insertions(+), 22 deletions(-)
Signature · 1 line
2.36.1
#3 lore raw

PATCH v3 2/6 Staging: rtl8192e: Avoid multiple assignments

This addresses an issue raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     CHECK: multiple assignments should be avoided
---
 drivers/staging/rtl8192e/rtllib_wx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +2 -1
index b7f19b38b0e1..121bf939c6a4 100644
@@ -149,7 +149,8 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
 			max_rate = rate;
 	}
 	iwe.cmd = SIOCGIWRATE;
-	iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
+	iwe.u.bitrate.disabled = 0;
+	iwe.u.bitrate.fixed = 0;
 	iwe.u.bitrate.value = max_rate * 500000;
 	start = iwe_stream_add_event_rsl(info, start, stop, &iwe, IW_EV_PARAM_LEN);
 	iwe.cmd = IWEVCUSTOM;
Signature · 1 line
2.36.1
#1 lore raw

PATCH v3 1/6 Staging: rtl8192e: Refactored rtllib_modes

In reply to Felix Schlepper

The initial reason for looking at this code was an issue raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     CHECK: Please use a blank line after function/struct/union/enum
     declarations

The additional blank line above the struct/before the headers is just cleaner.

However, as it turns out since there is no str formatting required One can replace the error prone str + size struct with a char array. The rest of this patch fixes the usecases.

---
 drivers/staging/rtl8192e/rtllib_wx.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +6 -15
index cf9a240924f2..b7f19b38b0e1 100644
@@ -17,17 +17,9 @@
 #include <linux/module.h>
 #include <linux/etherdevice.h>
 #include "rtllib.h"
-struct modes_unit {
-	char *mode_string;
-	int mode_size;
-};
-static struct modes_unit rtllib_modes[] = {
-	{"a", 1},
-	{"b", 1},
-	{"g", 1},
-	{"?", 1},
-	{"N-24G", 5},
-	{"N-5G", 4},
+
+static const char * const rtllib_modes[] = {
+	"a", "b", "g", "?", "N-24G", "N-5G"
 };
 
 #define MAX_CUSTOM_LEN 64
@@ -72,10 +64,9 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
 	/* Add the protocol name */
 	iwe.cmd = SIOCGIWNAME;
 	for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {
-		if (network->mode&(1<<i)) {
-			sprintf(pname, rtllib_modes[i].mode_string,
-				rtllib_modes[i].mode_size);
-			pname += rtllib_modes[i].mode_size;
+		if (network->mode & BIT(i)) {
+			strcpy(pname, rtllib_modes[i]);
+			pname += strlen(rtllib_modes[i]);
 		}
 	}
 	*pname = '\0';
Signature · 1 line
2.36.1
#5 lore raw

PATCH v3 3/6 Staging: rtl8192e: Remove unnecessary parentheses

In reply to Felix Schlepper

This addresses an issue raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     Unnecessary parentheses around wrqu->encoding
---
 drivers/staging/rtl8192e/rtllib_wx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +2 -2
index 121bf939c6a4..db076e819993 100644
@@ -277,7 +277,7 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
 			 struct iw_request_info *info,
 			 union iwreq_data *wrqu, char *keybuf)
 {
-	struct iw_point *erq = &(wrqu->encoding);
+	struct iw_point *erq = &wrqu->encoding;
 	struct net_device *dev = ieee->dev;
 	struct rtllib_security sec = {
 		.flags = 0
@@ -449,7 +449,7 @@ int rtllib_wx_get_encode(struct rtllib_device *ieee,
 			 struct iw_request_info *info,
 			 union iwreq_data *wrqu, char *keybuf)
 {
-	struct iw_point *erq = &(wrqu->encoding);
+	struct iw_point *erq = &wrqu->encoding;
 	int len, key;
 	struct lib80211_crypt_data *crypt;
 
Signature · 1 line
2.36.1
#7 lore raw

PATCH v3 4/6 Staging: rtl8192e: Added braces around else

In reply to Felix Schlepper

This addresses two issues raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     CHECK: braces {} should be used on all arms of this statement
     CHECK: Unbalanced braces around else statement

The coding style rule with not using unnecessary braces around if/else does not apply if only one branch is a single statement.

---
 drivers/staging/rtl8192e/rtllib_wx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +4 -2
index db076e819993..b949e7234150 100644
@@ -304,8 +304,9 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
 			netdev_dbg(ieee->dev,
 				   "Disabling encryption on key %d.\n", key);
 			lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
-		} else
+		} else {
 			netdev_dbg(ieee->dev, "Disabling encryption.\n");
+		}
 
 		/* Check all the keys to see if any are still configured,
 		 * and if no key index was provided, de-init them all
@@ -724,8 +725,9 @@ int rtllib_wx_set_auth(struct rtllib_device *ieee,
 		} else if (data->value & IW_AUTH_ALG_LEAP) {
 			ieee->open_wep = 1;
 			ieee->auth_mode = 2;
-		} else
+		} else {
 			return -EINVAL;
+		}
 		break;
 
 	case IW_AUTH_WPA_ENABLED:
Signature · 1 line
2.36.1
#9 lore raw

PATCH v3 5/6 Staging: rtl8192e: Remove unnecessary blank line

In reply to Felix Schlepper

This addresses an issue raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     CHECK: Blank lines aren't necessary before a close brace '}'
---
 drivers/staging/rtl8192e/rtllib_wx.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +0 -1
index b949e7234150..6b11908032d7 100644
@@ -601,7 +601,6 @@ int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
 			goto done;
 		}
 		*crypt = new_crypt;
-
 	}
 
 	if (ext->key_len > 0 && (*crypt)->ops->set_key &&
Signature · 1 line
2.36.1
#11 lore raw

PATCH v3 6/6 Staging: rtl8192e: Added spaces around '+'

In reply to Felix Schlepper

This addresses two issues raised by checkpatch.pl:

     $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
     CHECK: spaces preferred around that '+' (ctx:VxV)
---
 drivers/staging/rtl8192e/rtllib_wx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +1 -1
index 6b11908032d7..da2c41c9b92f 100644
@@ -769,7 +769,7 @@ int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len)
 	kfree(ieee->wps_ie);
 	ieee->wps_ie = NULL;
 	if (len) {
-		if (len != ie[1]+2)
+		if (len != ie[1] + 2)
 			return -EINVAL;
 		buf = kmemdup(ie, len, GFP_KERNEL);
 		if (!buf)
Signature · 1 line
2.36.1
Tested-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] Staging: rtl8192e: Refactored rtllib_modes

In reply to Felix Schlepper
Quoted 48 lines · Felix Schlepper

The initial reason for looking at this code was an issue raised by checkpatch.pl:

      $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
      CHECK: Please use a blank line after function/struct/union/enum
      declarations

The additional blank line above the struct/before the headers is just cleaner.

However, as it turns out since there is no str formatting required One can replace the error prone str + size struct with a char array. The rest of this patch fixes the usecases.

---
  drivers/staging/rtl8192e/rtllib_wx.c | 21 ++++++---------------
  1 file changed, 6 insertions(+), 15 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +3 -11
index cf9a240924f2..b7f19b38b0e1 100644
@@ -17,17 +17,9 @@
  #include <linux/module.h>
  #include <linux/etherdevice.h>
  #include "rtllib.h"
-struct modes_unit {
-	char *mode_string;
-	int mode_size;
-};
-static struct modes_unit rtllib_modes[] = {
-	{"a", 1},
-	{"b", 1},
-	{"g", 1},
-	{"?", 1},
-	{"N-24G", 5},
-	{"N-5G", 4},
+
+static const char * const rtllib_modes[] = {
+	"a", "b", "g", "?", "N-24G", "N-5G"
  };
 
  #define MAX_CUSTOM_LEN 64
@@ -72,10 +64,9 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
  	/* Add the protocol name */
  	iwe.cmd = SIOCGIWNAME;
  	for (i = 0; i < ARRAY_SIZE(rtllib_modes); i++) {

drivers/staging/rtl8192e/rtllib_wx.c static inline char *rtl819x_translate_scan(struct rtllib_device *ieee, · line 72

Quoted 10 lines
drivers/staging/rtl8192e/rtllib_wx.c +3 -4
-		if (network->mode&(1<<i)) {
-			sprintf(pname, rtllib_modes[i].mode_string,
-				rtllib_modes[i].mode_size);
-			pname += rtllib_modes[i].mode_size;
+		if (network->mode & BIT(i)) {
+			strcpy(pname, rtllib_modes[i]);
+			pname += strlen(rtllib_modes[i]);
  		}
  	}
  	*pname = '\0';
Tested-by on v3 2/6
#4 lore raw

Re: [PATCH v3 2/6] Staging: rtl8192e: Avoid multiple assignments

In reply to Felix Schlepper
Quoted 15 lines · Felix Schlepper

This addresses an issue raised by checkpatch.pl:

      $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
      CHECK: multiple assignments should be avoided
---
  drivers/staging/rtl8192e/rtllib_wx.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
index b7f19b38b0e1..121bf939c6a4 100644

drivers/staging/rtl8192e/rtllib_wx.c static inline char *rtl819x_translate_scan(struct rtllib_device *ieee, · line 156

Quoted 9 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -1
@@ -149,7 +149,8 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
  			max_rate = rate;
  	}
  	iwe.cmd = SIOCGIWRATE;
-	iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
+	iwe.u.bitrate.disabled = 0;
+	iwe.u.bitrate.fixed = 0;
  	iwe.u.bitrate.value = max_rate * 500000;
  	start = iwe_stream_add_event_rsl(info, start, stop, &iwe, IW_EV_PARAM_LEN);
  	iwe.cmd = IWEVCUSTOM;
Tested-by on v3 3/6
#6 lore raw

Re: [PATCH v3 3/6] Staging: rtl8192e: Remove unnecessary parentheses

In reply to Felix Schlepper
Quoted 24 lines · Felix Schlepper

This addresses an issue raised by checkpatch.pl:

      $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
      Unnecessary parentheses around wrqu->encoding
---
  drivers/staging/rtl8192e/rtllib_wx.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +1 -1
index 121bf939c6a4..db076e819993 100644
@@ -277,7 +277,7 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
  			 struct iw_request_info *info,
  			 union iwreq_data *wrqu, char *keybuf)
  {
-	struct iw_point *erq = &(wrqu->encoding);
+	struct iw_point *erq = &wrqu->encoding;
  	struct net_device *dev = ieee->dev;
  	struct rtllib_security sec = {
  		.flags = 0

drivers/staging/rtl8192e/rtllib_wx.c int rtllib_wx_get_encode(struct rtllib_device *ieee, · line 455

Quoted 8 lines
drivers/staging/rtl8192e/rtllib_wx.c +1 -1
@@ -449,7 +449,7 @@ int rtllib_wx_get_encode(struct rtllib_device *ieee,
  			 struct iw_request_info *info,
  			 union iwreq_data *wrqu, char *keybuf)
  {
-	struct iw_point *erq = &(wrqu->encoding);
+	struct iw_point *erq = &wrqu->encoding;
  	int len, key;
  	struct lib80211_crypt_data *crypt;
 
Tested-by on v3 4/6
#8 lore raw

Re: [PATCH v3 4/6] Staging: rtl8192e: Added braces around else

In reply to Felix Schlepper
Quoted 30 lines · Felix Schlepper

This addresses two issues raised by checkpatch.pl:

      $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
      CHECK: braces {} should be used on all arms of this statement
      CHECK: Unbalanced braces around else statement

The coding style rule with not using unnecessary braces around if/else does not apply if only one branch is a single statement.

---
  drivers/staging/rtl8192e/rtllib_wx.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +2 -1
index db076e819993..b949e7234150 100644
@@ -304,8 +304,9 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
  			netdev_dbg(ieee->dev,
  				   "Disabling encryption on key %d.\n", key);
  			lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt);
-		} else
+		} else {
  			netdev_dbg(ieee->dev, "Disabling encryption.\n");
+		}
 
  		/* Check all the keys to see if any are still configured,
  		 * and if no key index was provided, de-init them all

drivers/staging/rtl8192e/rtllib_wx.c int rtllib_wx_set_auth(struct rtllib_device *ieee, · line 733

Quoted 10 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -1
@@ -724,8 +725,9 @@ int rtllib_wx_set_auth(struct rtllib_device *ieee,
  		} else if (data->value & IW_AUTH_ALG_LEAP) {
  			ieee->open_wep = 1;
  			ieee->auth_mode = 2;
-		} else
+		} else {
  			return -EINVAL;
+		}
  		break;
 
  	case IW_AUTH_WPA_ENABLED:
Tested-by on v3 5/6
#10 lore raw

Re: [PATCH v3 5/6] Staging: rtl8192e: Remove unnecessary blank line

In reply to Felix Schlepper
Quoted 15 lines · Felix Schlepper

This addresses an issue raised by checkpatch.pl:

      $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
      CHECK: Blank lines aren't necessary before a close brace '}'
---
  drivers/staging/rtl8192e/rtllib_wx.c | 1 -
  1 file changed, 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
index b949e7234150..6b11908032d7 100644

drivers/staging/rtl8192e/rtllib_wx.c int rtllib_wx_set_encode_ext(struct rtllib_device *ieee, · line 606

Quoted 7 lines
drivers/staging/rtl8192e/rtllib_wx.c +0 -1
@@ -601,7 +601,6 @@ int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
  			goto done;
  		}
  		*crypt = new_crypt;
-
  	}
 
  	if (ext->key_len > 0 && (*crypt)->ops->set_key &&
Tested-by on v3 6/6
#12 lore raw

Re: [PATCH v3 6/6] Staging: rtl8192e: Added spaces around '+'

In reply to Felix Schlepper
Quoted 15 lines · Felix Schlepper

This addresses two issues raised by checkpatch.pl:

      $ ./scripts/checkpatch.pl --terse -f drivers/staging/rtl8192e/rtllib_wx.c
      CHECK: spaces preferred around that '+' (ctx:VxV)
---
  drivers/staging/rtl8192e/rtllib_wx.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
index 6b11908032d7..da2c41c9b92f 100644

drivers/staging/rtl8192e/rtllib_wx.c int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len) · line 775

Quoted 8 lines
drivers/staging/rtl8192e/rtllib_wx.c +1 -1
@@ -769,7 +769,7 @@ int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len)
  	kfree(ieee->wps_ie);
  	ieee->wps_ie = NULL;
  	if (len) {
-		if (len != ie[1]+2)
+		if (len != ie[1] + 2)
  			return -EINVAL;
  		buf = kmemdup(ie, len, GFP_KERNEL);
  		if (!buf)
Tested-by on the v3 series
#13 lore raw
In reply to Felix Schlepper
Quoted 21 lines · Felix Schlepper

This series addresses some issues raised by chechpatch.pl and some very minor refactoring.

v2:
- The first version, only addressed coding style issues. Now, I additionally refactored rtllib_modes and its uses, since there is no need to use string formatting.
- Logically separated one assignement into two. So we dont have 'fixed' = 'disabled', which was silly.

v3:
- Fixed a checkpatch.pl warning, which was introduced with patch 1/6.

Felix Schlepper (6):
Staging: rtl8192e: Refactored rtllib_modes
Staging: rtl8192e: Avoid multiple assignments
Staging: rtl8192e: Remove unnecessary parentheses
Staging: rtl8192e: Added braces around else
Staging: rtl8192e: Remove unnecessary blank line
Staging: rtl8192e: Added spaces around '+'

Quoted 3 lines
  drivers/staging/rtl8192e/rtllib_wx.c | 37 +++++++++++-----------------
  1 file changed, 15 insertions(+), 22 deletions(-)

Sorry for sending one email for each patch. Next time I will just send one mail for one patch series.

When compiling I saw that the driver is divided into more modules. So the r8192e_pci.ko is not touched by this patch series.

kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ make -C . M=drivers/staging/rtl8192e
make: Entering directory '/home/kernel/Documents/git/kernels/staging'
  CC [M]  drivers/staging/rtl8192e/rtllib_wx.o
  LD [M]  drivers/staging/rtl8192e/rtllib.o
  MODPOST drivers/staging/rtl8192e/Module.symvers
  CC [M]  drivers/staging/rtl8192e/rtllib.mod.o
  LD [M]  drivers/staging/rtl8192e/rtllib.ko
make: Leaving directory '/home/kernel/Documents/git/kernels/staging'
kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ sudo insmod drivers/staging/rtl8192e/rtllib.ko
kernel@matrix-ESPRIMO-P710:~/Documents/git/kernels/staging$ sudo insmod drivers/staging/rtl8192e/rtl8192e/r8192e_pci.ko