public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lee Yongjun <jun85566@gmail.com>
To: yury.norov@gmail.com
Cc: linux@rasmusvillemoes.dk, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, Lee Yongjun <jun85566@gmail.com>
Subject: [PATCH] lib/find_bit: fix uninitialized variable use in FIND_NTH_BIT
Date: Tue, 20 Jan 2026 22:18:27 +0900	[thread overview]
Message-ID: <20260120131827.12183-1-jun85566@gmail.com> (raw)

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.

Signed-off-by: Lee Yongjun <jun85566@gmail.com>
---
 lib/find_bit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/find_bit.c b/lib/find_bit.c
index d4b5a29e3e72..5a0066c26d9a 100644
--- a/lib/find_bit.c
+++ b/lib/find_bit.c
@@ -71,7 +71,7 @@ out:										\
 
 #define FIND_NTH_BIT(FETCH, size, num)						\
 ({										\
-	unsigned long sz = (size), nr = (num), idx, w, tmp;			\
+	unsigned long sz = (size), nr = (num), idx, w, tmp = 0;			\
 										\
 	for (idx = 0; (idx + 1) * BITS_PER_LONG <= sz; idx++) {			\
 		if (idx * BITS_PER_LONG + nr >= sz)				\
-- 
2.34.1


                 reply	other threads:[~2026-01-20 13:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260120131827.12183-1-jun85566@gmail.com \
    --to=jun85566@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=yury.norov@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox