public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme: Ensure ret is always initialized in
@ 2022-05-06 15:03 Nathan Chancellor
  2022-05-06 15:06 ` Nathan Chancellor
  2022-05-06 15:09 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Nathan Chancellor @ 2022-05-06 15:03 UTC (permalink / raw)
  To: Jens Axboe, Christoph Hellwig, Keith Busch, Sagi Grimberg
  Cc: Nick Desaulniers, Tom Rix, Kanchan Joshi, Anuj Gupta, linux-nvme,
	linux-kernel, llvm, Nathan Chancellor, kernel test robot

Clang warns:

  drivers/nvme/host/ioctl.c:674:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
          if (ns)
              ^~
  drivers/nvme/host/ioctl.c:677:9: note: uninitialized use occurs here
          return ret;
                 ^~~
  drivers/nvme/host/ioctl.c:674:2: note: remove the 'if' if its condition is always true
          if (ns)
          ^~~~~~~
  drivers/nvme/host/ioctl.c:672:9: note: initialize the variable 'ret' to silence this warning
          int ret;
                 ^
                  = 0
  1 error generated.

Initialize ret to zero so that it cannot be used uninitialized.

Fixes: 271ee3df5cca ("nvme: wire-up uring-cmd support for io-passthru on char-device.")
Link: https://github.com/ClangBuiltLinux/linux/issues/1630
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---

Or alternatively, remove the 'if (ns)' if ns can never be NULL; I tried
going down the rabbit hole to see if that is possible but I got a little
lost :^)

 drivers/nvme/host/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
index 9db88f2c15f8..3ad5285c1f96 100644
--- a/drivers/nvme/host/ioctl.c
+++ b/drivers/nvme/host/ioctl.c
@@ -669,7 +669,7 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
 	struct nvme_ns_head *head = container_of(cdev, struct nvme_ns_head, cdev);
 	int srcu_idx = srcu_read_lock(&head->srcu);
 	struct nvme_ns *ns = nvme_find_path(head);
-	int ret;
+	int ret = 0;
 
 	if (ns)
 		ret = nvme_ns_uring_cmd(ns, ioucmd, issue_flags);

base-commit: 002b149a51a53facaf26d7c6f2c1fe718673683c
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nvme: Ensure ret is always initialized in
  2022-05-06 15:03 [PATCH] nvme: Ensure ret is always initialized in Nathan Chancellor
@ 2022-05-06 15:06 ` Nathan Chancellor
  2022-05-06 15:09 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Nathan Chancellor @ 2022-05-06 15:06 UTC (permalink / raw)
  To: Jens Axboe, Christoph Hellwig, Keith Busch, Sagi Grimberg
  Cc: Nick Desaulniers, Tom Rix, Kanchan Joshi, Anuj Gupta, linux-nvme,
	linux-kernel, llvm, kernel test robot

Ugh, subject should be:

nvme: Ensure ret is always initialized in nvme_ns_head_chr_uring_cmd()

I can resend if this is the correct thing to do.

On Fri, May 06, 2022 at 08:03:58AM -0700, Nathan Chancellor wrote:
> Clang warns:
> 
>   drivers/nvme/host/ioctl.c:674:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>           if (ns)
>               ^~
>   drivers/nvme/host/ioctl.c:677:9: note: uninitialized use occurs here
>           return ret;
>                  ^~~
>   drivers/nvme/host/ioctl.c:674:2: note: remove the 'if' if its condition is always true
>           if (ns)
>           ^~~~~~~
>   drivers/nvme/host/ioctl.c:672:9: note: initialize the variable 'ret' to silence this warning
>           int ret;
>                  ^
>                   = 0
>   1 error generated.
> 
> Initialize ret to zero so that it cannot be used uninitialized.
> 
> Fixes: 271ee3df5cca ("nvme: wire-up uring-cmd support for io-passthru on char-device.")
> Link: https://github.com/ClangBuiltLinux/linux/issues/1630
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> 
> Or alternatively, remove the 'if (ns)' if ns can never be NULL; I tried
> going down the rabbit hole to see if that is possible but I got a little
> lost :^)
> 
>  drivers/nvme/host/ioctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c
> index 9db88f2c15f8..3ad5285c1f96 100644
> --- a/drivers/nvme/host/ioctl.c
> +++ b/drivers/nvme/host/ioctl.c
> @@ -669,7 +669,7 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
>  	struct nvme_ns_head *head = container_of(cdev, struct nvme_ns_head, cdev);
>  	int srcu_idx = srcu_read_lock(&head->srcu);
>  	struct nvme_ns *ns = nvme_find_path(head);
> -	int ret;
> +	int ret = 0;
>  
>  	if (ns)
>  		ret = nvme_ns_uring_cmd(ns, ioucmd, issue_flags);
> 
> base-commit: 002b149a51a53facaf26d7c6f2c1fe718673683c
> -- 
> 2.36.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nvme: Ensure ret is always initialized in
  2022-05-06 15:03 [PATCH] nvme: Ensure ret is always initialized in Nathan Chancellor
  2022-05-06 15:06 ` Nathan Chancellor
@ 2022-05-06 15:09 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2022-05-06 15:09 UTC (permalink / raw)
  To: Nathan Chancellor, Jens Axboe, Christoph Hellwig, Keith Busch,
	Sagi Grimberg
  Cc: Nick Desaulniers, Tom Rix, Kanchan Joshi, Anuj Gupta, linux-nvme,
	linux-kernel, llvm, kernel test robot

On 5/6/22 9:03 AM, Nathan Chancellor wrote:
> Clang warns:
> 
>   drivers/nvme/host/ioctl.c:674:6: error: variable 'ret' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>           if (ns)
>               ^~
>   drivers/nvme/host/ioctl.c:677:9: note: uninitialized use occurs here
>           return ret;
>                  ^~~
>   drivers/nvme/host/ioctl.c:674:2: note: remove the 'if' if its condition is always true
>           if (ns)
>           ^~~~~~~
>   drivers/nvme/host/ioctl.c:672:9: note: initialize the variable 'ret' to silence this warning
>           int ret;
>                  ^
>                   = 0
>   1 error generated.
> 
> Initialize ret to zero so that it cannot be used uninitialized.

Thanks, will fold this in.

> Or alternatively, remove the 'if (ns)' if ns can never be NULL; I tried
> going down the rabbit hole to see if that is possible but I got a little
> lost :^)

For the admin queue, ns can be NULL.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-06 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-06 15:03 [PATCH] nvme: Ensure ret is always initialized in Nathan Chancellor
2022-05-06 15:06 ` Nathan Chancellor
2022-05-06 15:09 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox