Skip to contentSkip to conversation

staging: r8188eu: refactor rtw_is_cckrates_included()

PATCH In review Michael Straube 3 participants 11 messages Aug 16, 2021 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 staging: r8188eu: refactor rtw_is_cckrates_included()

Refactor function rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +4 -5
index 0c7231cefdda..964255a8c778 100644
@@ -70,14 +70,13 @@ int rtw_get_bit_value_from_ieee_value(u8 val)
 
 uint	rtw_is_cckrates_included(u8 *rate)
 {
-	u32	i = 0;
+	u8 r;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+	while ((r = *rate++ & 0x7f)) {
+		if (r == 2 || r == 4 || r == 11 || r == 22)
 			return true;
-		i++;
 	}
+
 	return false;
 }
 
Signature · 1 line
2.32.0
#1 lore raw

PATCH v2 2/4 staging: r8188eu: convert rtw_is_cckrates_included() to bool

Function rtw_is_cckrates_included() returns boolean values. Change the return type to bool to reflect this.

---
v1 -> v2
Rewritten to apply with v2 of patch 1/4.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +-
 drivers/staging/r8188eu/include/ieee80211.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -1
index 964255a8c778..53556f1af425 100644
@@ -68,7 +68,7 @@ int rtw_get_bit_value_from_ieee_value(u8 val)
 	return 0;
 }
 
-uint	rtw_is_cckrates_included(u8 *rate)
+bool rtw_is_cckrates_included(u8 *rate)
 {
 	u8 r;
 
drivers/staging/r8188eu/include/ieee80211.h +1 -1
index bc5b030e9c40..cbefd7af1d4f 100644
@@ -1206,7 +1206,7 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv);
 
 int rtw_get_bit_value_from_ieee_value(u8 val);
 
-uint	rtw_is_cckrates_included(u8 *rate);
+bool rtw_is_cckrates_included(u8 *rate);
 
 uint	rtw_is_cckratesonly_included(u8 *rate);
 
Signature · 1 line
2.32.0
#3 lore raw

PATCH v2 3/4 staging: r8188eu: refactor rtw_is_cckratesonly_included()

In reply to Michael Straube

Refactor function rtw_is_cckratesonly_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +3 -5
index 53556f1af425..b1427e70cdf7 100644
@@ -82,13 +82,11 @@ bool rtw_is_cckrates_included(u8 *rate)
 
 uint	rtw_is_cckratesonly_included(u8 *rate)
 {
-	u32 i = 0;
+	u8 r;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
-		     (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
+	while ((r = *rate++ & 0x7f)) {
+		if (r != 2 && r != 4 && r != 11 && r != 22)
 			return false;
-		i++;
 	}
 
 	return true;
Signature · 1 line
2.32.0
Acked-by on v2 3/4
#4 lore raw

Re: [PATCH v2 3/4] staging: r8188eu: refactor rtw_is_cckratesonly_included()

Quoted 10 lines · CEST Michael Straube

Refactor function rtw_is_cckratesonly_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Thanks,

Fabio

#5 lore raw

PATCH v2 4/4 staging: r8188eu: convert rtw_is_cckratesonly_included() to bool

In reply to Michael Straube

Function rtw_is_cckratesonly_included() returns boolean values. Change the return type to bool to reflect this.

---
v1 -> v2
Rewritten to apply with v2 of patch 3/4.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +-
 drivers/staging/r8188eu/include/ieee80211.h  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -1
index b1427e70cdf7..a91c8d52a123 100644
@@ -80,7 +80,7 @@ bool rtw_is_cckrates_included(u8 *rate)
 	return false;
 }
 
-uint	rtw_is_cckratesonly_included(u8 *rate)
+bool rtw_is_cckratesonly_included(u8 *rate)
 {
 	u8 r;
 
drivers/staging/r8188eu/include/ieee80211.h +1 -2
index cbefd7af1d4f..1205d13171b2 100644
@@ -1207,8 +1207,7 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv);
 int rtw_get_bit_value_from_ieee_value(u8 val);
 
 bool rtw_is_cckrates_included(u8 *rate);
-
-uint	rtw_is_cckratesonly_included(u8 *rate);
+bool rtw_is_cckratesonly_included(u8 *rate);
 
 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
 
Signature · 1 line
2.32.0
Acked-by on v2 4/4
#6 lore raw

Re: [PATCH v2 4/4] staging: r8188eu: convert rtw_is_cckratesonly_included() to bool

Quoted 11 lines · CEST Michael Straube

Function rtw_is_cckratesonly_included() returns boolean values. Change the return type to bool to reflect this.

---
v1 -> v2
Rewritten to apply with v2 of patch 3/4.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 2 +-
 drivers/staging/r8188eu/include/ieee80211.h  | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

Thanks,

Fabio

Acked-by on v2 1/4
#7 lore raw
In reply to Michael Straube
Quoted 11 lines · CEST Michael Straube

Refactor function rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.

Nice work, although you chose to not take Joe's suggestion about making a helper inline function. That would have been perfect, but I think it is a minor issue. So...

Regards,

Fabio

P.S.: If I were you, I'd have provided a cover letter that would have helped the readers to immediately understand the purpose of the entire series. I'm not sure whether or not the above-mentioned cover is a strict requirement.

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/staging/r8188eu/core/rtw_ieee80211.c index 0c7231cefdda..

964255a8c778 100644

drivers/staging/r8188eu/core/rtw_ieee80211.c int rtw_get_bit_value_from_ieee_value(u8 val) · line 76

Quoted 11 lines
drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -3
@@ -70,14 +70,13 @@ int rtw_get_bit_value_from_ieee_value(u8 val)
 
 uint	rtw_is_cckrates_included(u8 *rate)
 {
-	u32	i = 0;
+	u8 r;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) 

== 4) ||

drivers/staging/r8188eu/core/rtw_ieee80211.c int rtw_get_bit_value_from_ieee_value(u8 val) · line 77

Quoted 1 line
drivers/staging/r8188eu/core/rtw_ieee80211.c +0 -1
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) 

== 22))

Quoted 8 lines
drivers/staging/r8188eu/core/rtw_ieee80211.c +3 -1
+	while ((r = *rate++ & 0x7f)) {
+		if (r == 2 || r == 4 || r == 11 || r == 22)
 			return true;
-		i++;
 	}
+
 	return false;
 }
#8 lore raw
Quoted 9 lines · Fabio M. De Francesco
Quoted 8 lines · CEST Michael Straube

Refactor function rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

Quoted 7 lines
Quoted 3 lines

 drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++-----

 1 file changed, 4 insertions(+), 5 deletions(-)

Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.

Perhaps do the whole thing in one go (moving the & 0x7f into the helper avoids an early loop exit defect when the rate being indexed is 0x80)

---
 drivers/staging/r8188eu/core/rtw_ieee80211.c | 33 +++++++++++++++-------------
 drivers/staging/r8188eu/include/ieee80211.h  |  5 ++---
 drivers/staging/r8188eu/os_dep/ioctl_linux.c |  4 ++--
 3 files changed, 22 insertions(+), 20 deletions(-)
drivers/staging/r8188eu/core/rtw_ieee80211.c +18 -15
index ff77e686721ce..f02863caddde7 100644
@@ -68,28 +68,31 @@ int rtw_get_bit_value_from_ieee_value(u8 val)
 	return 0;
 }
 
-uint	rtw_is_cckrates_included(u8 *rate)
+static bool rtw_is_cckrate(u8 rate)
 {
-	u32	i = 0;
+	rate &= 0x7f;
+	return rate == 2 || rate == 4 || rate == 11 || rate == 22;
+}
+
+bool rtw_is_cckrates_included(u8 *rate)
+{
+	u8 r;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+	while ((r = *rate++)) {
+		if (rtw_is_cckrate(r))
 			return true;
-		i++;
 	}
+
 	return false;
 }
 
