]> git.ipfire.org Git - thirdparty/linux.git/commit
lib/find_bit: fix uninitialized variable use in FIND_NTH_BIT
authorLee Yongjun <jun85566@gmail.com>
Tue, 20 Jan 2026 13:18:27 +0000 (22:18 +0900)
committerYury Norov <ynorov@nvidia.com>
Sun, 8 Feb 2026 23:47:29 +0000 (18:47 -0500)
commit92010ab6dbacc0e0f3566d92a84ff00a939e7fd4
tree4704172bba8b4fcd01f7792ccc2d2c493ada8e0a
parent4101b3b571701cdf1081b2f96124b1daaeaebbf1
lib/find_bit: fix uninitialized variable use in FIND_NTH_BIT

In the FIND_NTH_BIT macro, if the 'size' parameter is 0, both the
loop conditions and the modulo condition are not met. Consequently,
the 'tmp' variable remains uninitialized before being used in the
'found' label.

This results in the following smatch errors:

  lib/find_bit.c:164 __find_nth_bit() error: uninitialized symbol 'tmp'.
  lib/find_bit.c:171 __find_nth_and_bit() error: uninitialized symbol 'tmp'.
  lib/find_bit.c:178 __find_nth_andnot_bit() error: uninitialized symbol 'tmp'.
  lib/find_bit.c:187 __find_nth_and_andnot_bit() error: uninitialized symbol 'tmp'.

Initialize 'tmp' to 0 to ensure that fns() operates on a zeroed value
(no bits set) when size is 0, preventing the use of garbage values.

[Yury: size == 0 is generally a sign of error on client side, and in
this case, any returned value is OK because the returned value would be
greater than 'size'. Applying the patch to reduce the checker noise.]

Signed-off-by: Lee Yongjun <jun85566@gmail.com>
Signed-off-by: Yury Norov <ynorov@nvidia.com>
lib/find_bit.c