Skip to contentSkip to conversation

staging: rtl8723bs: Improve readability and clarity of sequence number wrapping

PATCH Superseded Abraham Samuel Adekunle 3 participants 14 messages Apr 7, 2025 – Apr 8, 2025 Staging

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v6 cover staging: rtl8723bs: Improve readability and clarity of sequence number wrapping

Tha patchset adds spaces around binary operators and also provides clarity on sequence number wrapping by using a modulo operation % 4096u, in place of the bitwise AND(&) operation & 0xfff. The patches are required to be applied in sequence.

Changes in v5:
- Converted the patch with the subject "Use % 4096 instead of & 0xfff" patch to a patchset.
- Added a patch to add spaces around binary operator.
Changes in v4:
- Corrected patch to use '%' instead of '&'.
- To ensure this change does not affect the functional behaviour, I compared the generated object files before and after the change using the cmp which compares the two object files byte by byte as shown below:

$ make drivers/staging/rtl8723bs/core/rtw_xmit.o $ cmp rtw_xmit_before.o rtw_xmit_after.o

No differences were found in the output, confirming that the change does not alter the compiled output.
Changes in v3:
- Added more description to the commit message.
- Removed blank line in the tag block.
- Added more patch recipients.
Changes in v2:
- Changed the commit message t a more descriptive message which makes it clear why the patch does the change.
- changed the subject title to include 4096u to show that an unsigned module is used.
Changes in v1:
- Added more patch recipients.

Abraham Samuel Adekunle (2):
staging: rtl8723bs: Add white spaces around binary operators
staging: rtl8723bs: Use % 4096u instead of & 0xfff

 drivers/staging/rtl8723bs/core/rtw_xmit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v6 1/2 staging: rtl8723bs: Add white spaces around binary operators

The code contains no spaces around binary operators making it hard to read. This also doesn't adhere to Linux kernel coding style.

Add white spaces around the binary operators to increase readability and endure adherence to Linux kernel coding styles.

---
 drivers/staging/rtl8723bs/core/rtw_xmit.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -2
index 297c93d65315..c41de6fd897b 100644
@@ -963,11 +963,11 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
 					if (SN_LESS(pattrib->seqnum, tx_seq)) {
 						pattrib->ampdu_en = false;/* AGG BK */
 					} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
-						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
 						pattrib->ampdu_en = true;/* AGG EN */
 					} else {
-						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;
 						pattrib->ampdu_en = true;/* AGG EN */
 					}
 				}
Signature · 1 line
2.34.1
#9 lore raw

PATCH v6 2/2 staging: rtl8723bs: Use % 4096u instead of & 0xfff

In reply to Abraham Samuel Adekunle

The sequence number is constrained to a range of [0, 4095], which is a total of 4096 values. The bitmask operation using & 0xfff is used to perform this wrap-around. While this is functionally correct, it obscures the intended semantic of a 4096-based wrap.

Using a modulo operation % 4096u makes the wrap-around logic explicit and easier to understand. It clearly signals that the sequence number cycles through a range of 4096 values.
It also makes the code robust against potential changes of the 4096 upper limit, especially when it becomes a non power of 2 value while the AND(&) works solely for power of 2 values.

The use of % 4096u also guarantees that the modulo operation is performed with unsigned arithmetic, preventing potential issues with the signed types.

---
 drivers/staging/rtl8723bs/core/rtw_xmit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/rtl8723bs/core/rtw_xmit.c +3 -3
index c41de6fd897b..5cfb6d1e9dae 100644
@@ -943,7 +943,7 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
 
 			if (psta) {
 				psta->sta_xmitpriv.txseq_tid[pattrib->priority]++;
-				psta->sta_xmitpriv.txseq_tid[pattrib->priority] &= 0xFFF;
+				psta->sta_xmitpriv.txseq_tid[pattrib->priority] %= 4096u;
 				pattrib->seqnum = psta->sta_xmitpriv.txseq_tid[pattrib->priority];
 
 				SetSeqNum(hdr, pattrib->seqnum);
@@ -963,11 +963,11 @@ s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr
 					if (SN_LESS(pattrib->seqnum, tx_seq)) {
 						pattrib->ampdu_en = false;/* AGG BK */
 					} else if (SN_EQUAL(pattrib->seqnum, tx_seq)) {
-						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
+						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) % 4096u;
 
 						pattrib->ampdu_en = true;/* AGG EN */
 					} else {
-						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;
+						psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) % 4096u;
 						pattrib->ampdu_en = true;/* AGG EN */
 					}
 				}
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

In reply to Abraham Samuel Adekunle
Quoted 7 lines · Abraham Samuel Adekunle

The code contains no spaces around binary operators making it hard to read. This also doesn't adhere to Linux kernel coding style.

Add white spaces around the binary operators to increase readability and endure adherence to Linux kernel coding styles.

...

drivers/staging/rtl8723bs/core/rtw_xmit.c s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr · line 970

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -2
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw
In reply to Abraham Samuel Adekunle
Quoted 5 lines · Abraham Samuel Adekunle

Tha patchset adds spaces around binary operators and also provides clarity on sequence number wrapping by using a modulo operation % 4096u, in place of the bitwise AND(&) operation & 0xfff. The patches are required to be applied in sequence.

...

Quoted 1 line

Changes in v5:

This is v6. Are there any changes in comparison to v5?

Quoted 3 lines

- Converted the patch with the subject "Use % 4096 instead of & 0xfff" patch to a patchset.
- Added a patch to add spaces around binary operator.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

In reply to Andy Shevchenko
Quoted 16 lines · Andy Shevchenko
Quoted 7 lines · Abraham Samuel Adekunle

The code contains no spaces around binary operators making it hard to read. This also doesn't adhere to Linux kernel coding style.

Add white spaces around the binary operators to increase readability and endure adherence to Linux kernel coding styles.

...

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +1 -1
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
Quoted 7 lines

drivers/staging/rtl8723bs/core/rtw_xmit.c s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr · line 970

Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +1 -1
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Okay, sorry
I will add a third patch for a line break before the patch for % operations since each patch should handle a single thing.

Thanks.

#11 lore raw
In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Abraham Samuel Adekunle

Tha patchset adds spaces around binary operators and also provides clarity on sequence number wrapping by using a modulo operation % 4096u, in place of the bitwise AND(&) operation & 0xfff. The patches are required to be applied in sequence.

Quoted 5 lines

...

Quoted 1 line

Changes in v5:

This is v6. Are there any changes in comparison to v5?

I added a cover letter and named it v6 to show it's a continuation from v5 and to show I added a
new patch for spaces.
I was not sure where would be best to add the change log so I put it in the cover letter.
But as it concerns the patch for the % operation, there is no change between v5 and v6

Thanks

Adekunle.

#4 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

In reply to Samuel Abraham
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -2
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;
Quoted 8 lines
Quoted 4 lines

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Okay, sorry
I will add a third patch for a line break before the patch for % operations since each patch should handle a single thing.

I am not sure you need a third patch for that. It lies into category of space and indentation fix.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw
In reply to Samuel Abraham
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 11 lines
Quoted 3 lines
Quoted 1 line

Changes in v5:

This is v6. Are there any changes in comparison to v5?

I added a cover letter and named it v6 to show it's a continuation from v5 and to show I added a
new patch for spaces.
I was not sure where would be best to add the change log so I put it in the cover letter.
But as it concerns the patch for the % operation, there is no change between v5 and v6

Then it should have

Changes in v6:
- none

which then questions the purpose of v6 :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

In reply to Andy Shevchenko
Quoted 19 lines · Andy Shevchenko
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 11 lines
Quoted 10 lines

drivers/staging/rtl8723bs/core/rtw_xmit.c s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr · line 970

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -2
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Quoted 7 lines
Quoted 3 lines

Okay, sorry
I will add a third patch for a line break before the patch for % operations since each patch should handle a single thing.

I am not sure you need a third patch for that. It lies into category of space and indentation fix.

Yeah. Let's not go crazy. Do the white space change as one patch. The rules are there to make reviewing easier. Splitting it up into three patches doesn't help anyone.

In staging we say, "Fix one type of checkpatch warning at a time." That's because it's a simple rule to explain and it stops people from sending us huge patches that fix every checkpatch warning. But this patch is small and everything is related and it's easy to review.

regards,
dan carpenter

#13 lore raw
In reply to Andy Shevchenko
Quoted 21 lines · Andy Shevchenko
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 11 lines
Quoted 3 lines
Quoted 1 line

Changes in v5:

This is v6. Are there any changes in comparison to v5?

I added a cover letter and named it v6 to show it's a continuation from v5 and to show I added a
new patch for spaces.
I was not sure where would be best to add the change log so I put it in the cover letter.
But as it concerns the patch for the % operation, there is no change between v5 and v6

Quoted 7 lines

Then it should have

Changes in v6:
- none

which then questions the purpose of v6 :-)

Okay, what should I version the next patchset I will be sending as, and also how about the change log. Do I write it in the individual patches rather than the cover letter?

I am a bit confused with that please kindly clarify. Thanks
Adekunle

