Re: [PATCH v5] staging: rtl8723bs: Use % 4096u instead of & 0xfff
Andy Shevchenko <[email protected]> Mon, 7 Apr 2025 19:16:39 +0300
| Newsgroups | dev.linux.lists.outreachy,dev.linux.lists.linux-staging,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAHp75VdtUhUBL5d103RunY5EvgmTQVH48S21N1-1KmDM0q44Aw@mail.gmail.com> |
On Mon, Apr 7, 2025 at 6:54 PM Abraham Samuel Adekunle <[email protected]> wrote: > > 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. ... > - psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)&0xfff; > + psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (tx_seq+1)%4096u; > - psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)&0xfff; > + psta->BA_starting_seqctrl[pattrib->priority & 0x0f] = (pattrib->seqnum+1)%4096u; To reduce churn, it would be nice to have another patch _before_ this one that makes above clearer (by adding spaces) as we already new in practice that it's hard to read: So, this will become two lines in each of the cases, and in this patch only one of those line will be touched. ... Besides that I haven't found in the changelog if you have looked at the entire driver code and checked that all usages of this field is done in the same / similar way and no need to convert anything more that these. -- With Best Regards, Andy Shevchenko