Re: [PATCH v5] staging: rtl8723bs: Use % 4096u instead of & 0xfff

From: Samuel Abraham
Date: Wed Apr 09 2025 - 10:07:17 EST


On Mon, Apr 7, 2025 at 5:17 PM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
>
> On Mon, Apr 7, 2025 at 6:54 PM Abraham Samuel Adekunle
> <abrahamadekunle50@xxxxxxxxx> 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