Re: [PATCH v5] staging: rtl8723bs: Use % 4096u instead of & 0xfff
Samuel Abraham <[email protected]> Wed, 9 Apr 2025 15:06:58 +0100
| Newsgroups | dev.linux.lists.outreachy,dev.linux.lists.linux-staging,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CADYq+fbbA+K6qsPSa73s94+Whe-_gZ0-ZquYjyx0S4RXFq1W-A@mail.gmail.com> |
On Mon, Apr 7, 2025 at 5:17=E2=80=AFPM Andy Shevchenko <[email protected]> wrote: > > On Mon, Apr 7, 2025 at 6:54=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. > > > ... > > 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. I have found more cases using a small Coccinelle semantic patch. There were also cases in the media driver, but I did not touch those since = it is not allowed for an outreachy applicant. I will send a patchset soon. Thanks Adekunle