#6 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

In reply to Dan Carpenter
Quoted 25 lines · Dan Carpenter
Quoted 23 lines · Andy Shevchenko
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 14 lines
Quoted 10 lines

drivers/staging/rtl8723bs/core/rtw_xmit.c s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr · line 970

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -2
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Okay, sorry
I will add a third patch for a line break before the patch for % operations since each patch should handle a single thing.

Quoted 7 lines
Quoted 3 lines

I am not sure you need a third patch for that. It lies into category of space and indentation fix.

Yeah. Let's not go crazy. Do the white space change as one patch. The rules are there to make reviewing easier. Splitting it up into three patches doesn't help anyone.

Okay thank you Dan. I have collapsed the spaces and linebreaks into one patch

Quoted 6 lines

In staging we say, "Fix one type of checkpatch warning at a time." That's because it's a simple rule to explain and it stops people from sending us huge patches that fix every checkpatch warning. But this patch is small and everything is related and it's easy to review.

Thank you very much for the clarity. I understand now.

I already asked Andy, but I would also like to seek your opinion on how I should version
the next patch. I already made this current one v6. Do I send v7 with changes in the cover letter,
or changes in the individual patches?
Or what is the best way please

Thanks

Adekunle.

#7 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

Quoted 42 lines · Samuel Abraham
Quoted 25 lines · Dan Carpenter
Quoted 23 lines · Andy Shevchenko
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 14 lines
Quoted 10 lines

drivers/staging/rtl8723bs/core/rtw_xmit.c s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattr · line 970

Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_xmit.c +2 -2
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Okay, sorry
I will add a third patch for a line break before the patch for % operations since each patch should handle a single thing.

Quoted 7 lines
Quoted 3 lines

I am not sure you need a third patch for that. It lies into category of space and indentation fix.

Yeah. Let's not go crazy. Do the white space change as one patch. The rules are there to make reviewing easier. Splitting it up into three patches doesn't help anyone.

Okay thank you Dan. I have collapsed the spaces and linebreaks into one patch

Quoted 6 lines

In staging we say, "Fix one type of checkpatch warning at a time." That's because it's a simple rule to explain and it stops people from sending us huge patches that fix every checkpatch warning. But this patch is small and everything is related and it's easy to review.

Quoted 6 lines

Thank you very much for the clarity. I understand now.

I already asked Andy, but I would also like to seek your opinion on how I should version
the next patch. I already made this current one v6. Do I send v7 with changes in the cover letter,

Yes.

Quoted 1 line

or changes in the individual patches?

Both? Put yourself in Greg's shoes and do whatever is easiest for Greg.

regards,
dan carpenter

#8 lore raw

Re: [PATCH v6 1/2] staging: rtl8723bs: Add white spaces around binary operators

Quoted 51 lines · Dan Carpenter
Quoted 42 lines · Samuel Abraham
Quoted 25 lines · Dan Carpenter
Quoted 23 lines · Andy Shevchenko
Quoted 4 lines · Samuel Abraham
Quoted 2 lines · Andy Shevchenko

On Tue, Apr 8, 2025 at 12:54 AM Abraham Samuel Adekunle <[email protected]> wrote:

...

Quoted 14 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +2 -2
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq + 1) & 0xfff;
 
-                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff;
+                                               psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum + 1) & 0xfff;

You mentioned Linux coding style, which also requires lines not to be so long. These lines are. That's why a few versions ago I suggested you to change these to be two lines each. I don't know how many times to repeat this (it's third one).

Okay, sorry
I will add a third patch for a line break before the patch for % operations since each patch should handle a single thing.

Quoted 7 lines
Quoted 3 lines

I am not sure you need a third patch for that. It lies into category of space and indentation fix.

Yeah. Let's not go crazy. Do the white space change as one patch. The rules are there to make reviewing easier. Splitting it up into three patches doesn't help anyone.

Okay thank you Dan. I have collapsed the spaces and linebreaks into one patch

Quoted 6 lines

In staging we say, "Fix one type of checkpatch warning at a time." That's because it's a simple rule to explain and it stops people from sending us huge patches that fix every checkpatch warning. But this patch is small and everything is related and it's easy to review.

Quoted 6 lines

Thank you very much for the clarity. I understand now.

I already asked Andy, but I would also like to seek your opinion on how I should version
the next patch. I already made this current one v6. Do I send v7 with changes in the cover letter,

Quoted 6 lines

Yes.

Quoted 1 line

or changes in the individual patches?

Both? Put yourself in Greg's shoes and do whatever is easiest for Greg.

Thank you very much, Dan.

Adekunle.