Skip to contentSkip to conversation

staging: rtl8723bs: refactor cckrates{only}_included

PATCH In review Michael Straube 2 participants 8 messages Sep 12, 2020 – Sep 13, 2020 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 staging: rtl8723bs: refactor cckrates{only}_included

Refactor cckrates_included() and cckratesonly_included() to simplify the code and improve readability.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +8 -6
index a5790a648a5b..4e0d86b2e2e0 100644
@@ -56,11 +56,12 @@ static u8 rtw_basic_rate_ofdm[3] = {
 
 int cckrates_included(unsigned char *rate, int ratelen)
 {
-	int	i;
+	int i;
 
 	for (i = 0; i < ratelen; i++) {
-		if  ((((rate[i]) & 0x7f) == 2)	|| (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+		u8 r = rate[i] & 0x7f;
+
+		if (r == 2 || r == 4 || r == 11 || r == 22)
 			return true;
 	}
 
@@ -69,11 +70,12 @@ int cckrates_included(unsigned char *rate, int ratelen)
 
 int cckratesonly_included(unsigned char *rate, int ratelen)
 {
-	int	i;
+	int i;
 
 	for (i = 0; i < ratelen; i++) {
-		if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
-		     (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
+		u8 r = rate[i] & 0x7f;
+
+		if (r != 2 && r != 4 && r != 11 && r != 22)
 			return false;
 	}
 
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/5 staging: rtl8723bs: make cckrates{only}_included static

Functions cckrates_included() and cckratesonly_included() are used only in the file core/rtw_wlan_util.c. Make them static and remove extern declarations from include/rtw_mlme_ext.c.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c   | 4 ++--
 drivers/staging/rtl8723bs/include/rtw_mlme_ext.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -2
index 4e0d86b2e2e0..22e4305d70a2 100644
@@ -54,7 +54,7 @@ static u8 rtw_basic_rate_ofdm[3] = {
 	IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
 };
 
-int cckrates_included(unsigned char *rate, int ratelen)
+static int cckrates_included(unsigned char *rate, int ratelen)
 {
 	int i;
 
@@ -68,7 +68,7 @@ int cckrates_included(unsigned char *rate, int ratelen)
 	return false;
 }
 
-int cckratesonly_included(unsigned char *rate, int ratelen)
+static int cckratesonly_included(unsigned char *rate, int ratelen)
 {
 	int i;
 
drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +0 -2
index 14583799039f..1567831caf91 100644
@@ -716,8 +716,6 @@ void sa_query_timer_hdl(struct timer_list *t);
 		DBG_871X("%s set_sa_query_timer(%p, %d)\n", __func__, (mlmeext), (ms)); \
 		_set_timer(&(mlmeext)->sa_query_timer, (ms)); \
 	} while (0)
-extern int cckrates_included(unsigned char *rate, int ratelen);
-extern int cckratesonly_included(unsigned char *rate, int ratelen);
 
 extern void process_addba_req(struct adapter *padapter, u8 *paddba_req, u8 *addr);
 
Signature · 1 line
2.28.0
#3 lore raw

PATCH 4/5 staging: rtl8723bs: remove comparsions to true

In reply to Michael Straube

Remove unnecessary comparsions to boolean values.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -2
index 7733d076af85..cad35ce0c21a 100644
@@ -1767,9 +1767,9 @@ void update_wireless_mode(struct adapter *padapter)
 		else if (pmlmeinfo->HT_enable)
 			network_type = WIRELESS_11_24N;
 
-		if ((cckratesonly_included(rate, ratelen)) == true)
+		if (cckratesonly_included(rate, ratelen))
 			network_type |= WIRELESS_11B;
-		else if ((cckrates_included(rate, ratelen)) == true)
+		else if (cckrates_included(rate, ratelen))
 			network_type |= WIRELESS_11BG;
 		else
 			network_type |= WIRELESS_11G;
Signature · 1 line
2.28.0
#4 lore raw

PATCH 5/5 staging: rtl8723bs: remove 5 GHz code

In reply to Michael Straube

Acoording to the TODO code valid only for 5 GHz should be removed.

- find and remove remaining code valid only for 5 GHz. Most of the obvious ones have been removed, but things like channel > 14 still exist.

Remove code path only valid for channels > 14.

---
 .../staging/rtl8723bs/core/rtw_wlan_util.c    | 31 +++++++------------
 1 file changed, 11 insertions(+), 20 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +11 -20
index cad35ce0c21a..fdb5a6b51c03 100644
@@ -1754,26 +1754,17 @@ void update_wireless_mode(struct adapter *padapter)
 	if ((pmlmeinfo->HT_info_enable) && (pmlmeinfo->HT_caps_enable))
 		pmlmeinfo->HT_enable = 1;
 
-	if (pmlmeext->cur_channel > 14) {
-		if (pmlmeinfo->VHT_enable)
-			network_type = WIRELESS_11AC;
-		else if (pmlmeinfo->HT_enable)
-			network_type = WIRELESS_11_5N;
-
-		network_type |= WIRELESS_11A;
-	} else {
-		if (pmlmeinfo->VHT_enable)
-			network_type = WIRELESS_11AC;
-		else if (pmlmeinfo->HT_enable)
-			network_type = WIRELESS_11_24N;
-
-		if (cckratesonly_included(rate, ratelen))
-			network_type |= WIRELESS_11B;
-		else if (cckrates_included(rate, ratelen))
-			network_type |= WIRELESS_11BG;
-		else
-			network_type |= WIRELESS_11G;
-	}
+	if (pmlmeinfo->VHT_enable)
+		network_type = WIRELESS_11AC;
+	else if (pmlmeinfo->HT_enable)
+		network_type = WIRELESS_11_24N;
+
+	if (cckratesonly_included(rate, ratelen))
+		network_type |= WIRELESS_11B;
+	else if (cckrates_included(rate, ratelen))
+		network_type |= WIRELESS_11BG;
+	else
+		network_type |= WIRELESS_11G;
 
 	pmlmeext->cur_wireless_mode = network_type & padapter->registrypriv.wireless_mode;
 
Signature · 1 line
2.28.0
#2 lore raw

PATCH 3/5 staging: rtl8723bs: convert cckrates{only}_included to bool

In reply to Michael Straube

Functions cckrates_included() and cckratesonly_included() return boolean values. Convert the return type from int to bool.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +2 -2
index 22e4305d70a2..7733d076af85 100644
@@ -54,7 +54,7 @@ static u8 rtw_basic_rate_ofdm[3] = {
 	IEEE80211_OFDM_RATE_24MB | IEEE80211_BASIC_RATE_MASK
 };
 
-static int cckrates_included(unsigned char *rate, int ratelen)
+static bool cckrates_included(unsigned char *rate, int ratelen)
 {
 	int i;
 
@@ -68,7 +68,7 @@ static int cckrates_included(unsigned char *rate, int ratelen)
 	return false;
 }
 
-static int cckratesonly_included(unsigned char *rate, int ratelen)
+static bool cckratesonly_included(unsigned char *rate, int ratelen)
 {
 	int i;
 
Signature · 1 line
2.28.0
#5 lore raw
In reply to Michael Straube
Quoted 32 lines · Michael Straube

Refactor cckrates_included() and cckratesonly_included() to simplify the code and improve readability.

---
 drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +4 -3
index a5790a648a5b..4e0d86b2e2e0 100644
@@ -56,11 +56,12 @@ static u8 rtw_basic_rate_ofdm[3] = {
 
 int cckrates_included(unsigned char *rate, int ratelen)
 {
-	int	i;
+	int i;
 
 	for (i = 0; i < ratelen; i++) {
-		if  ((((rate[i]) & 0x7f) == 2)	|| (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+		u8 r = rate[i] & 0x7f;
+
+		if (r == 2 || r == 4 || r == 11 || r == 22)
 			return true;
 	}
 
@@ -69,11 +70,12 @@ int cckrates_included(unsigned char *rate, int ratelen)
 
 int cckratesonly_included(unsigned char *rate, int ratelen)
 {

drivers/staging/rtl8723bs/core/rtw_wlan_util.c int cckrates_included(unsigned char *rate, int ratelen) · line 79

Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +4 -3
-	int	i;
+	int i;
 
 	for (i = 0; i < ratelen; i++) {
-		if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
-		     (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
+		u8 r = rate[i] & 0x7f;
+
+		if (r != 2 && r != 4 && r != 11 && r != 22)
 			return false;

It would be simpler to add and use an inline like:

static bool is_cckrate(unsigned char rate)

{
	rate &= 0x7f;
	return rate == 2 || rate == 4 || rate == 11 || rate == 22;
}

so these could be

bool cckrates_included(unsigned char *rate, int ratelen)

{
	int i;

	for (i = 0; i < ratelen; i++) {
		if (is_cckrate(rate[i])
			return true;
	}

	return false;
}

bool cckratesonly_included(unsigned char *rate, int ratelen)

{
	int i;

	if (i <= 0)
		return false;

	for (i = 0; i < ratelen; i++) {
		if (!is_cckrate(rate[i])
			return false;
	}

	return true;
}
#6 lore raw
Quoted 3 lines · Joe Perches
Quoted 2 lines · Michael Straube

Refactor cckrates_included() and cckratesonly_included() to simplify the code and improve readability.

[]

drivers/staging/rtl8723bs/core/rtw_wlan_util.c

Quoted 1 line
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +0 -0

[]

Quoted 2 lines

bool cckratesonly_included(unsigned char *rate, int ratelen) {

[]

Quoted 1 line
	if (i <= 0)
	if (ratelen <= 0)  of course...
Quoted 11 lines
		return false;

	for (i = 0; i < ratelen; i++) {
		if (!is_cckrate(rate[i])
			return false;
	}

	return true;
}
#7 lore raw
In reply to Joe Perches
Quoted 67 lines · Joe Perches
Quoted 32 lines · Michael Straube

Refactor cckrates_included() and cckratesonly_included() to simplify the code and improve readability.

---
  drivers/staging/rtl8723bs/core/rtw_wlan_util.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +4 -3
index a5790a648a5b..4e0d86b2e2e0 100644
@@ -56,11 +56,12 @@ static u8 rtw_basic_rate_ofdm[3] = {
 
  int cckrates_included(unsigned char *rate, int ratelen)
  {
-	int	i;
+	int i;
 
  	for (i = 0; i < ratelen; i++) {
-		if  ((((rate[i]) & 0x7f) == 2)	|| (((rate[i]) & 0x7f) == 4) ||
-		     (((rate[i]) & 0x7f) == 11)  || (((rate[i]) & 0x7f) == 22))
+		u8 r = rate[i] & 0x7f;
+
+		if (r == 2 || r == 4 || r == 11 || r == 22)
  			return true;
  	}
 
@@ -69,11 +70,12 @@ int cckrates_included(unsigned char *rate, int ratelen)
 
  int cckratesonly_included(unsigned char *rate, int ratelen)
  {

drivers/staging/rtl8723bs/core/rtw_wlan_util.c int cckrates_included(unsigned char *rate, int ratelen) · line 79

Quoted 10 lines
drivers/staging/rtl8723bs/core/rtw_wlan_util.c +4 -3
-	int	i;
+	int i;
 
  	for (i = 0; i < ratelen; i++) {
-		if  ((((rate[i]) & 0x7f) != 2) && (((rate[i]) & 0x7f) != 4) &&
-		     (((rate[i]) & 0x7f) != 11)  && (((rate[i]) & 0x7f) != 22))
+		u8 r = rate[i] & 0x7f;
+
+		if (r != 2 && r != 4 && r != 11 && r != 22)
  			return false;

It would be simpler to add and use an inline like:

static bool is_cckrate(unsigned char rate)

{
	rate &= 0x7f;
	return rate == 2 || rate == 4 || rate == 11 || rate == 22;
}

so these could be

bool cckrates_included(unsigned char *rate, int ratelen)

{
	int i;

	for (i = 0; i < ratelen; i++) {
		if (is_cckrate(rate[i])
			return true;
	}

	return false;
}

bool cckratesonly_included(unsigned char *rate, int ratelen)

Quoted 15 lines
{
	int i;

	if (i <= 0)
		return false;

	for (i = 0; i < ratelen; i++) {
		if (!is_cckrate(rate[i])
			return false;
	}

	return true;
}

I've just seen that there are already rtw_is_cckrates_included and rtw_is_cckratesonly_included in rtw_ieee80211.c that can be used here.

I will send another series removing the functions from rtw_wlan_util.c and use the ones from rtw_ieee80211.c.

So please don't merge this series, thanks.

Michael