Message ID | 377fe88656a9ebaa34e60debc5ae80638e277076.1683210012.git.anand.jain@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs-progs: fix may be used uninitialized in __set_extent_bit | expand |
On Thu, May 04, 2023 at 10:37:08PM +0800, Anand Jain wrote: > Compiler is throwing out this false positive warning in the following > function flow. Apparently, %parent and %p are initialized in tree_search_for_insert(). > > __set_extent_bit() > state = tree_search_for_insert(tree, start, &p, &parent); > insert_state_fast(tree, prealloc, p, parent, bits, changeset); > rb_link_node(&state->rb_node, parent, node); > > > Compile warnings: > > In file included from ./common/extent-cache.h:23, > from kernel-shared/ctree.h:26, > from kernel-shared/extent-io-tree.c:4: > kernel-shared/extent-io-tree.c: In function ‘__set_extent_bit’: > ./kernel-lib/rbtree.h:80:28: warning: ‘parent’ may be used uninitialized in this function [-Wmaybe-uninitialized] > node->__rb_parent_color = (unsigned long)parent; > ^~~~~~~~~~~~~~~~~~~~~ > kernel-shared/extent-io-tree.c:996:18: note: ‘parent’ was declared here > struct rb_node *parent; > ^~~~~~ > In file included from ./common/extent-cache.h:23, > from kernel-shared/ctree.h:26, > from kernel-shared/extent-io-tree.c:4: > ./kernel-lib/rbtree.h:83:11: warning: ‘p’ may be used uninitialized in this function [-Wmaybe-uninitialized] > *rb_link = node; > ~~~~~~~~~^~~~~~ > kernel-shared/extent-io-tree.c:995:19: note: ‘p’ was declared here > struct rb_node **p; > > > Fix: > > Initialize to NULL, as in the kernel. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> Added to devel, thanks.
diff --git a/kernel-shared/extent-io-tree.c b/kernel-shared/extent-io-tree.c index 206d154f09fa..35e21feed4cd 100644 --- a/kernel-shared/extent-io-tree.c +++ b/kernel-shared/extent-io-tree.c @@ -992,8 +992,8 @@ static int __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, { struct extent_state *state; struct extent_state *prealloc = NULL; - struct rb_node **p; - struct rb_node *parent; + struct rb_node **p = NULL; + struct rb_node *parent = NULL; int err = 0; u64 last_start; u64 last_end;
Compiler is throwing out this false positive warning in the following function flow. Apparently, %parent and %p are initialized in tree_search_for_insert(). __set_extent_bit() state = tree_search_for_insert(tree, start, &p, &parent); insert_state_fast(tree, prealloc, p, parent, bits, changeset); rb_link_node(&state->rb_node, parent, node); Compile warnings: In file included from ./common/extent-cache.h:23, from kernel-shared/ctree.h:26, from kernel-shared/extent-io-tree.c:4: kernel-shared/extent-io-tree.c: In function ‘__set_extent_bit’: ./kernel-lib/rbtree.h:80:28: warning: ‘parent’ may be used uninitialized in this function [-Wmaybe-uninitialized] node->__rb_parent_color = (unsigned long)parent; ^~~~~~~~~~~~~~~~~~~~~ kernel-shared/extent-io-tree.c:996:18: note: ‘parent’ was declared here struct rb_node *parent; ^~~~~~ In file included from ./common/extent-cache.h:23, from kernel-shared/ctree.h:26, from kernel-shared/extent-io-tree.c:4: ./kernel-lib/rbtree.h:83:11: warning: ‘p’ may be used uninitialized in this function [-Wmaybe-uninitialized] *rb_link = node; ~~~~~~~~~^~~~~~ kernel-shared/extent-io-tree.c:995:19: note: ‘p’ was declared here struct rb_node **p; Fix: Initialize to NULL, as in the kernel. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- kernel-shared/extent-io-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)