* [PATCH] NFS: Avoid using error uninitialized in nfs_lookup()
@ 2021-11-05 15:57 Nathan Chancellor
2021-11-05 20:01 ` Nick Desaulniers
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Chancellor @ 2021-11-05 15:57 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker
Cc: Nick Desaulniers, linux-nfs, linux-kernel, llvm, Nathan Chancellor
Clang warns:
fs/nfs/dir.c:1772:6: error: variable 'error' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
if (fhandle == NULL || fattr == NULL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/nfs/dir.c:1801:44: note: uninitialized use occurs here
trace_nfs_lookup_exit(dir, dentry, flags, error);
^~~~~
fs/nfs/dir.c:1772:2: note: remove the 'if' if its condition is always false
if (fhandle == NULL || fattr == NULL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/nfs/dir.c:1772:6: error: variable 'error' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]
if (fhandle == NULL || fattr == NULL)
^~~~~~~~~~~~~~~
fs/nfs/dir.c:1801:44: note: uninitialized use occurs here
trace_nfs_lookup_exit(dir, dentry, flags, error);
^~~~~
fs/nfs/dir.c:1772:6: note: remove the '||' if its condition is always false
if (fhandle == NULL || fattr == NULL)
^~~~~~~~~~~~~~~~~~
fs/nfs/dir.c:1754:11: note: initialize the variable 'error' to silence this warning
int error;
^
= 0
2 errors generated.
Add a label to skip the call to trace_nfs_lookup_exit() when the call to
nfs_alloc_fhandle() or nfs_alloc_fattr_with_label() fails because
trace_nfs_lookup_enter() has not been called at that point so tracing
the exit does not make sense.
Fixes: 8d3df1d0387e ("NFS: Remove the label from the nfs4_lookup_res struct")
Link: https://github.com/ClangBuiltLinux/linux/issues/1498
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
fs/nfs/dir.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 8de99f426183..1c978a7cf730 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1770,7 +1770,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
fhandle = nfs_alloc_fhandle();
fattr = nfs_alloc_fattr_with_label(NFS_SERVER(dir));
if (fhandle == NULL || fattr == NULL)
- goto out;
+ goto out_no_trace;
dir_verifier = nfs_save_change_attribute(dir);
trace_nfs_lookup_enter(dir, dentry, flags);
@@ -1799,6 +1799,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
nfs_set_verifier(dentry, dir_verifier);
out:
trace_nfs_lookup_exit(dir, dentry, flags, error);
+out_no_trace:
nfs_free_fattr(fattr);
nfs_free_fhandle(fhandle);
return res;
base-commit: cb66e0e973daa668dadd43441f877377a1b7b1ff
--
2.34.0.rc0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] NFS: Avoid using error uninitialized in nfs_lookup()
2021-11-05 15:57 [PATCH] NFS: Avoid using error uninitialized in nfs_lookup() Nathan Chancellor
@ 2021-11-05 20:01 ` Nick Desaulniers
0 siblings, 0 replies; 2+ messages in thread
From: Nick Desaulniers @ 2021-11-05 20:01 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Trond Myklebust, Anna Schumaker, linux-nfs, linux-kernel, llvm
On Fri, Nov 5, 2021 at 8:57 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> Clang warns:
>
> fs/nfs/dir.c:1772:6: error: variable 'error' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
> if (fhandle == NULL || fattr == NULL)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> fs/nfs/dir.c:1801:44: note: uninitialized use occurs here
> trace_nfs_lookup_exit(dir, dentry, flags, error);
> ^~~~~
> fs/nfs/dir.c:1772:2: note: remove the 'if' if its condition is always false
> if (fhandle == NULL || fattr == NULL)
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> fs/nfs/dir.c:1772:6: error: variable 'error' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]
> if (fhandle == NULL || fattr == NULL)
> ^~~~~~~~~~~~~~~
> fs/nfs/dir.c:1801:44: note: uninitialized use occurs here
> trace_nfs_lookup_exit(dir, dentry, flags, error);
> ^~~~~
> fs/nfs/dir.c:1772:6: note: remove the '||' if its condition is always false
> if (fhandle == NULL || fattr == NULL)
> ^~~~~~~~~~~~~~~~~~
> fs/nfs/dir.c:1754:11: note: initialize the variable 'error' to silence this warning
> int error;
> ^
> = 0
> 2 errors generated.
>
> Add a label to skip the call to trace_nfs_lookup_exit() when the call to
> nfs_alloc_fhandle() or nfs_alloc_fattr_with_label() fails because
> trace_nfs_lookup_enter() has not been called at that point so tracing
> the exit does not make sense.
>
> Fixes: 8d3df1d0387e ("NFS: Remove the label from the nfs4_lookup_res struct")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1498
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
> fs/nfs/dir.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
> index 8de99f426183..1c978a7cf730 100644
> --- a/fs/nfs/dir.c
> +++ b/fs/nfs/dir.c
> @@ -1770,7 +1770,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
> fhandle = nfs_alloc_fhandle();
> fattr = nfs_alloc_fattr_with_label(NFS_SERVER(dir));
> if (fhandle == NULL || fattr == NULL)
> - goto out;
> + goto out_no_trace;
>
> dir_verifier = nfs_save_change_attribute(dir);
> trace_nfs_lookup_enter(dir, dentry, flags);
> @@ -1799,6 +1799,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
> nfs_set_verifier(dentry, dir_verifier);
> out:
> trace_nfs_lookup_exit(dir, dentry, flags, error);
> +out_no_trace:
> nfs_free_fattr(fattr);
> nfs_free_fhandle(fhandle);
> return res;
>
> base-commit: cb66e0e973daa668dadd43441f877377a1b7b1ff
> --
> 2.34.0.rc0
>
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-05 20:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05 15:57 [PATCH] NFS: Avoid using error uninitialized in nfs_lookup() Nathan Chancellor
2021-11-05 20:01 ` Nick Desaulniers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).