nvme: fix uninitialized-variable warning
PATCH 1/1 nvme: fix uninitialized-variable warning
gcc -O3 adds a bogus warning in this file:
In file included from include/linux/compiler_types.h:68,
from <command-line>:drivers/nvme/host/core.c: In function 'nvme_set_queue_count':include/linux/compiler-gcc.h:71:45: error: 'res.u32' may be used uninitialized in this function [-Werror=maybe-uninitialized]
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
^~~~~~~~~~~~
drivers/nvme/host/core.c:1167:20: note: 'res.u32' was declared here
union nvme_result res;
^~~Slightly rearrange the code, enough to let gcc understand better what is going on and not warn about it.
--- drivers/nvme/host/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +4 -3
@@ -825,14 +825,15 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,int ret; req =nvme_alloc_request (q, cmd, flags, qid); -if (IS_ERR (req)) -return PTR_ERR (req); + ret =PTR_ERR_OR_ZERO (req); +if (ret <0 ) +return ret; req->timeout = timeout ? timeout :ADMIN_TIMEOUT ;if (buffer && bufflen) { ret =blk_rq_map_kern (q, req, buffer, bufflen,GFP_KERNEL ); -if (ret) +if (ret <0 ) goto out; }
Signature · 1 line
2.20.0
Quoted 11 lines · Arnd Bergmann
Fixes mmtom ("init/Kconfig: enable -O3 for all arches")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/nvme/host/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +0
-0
drivers/nvme/host/core.c int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, · line 830
Quoted 8 lines
drivers/nvme/host/core.c +3
-2@@ -825,14 +825,15 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,int ret; req =nvme_alloc_request (q, cmd, flags, qid); -if (IS_ERR (req)) -return PTR_ERR (req); + ret =PTR_ERR_OR_ZERO (req); +if (ret <0 ) +return ret;
This one is just gross. I think we'll need to find some other fix that doesn't obsfucate the code as much.
drivers/nvme/host/core.c int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, · line 836
Quoted 7 lines
drivers/nvme/host/core.c +1
-1req->timeout = timeout ? timeout :ADMIN_TIMEOUT ;if (buffer && bufflen) { ret =blk_rq_map_kern (q, req, buffer, bufflen,GFP_KERNEL ); -if (ret) +if (ret <0 )
OTOH if this shuts up a compiler warning I'd be perfectly fine with it.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 15 lines · Christoph Hellwig
Quoted 13 lines · Arnd Bergmann
Fixes mmtom ("init/Kconfig: enable -O3 for all arches")Signed-off-by Arnd Bergmann <[email protected]>--- drivers/nvme/host/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)drivers/nvme/host/core.c +0
-0@@ -825,14 +825,15 @@ int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd,int ret;
Quoted 9 lines
drivers/nvme/host/core.c int __nvme_submit_sync_cmd(struct request_queue *q, struct nvme_command *cmd, · line 830
Quoted 6 lines
drivers/nvme/host/core.c +3
-2req =nvme_alloc_request (q, cmd, flags, qid); -if (IS_ERR (req)) -return PTR_ERR (req); + ret =PTR_ERR_OR_ZERO (req); +if (ret <0 ) +return ret;This one is just gross. I think we'll need to find some other fix that doesn't obsfucate the code as much.
Initializing the nvme_result in nvme_features() would do it, as would setting it in the error path in __nvme_submit_sync_cmd() -- either way the compiler cannot be confused about whether it is initialized later on.
Arnd
Quoted 7 lines · Arnd Bergmann
Quoted 2 lines
This one is just gross. I think we'll need to find some other fix that doesn't obsfucate the code as much.
Initializing the
nvme_resultinnvme_features()would do it, as would setting it in the error path in__nvme_submit_sync_cmd()-- either way the compiler cannot be confused about whether it is initialized later on.
Given that this is outside the hot path we can just zero the whole structure before submitting the I/O.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 11 lines · Christoph Hellwig
Quoted 7 lines · Arnd Bergmann
Quoted 2 lines
This one is just gross. I think we'll need to find some other fix that doesn't obsfucate the code as much.
Initializing the
nvme_resultinnvme_features()would do it, as would setting it in the error path in__nvme_submit_sync_cmd()-- either way the compiler cannot be confused about whether it is initialized later on.Given that this is outside the hot path we can just zero the whole structure before submitting the I/O.
I think this should be okay:
---
drivers/nvme/host/core.c +1 -1
@@ -1165,8 +1165,8 @@ static int nvme_identify_ns(struct nvme_ctrl *ctrl,static int nvme_features (struct nvme_ctrl *dev,u8 op,unsigned int fid,unsigned int dword11,void *buffer,size_t buflen,u32 *result) { +union nvme_result res = {0 };struct nvme_command c; -union nvme_result res;int ret;memset (&c,0 ,sizeof (c));
--
Christoph Hellwig
maintainerQuoted 10 lines · Keith Busch
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Arnd Bergmann
Quoted 2 lines
This one is just gross. I think we'll need to find some other fix that doesn't obsfucate the code as much.
Initializing the
nvme_resultinnvme_features()would do it, as would setting it in the error path in__nvme_submit_sync_cmd()-- either way the compiler cannot be confused about whether it is initialized later on.
Quoted 4 lines
Quoted 2 lines
Given that this is outside the hot path we can just zero the whole structure before submitting the I/O.
I think this should be okay:
This looks good. Can you send a formal patch?