Skip to contentSkip to conversation

staging: r8188eu: refactor rtw_is_cckrates_included()

PATCH Superseded Michael Straube 2 participants 5 messages Aug 16, 2021 Staging

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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

---
 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..beff2ab73a1a 100644
@@ -70,13 +70,12 @@ int rtw_get_bit_value_from_ieee_value(u8 val)
 
 uint	rtw_is_cckrates_included(u8 *rate)
 {
-	u32	i = 0;
+	while (*rate) {
+		u8 r = *rate & 0x7f;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+		if (r == 2 || r == 4 || r == 11 || r == 22)
 			return true;
-		i++;
+		rate++;
 	}
 	return false;
 }
Signature · 1 line
2.32.0
#1 lore raw

PATCH 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.

---
 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 beff2ab73a1a..c8627ad83006 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)
 {
 	while (*rate) {
 		u8 r = *rate & 0x7f;
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
#2 lore raw

PATCH 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.

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

PATCH 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.

---
 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 200c90b8ea51..fdbedc99f798 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)
 {
 	while (*rate) {
 		u8 r = *rate & 0x7f;
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
#4 lore raw
In reply to Michael Straube
Quoted 2 lines · Michael Straube

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

[]

drivers/staging/r8188eu/core/rtw_ieee80211.c

Quoted 1 line
drivers/staging/r8188eu/core/rtw_ieee80211.c +0 -0

[]

Quoted 16 lines
drivers/staging/r8188eu/core/rtw_ieee80211.c +0 -0
@@ -70,13 +70,12 @@ int rtw_get_bit_value_from_ieee_value(u8 val)

 uint rtw_is_cckrates_included(u8 *rate)
 {

drivers/staging/r8188eu/core/rtw_ieee80211.c +3 -4
-	u32	i = 0;
+	while (*rate) {
+		u8 r = *rate & 0x7f;
 
-	while (rate[i] != 0) {
-		if  ((((rate[i]) & 0x7f) == 2) || (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+		if (r == 2 || r == 4 || r == 11 || r == 22)

  return true;

drivers/staging/r8188eu/core/rtw_ieee80211.c +1 -1
-		i++;
+		rate++;
Quoted 3 lines

  }
  return false;
 }

Bikeshed:

More compact code with only 1 reference of rate not 3 is more readable to at least me.

	u8 r;

	while ((r = *rate++ & 0x7f)) {
		if (r == 2 || r == 4 || r == 11 || r == 22)
			return true;
	}

	return false;

And you might make a static inline for the test of r so it could be reused in the rtw_is_cckratesonly_included function

static inline bool is_cckrate(u8 rate)

{
	return rate == 2 || rate == 4 || rate == 11 || rate == 22;
}

so this could be:

	u8 r;

	while ((r = *rate++ & 0x7f)) {
		if (is_cckrate(r))
			return true;
	}

	return false;