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: <CAHp75VdtUhUBL5d103RunY5EvgmTQVH48S21N1-1KmDM0q44Aw@mail.gmail.com>
Date: Mon, 7 Apr 2025 19:16:39 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Abraham Samuel Adekunle <abrahamadekunle50@...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 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.

...

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.

-- 
With Best Regards,
Andy Shevchenko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