All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rong Tao <rtoax@foxmail.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	rongtao@cestc.cn, rtoax@foxmail.com, willy@infradead.org,
	wuchi.zero@gmail.com
Subject: [PATCH] lib/radix-tree: Fix uninitialized variable compilation warning
Date: Thu, 10 Nov 2022 13:00:42 +0800	[thread overview]
Message-ID: <tencent_B7D657EF5135C40D0303A1C3AC90CB0B9507@qq.com> (raw)
In-Reply-To: <20221109162348.3dbde3a7942c303af012276c@linux-foundation.org>

From: Rong Tao <rongtao@cestc.cn>

We need to set an initial value for offset to eliminate compilation
warning. And if the tree is empty, return NULL early.

How to reproduce warning:

$ make -C tools/testing/radix-tree
radix-tree.c: In function ‘radix_tree_tag_clear’:
radix-tree.c:1046:17: warning: ‘offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]
1046 |                 node_tag_clear(root, parent, tag, offset);
     |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 lib/radix-tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 3c78e1e8b2ad..eee453b856b6 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1029,10 +1029,10 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
 {
 	struct radix_tree_node *node, *parent;
 	unsigned long maxindex;
-	int offset;
+	int offset = 0;
 
 	radix_tree_load_root(root, &node, &maxindex);
-	if (index > maxindex)
+	if (index > maxindex || !node)
 		return NULL;
 
 	parent = NULL;
-- 
2.31.1


  reply	other threads:[~2022-11-10  5:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 14:34 [PATCH] radix tree test suite: Fix uninitialized variable compilation warning Rong Tao
2022-11-10  0:23 ` Andrew Morton
2022-11-10  5:00   ` Rong Tao [this message]
2022-11-10 16:06     ` [PATCH] lib/radix-tree: " Matthew Wilcox
2022-11-11  2:11       ` Rong Tao
2022-11-10 16:06   ` [PATCH] radix tree test suite: " Matthew Wilcox

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=tencent_B7D657EF5135C40D0303A1C3AC90CB0B9507@qq.com \
    --to=rtoax@foxmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rongtao@cestc.cn \
    --cc=willy@infradead.org \
    --cc=wuchi.zero@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.