lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vd0PUFv_tigmKp7MEiOOuHpFhB_i8u42jZdQ1jajjq0rw@mail.gmail.com>
Date: Thu, 10 Apr 2025 20:43:53 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Abraham Samuel Adekunle <abrahamadekunle50@...il.com>
Cc: outreachy@...ts.linux.dev, julia.lawall@...ia.fr, 
	gregkh@...uxfoundation.org, linux-staging@...ts.linux.dev, 
	linux-kernel@...r.kernel.org, david.laight.linux@...il.com, 
	dan.carpenter@...aro.org, andy@...nel.org
Subject: Re: [PATCH] staging: rtl8723bs: Replace `& 0xfff` with `% 4096u`

On Wed, Apr 9, 2025 at 9:48 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.
>
> Found by Coccinelle.

This should be folded to the initial change since it's the same driver
and values most likely are related to each other.


> $ make drivers/staging/rtl8723bs/core/rtw_xmit.o
> $ cmp rtw_xmit_before.o rtw_xmit_after.o

cmp is good but not good enough in general. Here it shows the 1:1
binary, but in some cases code can be the same, while binaries are
different. To make sure the code is the same use the bloat-o-meter
tool instead.

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