* Re: [PATCH] radix tree test suite: Fix uninitialized variable compilation warning
[not found] <tencent_DF74099967595DCEA93CBDC28D062026180A@qq.com>
@ 2022-11-10 0:23 ` Andrew Morton
2022-11-10 5:00 ` [PATCH] lib/radix-tree: " Rong Tao
2022-11-10 16:06 ` [PATCH] radix tree test suite: " Matthew Wilcox
0 siblings, 2 replies; 5+ messages in thread
From: Andrew Morton @ 2022-11-10 0:23 UTC (permalink / raw)
To: Rong Tao; +Cc: Rong Tao, wuchi, open list, linux-mm, Matthew Wilcox
On Wed, 9 Nov 2022 22:34:25 +0800 Rong Tao <rtoax@foxmail.com> wrote:
> [PATCH] radix tree test suite: Fix uninitialized variable compilation warning
This is not the test suite.
> We need to set an initial value for offset to eliminate compilation
> warning.
>
> 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);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ...
>
> --- a/lib/radix-tree.c
> +++ b/lib/radix-tree.c
> @@ -1029,7 +1029,7 @@ 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)
Are we sure this isn't actually a bug? What happens if the tree is empty?
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] lib/radix-tree: Fix uninitialized variable compilation warning
2022-11-10 0:23 ` [PATCH] radix tree test suite: Fix uninitialized variable compilation warning Andrew Morton
@ 2022-11-10 5:00 ` Rong Tao
2022-11-10 16:06 ` Matthew Wilcox
2022-11-10 16:06 ` [PATCH] radix tree test suite: " Matthew Wilcox
1 sibling, 1 reply; 5+ messages in thread
From: Rong Tao @ 2022-11-10 5:00 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, linux-mm, rongtao, rtoax, willy, wuchi.zero
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] radix tree test suite: Fix uninitialized variable compilation warning
2022-11-10 0:23 ` [PATCH] radix tree test suite: Fix uninitialized variable compilation warning Andrew Morton
2022-11-10 5:00 ` [PATCH] lib/radix-tree: " Rong Tao
@ 2022-11-10 16:06 ` Matthew Wilcox
1 sibling, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2022-11-10 16:06 UTC (permalink / raw)
To: Andrew Morton; +Cc: Rong Tao, Rong Tao, wuchi, open list, linux-mm
On Wed, Nov 09, 2022 at 04:23:48PM -0800, Andrew Morton wrote:
> On Wed, 9 Nov 2022 22:34:25 +0800 Rong Tao <rtoax@foxmail.com> wrote:
>
> > [PATCH] radix tree test suite: Fix uninitialized variable compilation warning
>
> This is not the test suite.
>
> > We need to set an initial value for offset to eliminate compilation
> > warning.
> >
> > 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);
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > ...
> >
> > --- a/lib/radix-tree.c
> > +++ b/lib/radix-tree.c
> > @@ -1029,7 +1029,7 @@ 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)
>
> Are we sure this isn't actually a bug? What happens if the tree is empty?
If the tree is empty, then node is NULL and we never use offset.
The compiler is too stupid to know this. This warning is only observed
when building the test suite and not when building the kernel itself.
I'm not sure the patch is worth it, tbh.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] lib/radix-tree: Fix uninitialized variable compilation warning
2022-11-10 5:00 ` [PATCH] lib/radix-tree: " Rong Tao
@ 2022-11-10 16:06 ` Matthew Wilcox
2022-11-11 2:11 ` Rong Tao
0 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox @ 2022-11-10 16:06 UTC (permalink / raw)
To: Rong Tao; +Cc: akpm, linux-kernel, linux-mm, rongtao, wuchi.zero
On Thu, Nov 10, 2022 at 01:00:42PM +0800, Rong Tao wrote:
> radix_tree_load_root(root, &node, &maxindex);
> - if (index > maxindex)
> + if (index > maxindex || !node)
> return NULL;
No, stop it, you don't know what you're doing.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Re: [PATCH] lib/radix-tree: Fix uninitialized variable compilation warning
2022-11-10 16:06 ` Matthew Wilcox
@ 2022-11-11 2:11 ` Rong Tao
0 siblings, 0 replies; 5+ messages in thread
From: Rong Tao @ 2022-11-11 2:11 UTC (permalink / raw)
To: willy; +Cc: akpm, linux-kernel, linux-mm, rongtao, rtoax, wuchi.zero
Thanks for your reply, actually, at first time, i just want to fix the
compile warning, and i don't really know about the radix tree code,
i'm sorry, i hope i can do it better next time.
Rong Tao.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-11-11 2:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <tencent_DF74099967595DCEA93CBDC28D062026180A@qq.com>
2022-11-10 0:23 ` [PATCH] radix tree test suite: Fix uninitialized variable compilation warning Andrew Morton
2022-11-10 5:00 ` [PATCH] lib/radix-tree: " Rong Tao
2022-11-10 16:06 ` Matthew Wilcox
2022-11-11 2:11 ` Rong Tao
2022-11-10 16:06 ` [PATCH] radix tree test suite: " Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox