Skip to contentSkip to conversation

Staging: rtl8192e: rtllib_wx.c coding style

PATCH In review Felix Schlepper 3 participants 12 messages Jun 28, 2022 – Jun 29, 2022 Staging

lore
Share & tools
lore
#0 lore raw

cover Staging: rtl8192e: rtllib_wx.c coding style

This series addresses some issues raised by chechpatch.pl. There are no logical changes, just addressing coding style. I 'tested' it by bulding.

Felix Schlepper (7):
Staging: rtl8192e: Added blank lines before/after struct
Staging: rtl8192e: Added spaces around binary operators
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 | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/7 Staging: rtl8192e: Added blank lines before/after struct

This addresses 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.

---
 drivers/staging/rtl8192e/rtllib_wx.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/rtl8192e/rtllib_wx.c +2 -0
index cf9a240924f2..3b81a3395527 100644
@@ -17,10 +17,12 @@
 #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},
Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH 1/7] Staging: rtl8192e: Added blank lines before/after struct

Quoted 8 lines · Felix Schlepper

This addresses 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.

[]

drivers/staging/rtl8192e/rtllib_wx.c

Quoted 1 line
drivers/staging/rtl8192e/rtllib_wx.c +0 -0

[]

drivers/staging/rtl8192e/rtllib_wx.c line 28

Quoted 13 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -0
@@ -17,10 +17,12 @@
 #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},

Please always look deeper at the code and do not simply take any checkpatch suggestion as the "best" fix.

Using this struct style with an embedded length is error prone and would likely be better as a simple char * array.

Also, the existing sprintf use of mode_string and mode_size is nonsensical. There is nothing to format in any of the mode_size. so the use of mode_size as an argument is silly.

Perhaps something like this would be better:

---
 drivers/staging/rtl8192e/rtllib_wx.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +5 -16
index cf9a240924f20..90dcce152d80c 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 *rtllib_modes[] = {
+	"a", "b", "g", "?", "N-24G", "N-5G",
 };
 
 #define MAX_CUSTOM_LEN 64
@@ -72,11 +64,8 @@ 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))
+			pname = stpcpy(pname, rtllib_modes[i]);
 	}
 	*pname = '\0';
 	snprintf(iwe.u.name, IFNAMSIZ, "IEEE802.11%s", proto_name);
#3 lore raw

Re: [PATCH 1/7] Staging: rtl8192e: Added blank lines before/after struct

Quoted 29 lines · Joe Perches
Quoted 8 lines · Felix Schlepper

This addresses 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.

[]

drivers/staging/rtl8192e/rtllib_wx.c

Quoted 1 line
drivers/staging/rtl8192e/rtllib_wx.c +0 -0

[]

drivers/staging/rtl8192e/rtllib_wx.c line 28

Quoted 13 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -0
@@ -17,10 +17,12 @@
 #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},

Please always look deeper at the code and do not simply take any checkpatch suggestion as the "best" fix.

Quoted 6 lines

Using this struct style with an embedded length is error prone and would likely be better as a simple char * array.

Also, the existing sprintf use of mode_string and mode_size is nonsensical. There is nothing to format in any of the mode_size. so the use of mode_size as an argument is silly.

First of all, thank you for your suggestions.
I did realize that there is nothing to format, but I did not dare to make that change in case a format could be added.
However, looking at it now. This has not been touched in over 10 years. So it is probably safe to change that.

Quoted 34 lines

Perhaps something like this would be better:

---
 drivers/staging/rtl8192e/rtllib_wx.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +3 -11
index cf9a240924f20..90dcce152d80c 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 *rtllib_modes[] = {
+	"a", "b", "g", "?", "N-24G", "N-5G",
 };
 
 #define MAX_CUSTOM_LEN 64
@@ -72,11 +64,8 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
 	/* Add the protocol name */
 	iwe.cmd = SIOCGIWNAME;

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

Quoted 10 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -5
 	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))
+			pname = stpcpy(pname, rtllib_modes[i]);
 	}
 	*pname = '\0';

Would this not be also redundant since stpcpy already returns a pointer to the new NUL-terminating character?

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

Quoted 2 lines
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
 	snprintf(iwe.u.name, IFNAMSIZ, "IEEE802.11%s", proto_name);

Will resubmit later.

Cheers
Felix Schlepper

#4 lore raw

Re: [PATCH 1/7] Staging: rtl8192e: Added blank lines before/after struct

Quoted 71 lines · Felix Schlepper
Quoted 29 lines · Joe Perches
Quoted 8 lines · Felix Schlepper

This addresses 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.

[]

drivers/staging/rtl8192e/rtllib_wx.c

Quoted 1 line
drivers/staging/rtl8192e/rtllib_wx.c +0 -0

[]

drivers/staging/rtl8192e/rtllib_wx.c line 28

Quoted 13 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -0
@@ -17,10 +17,12 @@
 #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},

Please always look deeper at the code and do not simply take any checkpatch suggestion as the "best" fix.

Quoted 6 lines

Using this struct style with an embedded length is error prone and would likely be better as a simple char * array.

Also, the existing sprintf use of mode_string and mode_size is nonsensical. There is nothing to format in any of the mode_size. so the use of mode_size as an argument is silly.

First of all, thank you for your suggestions.
I did realize that there is nothing to format, but I did not dare to make that change in case a format could be added.
However, looking at it now. This has not been touched in over 10 years. So it is probably safe to change that.

Quoted 30 lines

Perhaps something like this would be better:

---
 drivers/staging/rtl8192e/rtllib_wx.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)
drivers/staging/rtl8192e/rtllib_wx.c +3 -11
index cf9a240924f20..90dcce152d80c 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 *rtllib_modes[] = {
+	"a", "b", "g", "?", "N-24G", "N-5G",
 };
 
Quoted 17 lines
Quoted 4 lines
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
 #define MAX_CUSTOM_LEN 64
@@ -72,11 +64,8 @@ static inline char *rtl819x_translate_scan(struct rtllib_device *ieee,
 	/* Add the protocol name */
 	iwe.cmd = SIOCGIWNAME;

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

Quoted 10 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -5
 	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))
+			pname = stpcpy(pname, rtllib_modes[i]);
 	}
 	*pname = '\0';

Would this not be also redundant since stpcpy already returns a pointer to the new NUL-terminating character?

Quoted 1 line
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
 	snprintf(iwe.u.name, IFNAMSIZ, "IEEE802.11%s", proto_name);

Only if proto_name is initialized. Is it?

Also I believe stpcpy is not a standard linux call, so maybe this needs to be strcpy or strncpy then strlen.

#5 lore raw

PATCH 2/7 Staging: rtl8192e: Added spaces around binary operators

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)
     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 3b81a3395527..7bd1e829ff7e 100644
@@ -74,7 +74,7 @@ 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)) {
+		if (network->mode & (1 << i)) {
 			sprintf(pname, rtllib_modes[i].mode_string,
 				rtllib_modes[i].mode_size);
 			pname += rtllib_modes[i].mode_size;
Signature · 1 line
2.36.1
#6 lore raw

PATCH 3/7 Staging: rtl8192e: Avoid multiple assignments

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: multiple assignments should be avoided

This patch does not change the logical of the assignments.

---
 drivers/staging/rtl8192e/rtllib_wx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +2 -1
index 7bd1e829ff7e..c8fc66113b41 100644
@@ -160,7 +160,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 = iwe.u.bitrate.disabled;
 	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
#7 lore raw

Re: [PATCH 3/7] Staging: rtl8192e: Avoid multiple assignments

Quoted 17 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

This patch does not change the logical of the assignments.

---
 drivers/staging/rtl8192e/rtllib_wx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8192e/rtllib_wx.c +0 -0
index 7bd1e829ff7e..c8fc66113b41 100644

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

Quoted 6 lines
drivers/staging/rtl8192e/rtllib_wx.c +2 -1
@@ -160,7 +160,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 = iwe.u.bitrate.disabled;
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This assignment makes no sense. Why are we setting fixed = disabled? If you're going to split it apart do:

	iwe.u.bitrate.disabled = 0;
	iwe.u.bitrate.fixed = 0;

regards,
dan carpenter

#8 lore raw

PATCH 4/7 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 c8fc66113b41..f1a497ff4aa6 100644
@@ -288,7 +288,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
@@ -460,7 +460,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
#9 lore raw

PATCH 5/7 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 f1a497ff4aa6..976d81f0d7a6 100644
@@ -315,8 +315,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
@@ -735,8 +736,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
#10 lore raw

PATCH 6/7 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 976d81f0d7a6..9945f3f136d1 100644
@@ -612,7 +612,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 7/7 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 9945f3f136d1..52e5e4e5977b 100644
@@ -780,7 +780,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