]> www.infradead.org Git - users/jedix/linux-maple.git/commit
staging: rtl8723bs: Use % 4096 instead of & 0xfff
authorAbraham Samuel Adekunle <abrahamadekunle50@gmail.com>
Fri, 18 Apr 2025 09:47:55 +0000 (09:47 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 18 Apr 2025 10:40:15 +0000 (12:40 +0200)
commita5df13cd7b05f87f864c2d575020d287879659aa
tree07328feb6d0d0df8380bc2971ba2ac9d70472ee3
parent28925280ed6c12705a9273cc9853c97b22ef2176
staging: rtl8723bs: Use % 4096 instead of & 0xfff

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>
Suggested-by: David Laight <david.laight.linux@gmail.com>
Signed-off-by: Abraham Samuel Adekunle <abrahamadekunle50@gmail.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Link: https://lore.kernel.org/r/e8d515539ba560961003eae15d301d03e6cdd17d.1744966511.git.abrahamadekunle50@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c
drivers/staging/rtl8723bs/core/rtw_recv.c
drivers/staging/rtl8723bs/core/rtw_xmit.c