Re: [PATCH] staging: rtl8723bs: Replace `& 0xfff` with `% 4096u`
Samuel Abraham <[email protected]> Fri, 11 Apr 2025 08:43:26 +0100
| Newsgroups | dev.linux.lists.outreachy,dev.linux.lists.linux-staging,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CADYq+fbHCUigvrTuCLiF1TXN=VEBO42PvHQqvgfmTgJejLqS4Q@mail.gmail.com> |
On Thu, Apr 10, 2025 at 6:44=E2=80=AFPM Andy Shevchenko <[email protected]> wrote: > > On Wed, Apr 9, 2025 at 9:48=E2=80=AFPM 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. > > > > Found by Coccinelle. > > This should be folded to the initial change since it's the same driver > and values most likely are related to each other. Okay noted. > > > > $ make drivers/staging/rtl8723bs/core/rtw_xmit.o > > $ cmp rtw_xmit_before.o rtw_xmit_after.o > > cmp is good but not good enough in general. Here it shows the 1:1 > binary, but in some cases code can be the same, while binaries are > different. To make sure the code is the same use the bloat-o-meter > tool instead. Okay, thanks for the suggestion. I will check out the bloat-o-meter tool. Adekunle.