[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vfy0KMs1STmS4_5MqdCysKiZs_GaG1ahRNDr8ARhjRAUg@mail.gmail.com>
Date: Mon, 7 Apr 2025 07:42:05 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Abraham Samuel Adekunle <abrahamadekunle50@...il.com>
Cc: Julia Lawall <julia.lawall@...ia.fr>, Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
outreachy@...ts.linux.dev, andy@...nel.org, dan.carpenter@...aro.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] staging: rtl8723bs: Use % 4096u instead of & 0xfff
On Mon, Apr 7, 2025 at 3:27 AM 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 with `4096u` makes the wrap-around logic
> explicit and easier to understand. It clearly signals that the sequence
> number cycles though a range of 4096 values.
>
> The use of `4096u` also guarantees that the modulo operation is performed
> with unsigned arithmetic, preventing potential issues with signed types.
Also there are a couple of important things about modulo vs. AND:
The modulo use for wrapping around is making code robust against
potential changes of the upper range, especially when it becomes
non-power-of-2 value, the AND works solely for power-of-2 values. The
modulo in case of power-of-2 is optimised by the compiler to the same
or equivalent code.
> Suggested-by: Andy Shevchenko <andy@...nel.org>
> David Laight <david.laight.linux@...il.com>
Not sure what tag David's name is meant for.
>
This blank line shouldn't be here. It's a tag block where we don't put
blank lines.
> Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@...il.com>
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists