Skip to contentSkip to conversation

xfs: Zero initialize highstale and lowstale in xfs_dir2_leafn_add

PATCH In review Nathan Chancellor 2 participants 2 messages Mar 8, 2019 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: Zero initialize highstale and lowstale in xfs_dir2_leafn_add

When building with -Wsometimes-uninitialized, Clang warns:

fs/xfs/libxfs/xfs_dir2_node.c:481:6: warning: variable 'lowstale' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] fs/xfs/libxfs/xfs_dir2_node.c:481:6: warning: variable 'highstale' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

While it isn't technically wrong, it isn't a problem in practice because highstale and lowstale are only initialized in xfs_dir2_leafn_add when compact is not zero then they are passed to xfs_dir3_leaf_find_entry, where they are initialized before use when compact is zero. Regardless, it's better not to be passing around uninitialized stack memory so zero initialize these variables, which silences this warning.

---
 fs/xfs/libxfs/xfs_dir2_node.c | 2 ++
 1 file changed, 2 insertions(+)
fs/xfs/libxfs/xfs_dir2_node.c +2 -0
index 3b03703c5c3d..de46f26c5292 100644
@@ -444,6 +444,8 @@ xfs_dir2_leafn_add(
 
 	dp = args->dp;
 	leaf = bp->b_addr;
+	highstale = 0;
+	lowstale = 0;
 	dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
 	ents = dp->d_ops->leaf_ents_p(leaf);
 
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

fs/xfs/libxfs/xfs_dir2_node.c:481:6: warning: variable 'lowstale' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] fs/xfs/libxfs/xfs_dir2_node.c:481:6: warning: variable 'highstale' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

While it isn't technically wrong, it isn't a problem in practice because highstale and lowstale are only initialized in xfs_dir2_leafn_add when compact is not zero then they are passed to xfs_dir3_leaf_find_entry, where they are initialized before use when compact is zero. Regardless, it's better not to be passing around uninitialized stack memory so zero initialize these variables, which silences this warning.

---
 fs/xfs/libxfs/xfs_dir2_node.c | 2 ++
 1 file changed, 2 insertions(+)
fs/xfs/libxfs/xfs_dir2_node.c +0 -0
index 3b03703c5c3d..de46f26c5292 100644

fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leafn_add( · line 448

Quoted 5 lines
fs/xfs/libxfs/xfs_dir2_node.c +2 -0
@@ -444,6 +444,8 @@ xfs_dir2_leafn_add(
 
 	dp = args->dp;
 	leaf = bp->b_addr;
+	highstale = 0;
+	lowstale = 0;

I think it would be a good idea to clean all the typedef junk out of the function definition as well... but on its own this will at least shut up the smatch/clang warnings, so:

Looks ok,

(I'll have this and the cleanup tested and ready tomorrow, probably...)

Thanks for the contribution!

--D

Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +0 -0
 	dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
 	ents = dp->d_ops->leaf_ents_p(leaf);
 
Signature · 1 line
2.21.0