From: Greg KH <gregkh@linuxfoundation.org>
To: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>
Cc: outreachy@lists.linux.dev, julia.lawall@inria.fr,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
david.laight.linux@gmail.com, dan.carpenter@linaro.org,
andy@kernel.org
Subject: Re: [PATCH] staging: rtl8723bs: Replace `& 0xfff` with `% 4096u`
Date: Mon, 14 Apr 2025 09:21:28 +0200 [thread overview]
Message-ID: <2025041402-colonize-rocker-1db1@gregkh> (raw)
In-Reply-To: <Z/bA4tMF5uKLe55p@ubuntu>
On Wed, Apr 09, 2025 at 06:48:02PM +0000, Abraham Samuel Adekunle 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.
>
> Suggested by Andy Shevchenko <andy@kernel.org>
> Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>
> ---
> Coccinelle semantic patch used to find cases:
> @@
> expression e;
>
> @@
> * e & 0xfff
>
> To ensure this change does not affect the functional
> behaviour, I compared the generated object files before and
> after the change using the `cmp` which compares the two
> object files byte by byte as shown below:
>
> $ make drivers/staging/rtl8723bs/core/rtw_xmit.o
> $ cmp rtw_xmit_before.o rtw_xmit_after.o
>
> No differences were found in the output, confirming that the
> change does not alter the compiled output.
This is version 11, right? What happened to the list of previous
versions and what changed down here?
confused,
greg k-h
next prev parent reply other threads:[~2025-04-14 7:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 18:48 [PATCH] staging: rtl8723bs: Replace `& 0xfff` with `% 4096u` Abraham Samuel Adekunle
2025-04-10 17:43 ` Andy Shevchenko
2025-04-11 7:43 ` Samuel Abraham
2025-04-11 10:37 ` Dan Carpenter
2025-04-11 12:47 ` Andy Shevchenko
2025-04-12 14:19 ` Dan Carpenter
2025-04-12 17:52 ` Andy Shevchenko
2025-04-14 7:21 ` Greg KH [this message]
2025-04-14 7:38 ` Samuel Abraham
2025-04-14 9:00 ` Greg KH
2025-04-14 9:17 ` Samuel Abraham
2025-04-17 16:33 ` Samuel Abraham
2025-04-17 16:56 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025041402-colonize-rocker-1db1@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=abrahamadekunle50@gmail.com \
--cc=andy@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=david.laight.linux@gmail.com \
--cc=julia.lawall@inria.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.