Skip to contentSkip to conversation

staging: rtl8723bs: Code cleanup patches

PATCH In review Erick Karanja 4 participants 12 messages Apr 2, 2025 – Apr 4, 2025 Staging

lore
Share & tools
lore
#0 lore raw

v2 cover staging: rtl8723bs: Code cleanup patches

This patchset refactors the rtl8723bs driver by replacing integer literals (1 and 0) with true and false in instances where values are already defined with true or false but some defination contains (1 or 0)

Changes in v2:
- [PATCH 1/3]: Rename the subject line and improve on the subject body
- [PATCH 2/3]: Rename the subject line and improve on the subject body
- [PATCH 3/3]: Rename the subject line and improve in the subject body
improving code readability and consistency with standard kernel practices. The transformation was performed using Coccinelle.

below is the coccinelle script used:
@initialize:ocaml@
@@

let same_function p q =
(List.hd p).Coccilib.current_element = (List.hd q).Coccilib.current_element

@r@
expression e;
position p;
symbol true,false;
@@

e =@p \(true\|false\)

@@
expression r.e;
position q : script:ocaml(r.p) { same_function p q }; @@

e =@q
(
- 1
+ true
|
- 0
+ false
)

@s@
type T;
T e;
identifier fld;
symbol true,false;
@@

e.fld = \(true\|false\)

@@
type s.T;
T e;
identifier s.fld;
@@

e.fld =
(
- 1
+ true
|
- 0
+ false
)

Erick Karanja (3):
staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted
staging: rtl8723bs: Modify struct sta_info attribute qos_option
staging: rtl8723bs: Modify struct sta_info attribute qos_option and

    ieee8021x_blocked
 drivers/staging/rtl8723bs/core/rtw_ap.c       | 12 ++++++------
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c |  4 ++--
 drivers/staging/rtl8723bs/core/rtw_recv.c     |  2 +-
 3 files changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/3 staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame
 			u8 *mgmt_DATA;
 			u32 data_len = 0;
 
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;
 			pattrib->encrypt = _AES_;
 			pattrib->hdrlen = sizeof(struct ieee80211_hdr_3addr);
 			/* set iv and icv length */
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Quoted 15 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
@@ -1358,7 +1358,7 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame
 			u8 *mgmt_DATA;
 			u32 data_len = 0;
 
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type. So setting it to "false" does not seem correct here, right?

Also, the name of the variable should really be changed.

But, step back, are you _SURE_ you can change this structure at all? At a quick glance it kind of looks like it comes directly from the hardware, or am I mis-reading the driver code?

Have you tested this series on an actual device?

thanks,

greg k-h

#3 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Quoted 19 lines · Greg KH
Quoted 18 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame
 			u8 *mgmt_DATA;
 			u32 data_len = 0;
 
Quoted 5 lines

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type. So setting it to "false" does not seem correct here, right?

Is false different than 0?

Elsewhere there is an assignment to true.

julia

Quoted 14 lines

Also, the name of the variable should really be changed.

But, step back, are you _SURE_ you can change this structure at all? At a quick glance it kind of looks like it comes directly from the hardware, or am I mis-reading the driver code?

Have you tested this series on an actual device?

thanks,

greg k-h

maintainer
#4 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Quoted 23 lines · Julia Lawall
Quoted 19 lines · Greg KH
Quoted 18 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame
 			u8 *mgmt_DATA;
 			u32 data_len = 0;
 
Quoted 7 lines
Quoted 5 lines

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type. So setting it to "false" does not seem correct here, right?

Is false different than 0?

Does C guarantee that? I can never remember. I don't think it guarantees that a 'bool' will only be 8 bits, or am I mistaken there too?

Quoted 1 line

Elsewhere there is an assignment to true.

Was that in the original driver?

If this doesn't come from the hardware, then it's fine to make the change. If it does, it needs to be verified that the layout and bit values are identical.

thanks,

greg k-h

#5 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Quoted 32 lines · Greg KH
Quoted 23 lines · Julia Lawall
Quoted 19 lines · Greg KH
Quoted 18 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame
 			u8 *mgmt_DATA;
 			u32 data_len = 0;
 
Quoted 7 lines
Quoted 5 lines

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type. So setting it to "false" does not seem correct here, right?

Is false different than 0?

Quoted 7 lines

Does C guarantee that? I can never remember. I don't think it guarantees that a 'bool' will only be 8 bits, or am I mistaken there too?

Quoted 1 line

Elsewhere there is an assignment to true.

Was that in the original driver?

Yes:

git blame -L 436,436 drivers/staging/rtl8723bs/core/rtw_recv.c

554c0a3abf216 (Hans de Goede 2017-03-29 19:47:51 +0200 436) prxattrib->bdecrypted = true;

Quoted 3 lines

If this doesn't come from the hardware, then it's fine to make the change. If it does, it needs to be verified that the layout and bit values are identical.

Erick, you can see if the generated assembly code is the same before and after the same. You can see that with
make drivers/staging/rtl8723bs/core/rtw_recv.s

julia

#6 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

In reply to Greg KH
Quoted 30 lines · Greg KH
Quoted 29 lines · Julia Lawall
Quoted 24 lines · Greg KH
Quoted 15 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
@@ -1358,7 +1358,7 @@ static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame
 			u8 *mgmt_DATA;
 			u32 data_len = 0;
 
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type. So setting it to "false" does not seem correct here, right?

Quoted 6 lines
Quoted 1 line

Is false different than 0?

Does C guarantee that? I can never remember. I don't think it guarantees that a 'bool' will only be 8 bits, or am I mistaken there too?

These patches are fine. This does come from the hardware but the patches don't change the layout of the struct, just the right hand side of the assignment.

The C standard doesn't specify the size of _Bool. It just has to be unsigned and at least one bit large. The surprising thing about _Bool type is that it doesn't truncate anything. So you can do:
"_Bool x = y & BIT(20);" and it works, but if we use unsigned char then we would have to add a !!. "unsigned char x = !!(y & BIT(20));"

Btw, true/false are not keywords in C. They're defined in include/linux/stddef.h.

The main review here is if there is a typo where we accidentally type true instead of false.

regards,
dan carpenter

#7 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

In reply to Greg KH
Quoted 43 lines · Greg KH
Quoted 27 lines · Julia Lawall
Quoted 23 lines · Greg KH
Quoted 22 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied,
as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int

