* [PATCH] xfs: Zero initialize highstale and lowstale in xfs_dir2_leafn_add
@ 2019-03-08 0:34 Nathan Chancellor
2019-03-08 0:47 ` Darrick J. Wong
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2019-03-08 0:34 UTC (permalink / raw)
To: Darrick J. Wong
Cc: linux-xfs, linux-kernel, Nick Desaulniers, clang-built-linux,
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.
Link: https://github.com/ClangBuiltLinux/linux/issues/393
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
fs/xfs/libxfs/xfs_dir2_node.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
index 3b03703c5c3d..de46f26c5292 100644
--- a/fs/xfs/libxfs/xfs_dir2_node.c
+++ b/fs/xfs/libxfs/xfs_dir2_node.c
@@ -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);
--
2.21.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] xfs: Zero initialize highstale and lowstale in xfs_dir2_leafn_add
2019-03-08 0:34 [PATCH] xfs: Zero initialize highstale and lowstale in xfs_dir2_leafn_add Nathan Chancellor
@ 2019-03-08 0:47 ` Darrick J. Wong
0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2019-03-08 0:47 UTC (permalink / raw)
To: Nathan Chancellor
Cc: linux-xfs, linux-kernel, Nick Desaulniers, clang-built-linux
On Thu, Mar 07, 2019 at 05:34:13PM -0700, Nathan Chancellor wrote:
> 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.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/393
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
> fs/xfs/libxfs/xfs_dir2_node.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
> index 3b03703c5c3d..de46f26c5292 100644
> --- a/fs/xfs/libxfs/xfs_dir2_node.c
> +++ b/fs/xfs/libxfs/xfs_dir2_node.c
> @@ -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,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
(I'll have this and the cleanup tested and ready tomorrow, probably...)
Thanks for the contribution!
--D
> dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
> ents = dp->d_ops->leaf_ents_p(leaf);
>
> --
> 2.21.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-03-08 0:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-08 0:34 [PATCH] xfs: Zero initialize highstale and lowstale in xfs_dir2_leafn_add Nathan Chancellor
2019-03-08 0:47 ` Darrick J. Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox