[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CADYq+fY5fbENFa9b53HKNPrCHTfR6YPDektUoTi8=9h5ZbxbuA@mail.gmail.com>
Date: Mon, 7 Apr 2025 21:58:05 +0100
From: Samuel Abraham <abrahamadekunle50@...il.com>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: gregkh@...uxfoundation.org, julia.lawall@...ia.fr,
outreachy@...ts.linux.dev, linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org, david.laight.linux@...il.com, andy@...nel.org,
dan.carpenter@...aro.org
Subject: Re: [PATCH v5] staging: rtl8723bs: Use % 4096u instead of & 0xfff
On Mon, Apr 7, 2025 at 5:17 PM Andy Shevchenko
<andy.shevchenko@...il.com> wrote:
>
> On Mon, Apr 7, 2025 at 6:54 PM Abraham Samuel Adekunle
> <abrahamadekunle50@...il.com> 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.
Okay, I will send a patchset for the change. The first one will add
the spaces, then the
second one will add the logic, and they can be applied in sequence.
>
> ...
>
> 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.
No, I have not checked other drivers. I will write a semantic patch to
match and transform such cases
Thanks
Adekunle.
Powered by blists - more mailing lists