-uint	rtw_is_cckratesonly_included(u8 *rate)
+bool rtw_is_cckratesonly_included(u8 *rate)
 {
-	u32 i = 0;
+	u8 r;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
-		     (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
+	while ((r = *rate++)) {
+		if (!rtw_is_cckrate(r))
 			return false;
-		i++;
 	}
 
 	return true;
@@ -98,14 +101,14 @@ uint	rtw_is_cckratesonly_included(u8 *rate)
 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
 {
 	if (channel > 14) {
-		if ((rtw_is_cckrates_included(rate)) == true)
+		if ((rtw_is_cckrates_included(rate)))
 			return WIRELESS_INVALID;
 		else
 			return WIRELESS_11A;
 	} else {  /*  could be pure B, pure G, or B/G */
-		if ((rtw_is_cckratesonly_included(rate)) == true)
+		if ((rtw_is_cckratesonly_included(rate)))
 			return WIRELESS_11B;
-		else if ((rtw_is_cckrates_included(rate)) == true)
+		else if ((rtw_is_cckrates_included(rate)))
 			return	WIRELESS_11BG;
 		else
 			return WIRELESS_11G;
drivers/staging/r8188eu/include/ieee80211.h +2 -3
index 4dfa817175e77..890419d201903 100644
@@ -1225,9 +1225,8 @@ int rtw_generate_ie(struct registry_priv *pregistrypriv);
 
 int rtw_get_bit_value_from_ieee_value(u8 val);
 
-uint	rtw_is_cckrates_included(u8 *rate);
-
-uint	rtw_is_cckratesonly_included(u8 *rate);
+bool rtw_is_cckrates_included(u8 *rate);
+bool rtw_is_cckratesonly_included(u8 *rate);
 
 int rtw_check_network_type(unsigned char *rate, int ratelen, int channel);
 
drivers/staging/r8188eu/os_dep/ioctl_linux.c +2 -2
index a94946ad11fce..37ab633acb982 100644
@@ -784,12 +784,12 @@ static int rtw_wx_get_name(struct net_device *dev,
 
 		prates = &pcur_bss->SupportedRates;
 
-		if (rtw_is_cckratesonly_included((u8 *)prates) == true) {
+		if (rtw_is_cckratesonly_included((u8 *)prates)) {
 			if (ht_cap)
 				snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bn");
 			else
 				snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
-		} else if ((rtw_is_cckrates_included((u8 *)prates)) == true) {
+		} else if ((rtw_is_cckrates_included((u8 *)prates))) {
 			if (ht_cap)
 				snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11bgn");
 			else
#9 lore raw
Quoted 14 lines · Joe Perches
Quoted 13 lines · Fabio M. De Francesco
Quoted 11 lines · CEST Michael Straube

Refactor function rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

  drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 3 lines

Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.

Perhaps do the whole thing in one go (moving the & 0x7f into the helper avoids an early loop exit defect when the rate being indexed is 0x80)

I will send v3 with your suggestions. The comparsions to boolean ( ... == true ) will be addressed in a separate series that cleans up comparsions to true/false in all files.

Regards,
Michael

#10 lore raw
In reply to Joe Perches
Quoted 14 lines · Joe Perches
Quoted 13 lines · Fabio M. De Francesco
Quoted 11 lines · CEST Michael Straube

Refactor function rtw_is_cckrates_included(). Improves readability and slightly reduces object file size.

---
v1 -> v2
Refactored to more compact code as suggested by Joe Perches.

  drivers/staging/r8188eu/core/rtw_ieee80211.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
Quoted 7 lines
Quoted 3 lines

Thanks for redoing the series as suggested by Joe Perches. This is a perfect case where conciseness and readability don't clash and instead the former enhances the latter.

Perhaps do the whole thing in one go (moving the & 0x7f into the helper avoids an early loop exit defect when the rate being indexed is 0x80)

I have sent a new patch that does the refactoring in one go, so this series is obsolete now. ;)

Regards,
Michael