validate_80211w_mgmt(struct adapter *adapter, union recv_frame u8 *mgmt_DATA;
  u32 data_len = 0;

Quoted 8 lines
Quoted 6 lines

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type.  So setting it to "false"
does not seem correct here, right?

Is false different than 0?

Does C guarantee that?  I can never remember.  I don't think it guarantees that a 'bool' will only be 8 bits, or am I mistaken there too?

Quoted 1 line

Elsewhere there is an assignment to true.

Quoted 7 lines

Was that in the original driver?

If this doesn't come from the hardware, then it's fine to make the change.  If it does, it needs to be verified that the layout and bit values are identical.

thanks,

I have compared the generated assembly code before and after and I have observed the only change is the comment below.
-# drivers/staging/rtl8723bs/core/rtw_recv.c:1361:
pattrib->bdecrypted = 0;
+# drivers/staging/rtl8723bs/core/rtw_recv.c:1361:
pattrib->bdecrypted = false;
There is no change in the assembly instructions.

Quoted 2 lines

greg k-h

maintainer
#8 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Quoted 58 lines · Erick Karanja
Quoted 43 lines · Greg KH
Quoted 27 lines · Julia Lawall
Quoted 23 lines · Greg KH
Quoted 22 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is implied,
as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int

validate_80211w_mgmt(struct adapter *adapter, union recv_frame u8 *mgmt_DATA;
  u32 data_len = 0;

Quoted 8 lines
Quoted 6 lines

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type.  So setting it to "false"
does not seem correct here, right?

Is false different than 0?

Does C guarantee that?  I can never remember.  I don't think it guarantees that a 'bool' will only be 8 bits, or am I mistaken there too?

Quoted 1 line

Elsewhere there is an assignment to true.

Quoted 7 lines

Was that in the original driver?

If this doesn't come from the hardware, then it's fine to make the change.  If it does, it needs to be verified that the layout and bit values are identical.

thanks,

I have compared the generated assembly code
before and after and I have observed the only
change is the comment below.

(quoted diff) +1 -1
-# drivers/staging/rtl8723bs/core/rtw_recv.c:1361:
 			pattrib->bdecrypted = 0;
+# drivers/staging/rtl8723bs/core/rtw_recv.c:1361:
 			pattrib->bdecrypted = false;
Quoted 1 line

There is no change in the assembly instructions.

Showing the assembly is key, not just a comment :)

#9 lore raw

Re: [PATCH v2 1/3] staging: rtl8723bs: Modify struct rx_pkt_attrib attribute bdecrypted

Quoted 59 lines · Greg KH
Quoted 58 lines · Erick Karanja
Quoted 57 lines · Greg KH
Quoted 31 lines · Julia Lawall
Quoted 27 lines · Greg KH
Quoted 25 lines · Erick Karanja

Standardize boolean representation by ensuring consistency, replace instances of 1/0 with true/false where boolean logic is
implied,
as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool
type usage.

---
 drivers/staging/rtl8723bs/core/rtw_recv.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/rtl8723bs/core/rtw_recv.c +0 -0
index a389ba5ecc6f..fd04dbacb50f 100644
@@ -1358,7 +1358,7 @@ static signed int

validate_80211w_mgmt(struct adapter *adapter, union recv_frame
  u8 *mgmt_DATA;
  u32 data_len = 0;

Quoted 8 lines
Quoted 6 lines

drivers/staging/rtl8723bs/core/rtw_recv.c static signed int validate_80211w_mgmt(struct adapter *adapter, union recv_frame · line 1361

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_recv.c +1 -1
-			pattrib->bdecrypted = 0;
+			pattrib->bdecrypted = false;

but bdecrypted is a u8, not a boolean type.  So setting it to "false"
does not seem correct here, right?

Is false different than 0?

Does C guarantee that?  I can never remember.  I don't think it guarantees that a 'bool' will only be 8 bits, or am I mistaken there
too?

Quoted 1 line

Elsewhere there is an assignment to true.

Was that in the original driver?

If this doesn't come from the hardware, then it's fine to make the
change.  If it does, it needs to be verified that the layout and bit
values are identical.

thanks,

Quoted 10 lines
Quoted 8 lines

I have compared the generated assembly code before and after and I have observed the only change is the comment below.
-# drivers/staging/rtl8723bs/core/rtw_recv.c:1361:
  pattrib->bdecrypted = 0; +# drivers/staging/rtl8723bs/core/rtw_recv.c:1361:
  pattrib->bdecrypted = false; There is no change in the assembly instructions.

Showing the assembly is key, not just a comment :)

Thank you for the update. I will take this into consideration. Erick

#10 lore raw

PATCH v2 2/3 staging: rtl8723bs: Modify struct sta_info attribute qos_option

In reply to Erick Karanja

Standardize boolean representation by ensuring consistency, replacing instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false.
This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +2 -2
index 952ce6dd5af9..8f2c9c3e853c 100644
@@ -1173,7 +1173,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
 
 	/*  check if there is WMM IE & support WWM-PS */
 	pstat->flags &= ~WLAN_STA_WME;
-	pstat->qos_option = 0;
+	pstat->qos_option = false;
 	pstat->qos_info = 0;
 	pstat->has_legacy_ac = true;
 	pstat->uapsd_vo = 0;
@@ -1189,7 +1189,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame)
 
 					pstat->flags |= WLAN_STA_WME;
 
-					pstat->qos_option = 1;
+					pstat->qos_option = true;
 					pstat->qos_info = *(p+8);
 
 					pstat->max_sp_len = (pstat->qos_info>>5)&0x3;
Signature · 1 line
2.43.0
#11 lore raw

PATCH v2 3/3 staging: rtl8723bs: Modify struct sta_info attribute qos_option and ieee8021x_blocked

In reply to Erick Karanja

Standardize boolean representation by ensuring consistency, replacing instances of 1/0 with true/false where boolean logic is implied, as some definitions already use true/false. This improves code clarity and aligns with the kernel’s bool type usage.

---
 drivers/staging/rtl8723bs/core/rtw_ap.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/core/rtw_ap.c +6 -6
index d46a04b9a05e..199727f04516 100644
@@ -386,10 +386,10 @@ void update_bmc_sta(struct adapter *padapter)
 
 		pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
 
-		psta->qos_option = 0;
+		psta->qos_option = false;
 		psta->htpriv.ht_option = false;
 
-		psta->ieee8021x_blocked = 0;
+		psta->ieee8021x_blocked = false;
 
 		memset((void *)&psta->sta_stats, 0, sizeof(struct stainfo_stats));
 
@@ -1967,17 +1967,17 @@ void sta_info_update(struct adapter *padapter, struct sta_info *psta)
 
 	/* update wmm cap. */
 	if (WLAN_STA_WME & flags)
-		psta->qos_option = 1;
+		psta->qos_option = true;
 	else
-		psta->qos_option = 0;
+		psta->qos_option = false;
 
 	if (pmlmepriv->qospriv.qos_option == 0)
-		psta->qos_option = 0;
+		psta->qos_option = false;
 
 	/* update 802.11n ht cap. */
 	if (WLAN_STA_HT & flags) {
 		psta->htpriv.ht_option = true;
-		psta->qos_option = 1;
+		psta->qos_option = true;
 	} else {
 		psta->htpriv.ht_option = false;
 	}
Signature · 1 line
2.43.0