Re: [PATCH] staging: rtl8723bs: Replace `& 0xfff` with `% 4096u`
Andy Shevchenko <[email protected]> Thu, 10 Apr 2025 20:43:53 +0300
| Newsgroups | dev.linux.lists.outreachy,dev.linux.lists.linux-staging,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAHp75Vd0PUFv_tigmKp7MEiOOuHpFhB_i8u42jZdQ1jajjq0rw@mail.gmail.com> |
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. > $ 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. --=20 With Best Regards, Andy Shevchenko