* [PATCH] nvme: fix uninitialized-variable warning
@ 2020-01-07 21:42 Arnd Bergmann
2020-01-30 15:04 ` Christoph Hellwig
0 siblings, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2020-01-07 21:42 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
Cc: Oleksandr Natalenko, Bart Van Assche, Chaitanya Kulkarni,
Marta Rybczynska, linux-kernel, linux-nvme, Arnd Bergmann,
Hannes Reinecke
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.
Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/nvme/host/core.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 667f18f465be..6f0991e8c5cc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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;
}
--
2.20.0
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: fix uninitialized-variable warning
2020-01-07 21:42 [PATCH] nvme: fix uninitialized-variable warning Arnd Bergmann
@ 2020-01-30 15:04 ` Christoph Hellwig
2020-01-30 15:36 ` Arnd Bergmann
0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-01-30 15:04 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Oleksandr Natalenko, Bart Van Assche, Chaitanya Kulkarni,
Marta Rybczynska, linux-kernel, linux-nvme, Jens Axboe,
Hannes Reinecke, Keith Busch, Christoph Hellwig, Sagi Grimberg
On Tue, Jan 07, 2020 at 10:42:08PM +0100, Arnd Bergmann wrote:
> Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> drivers/nvme/host/core.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 667f18f465be..6f0991e8c5cc 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -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.
>
> 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)
OTOH if this shuts up a compiler warning I'd be perfectly fine with it.
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: fix uninitialized-variable warning
2020-01-30 15:04 ` Christoph Hellwig
@ 2020-01-30 15:36 ` Arnd Bergmann
2020-01-30 15:48 ` Christoph Hellwig
0 siblings, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2020-01-30 15:36 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Oleksandr Natalenko, Bart Van Assche, Chaitanya Kulkarni,
Marta Rybczynska, linux-kernel, linux-nvme, Jens Axboe,
Hannes Reinecke, Keith Busch, Christoph Hellwig, Sagi Grimberg
On Thu, Jan 30, 2020 at 4:04 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Tue, Jan 07, 2020 at 10:42:08PM +0100, Arnd Bergmann wrote:
> > Fixes: mmtom ("init/Kconfig: enable -O3 for all arches")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > ---
> > drivers/nvme/host/core.c | 7 ++++---
> > 1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> > index 667f18f465be..6f0991e8c5cc 100644
> > --- a/drivers/nvme/host/core.c
> > +++ b/drivers/nvme/host/core.c
> > @@ -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.
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
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: fix uninitialized-variable warning
2020-01-30 15:36 ` Arnd Bergmann
@ 2020-01-30 15:48 ` Christoph Hellwig
2020-02-13 19:51 ` Keith Busch
0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2020-01-30 15:48 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Oleksandr Natalenko, Jens Axboe, Sagi Grimberg,
Chaitanya Kulkarni, Marta Rybczynska, linux-kernel, linux-nvme,
Christoph Hellwig, Hannes Reinecke, Keith Busch,
Christoph Hellwig, Bart Van Assche
On Thu, Jan 30, 2020 at 04:36:48PM +0100, Arnd Bergmann wrote:
> > 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.
Given that this is outside the hot path we can just zero the whole
structure before submitting the I/O.
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: fix uninitialized-variable warning
2020-01-30 15:48 ` Christoph Hellwig
@ 2020-02-13 19:51 ` Keith Busch
2020-02-19 15:21 ` Christoph Hellwig
0 siblings, 1 reply; 9+ messages in thread
From: Keith Busch @ 2020-02-13 19:51 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Oleksandr Natalenko, Bart Van Assche, Arnd Bergmann,
Chaitanya Kulkarni, linux-kernel, linux-nvme, Jens Axboe,
Marta Rybczynska, Hannes Reinecke, Christoph Hellwig,
Sagi Grimberg
On Thu, Jan 30, 2020 at 07:48:15AM -0800, Christoph Hellwig wrote:
> On Thu, Jan 30, 2020 at 04:36:48PM +0100, Arnd Bergmann wrote:
> > > 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.
>
> 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:
---
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 7f05deada7f4..4aeed750dab2 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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));
--
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: fix uninitialized-variable warning
2020-02-13 19:51 ` Keith Busch
@ 2020-02-19 15:21 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2020-02-19 15:21 UTC (permalink / raw)
To: Keith Busch
Cc: Oleksandr Natalenko, Jens Axboe, Sagi Grimberg, Arnd Bergmann,
Chaitanya Kulkarni, linux-kernel, linux-nvme, Christoph Hellwig,
Marta Rybczynska, Hannes Reinecke, Christoph Hellwig,
Bart Van Assche
On Fri, Feb 14, 2020 at 04:51:06AM +0900, Keith Busch wrote:
> On Thu, Jan 30, 2020 at 07:48:15AM -0800, Christoph Hellwig wrote:
> > On Thu, Jan 30, 2020 at 04:36:48PM +0100, Arnd Bergmann wrote:
> > > > 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.
> >
> > 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?
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] nvme: Fix uninitialized-variable warning
@ 2020-02-19 16:19 Keith Busch
2020-02-19 16:22 ` Christoph Hellwig
2020-02-20 7:43 ` Sagi Grimberg
0 siblings, 2 replies; 9+ messages in thread
From: Keith Busch @ 2020-02-19 16:19 UTC (permalink / raw)
To: linux-nvme, sagi, hch; +Cc: Keith Busch, Arnd Bergmann
gcc may detect a false positive on nvme using an unintialized variable
if setting features fails. Since this is not a fast path, explicitly
initialize this variable to suppress the warning.
Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/nvme/host/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ada59df642d2..a4d8c90ee7cc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -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));
--
2.21.0
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: Fix uninitialized-variable warning
2020-02-19 16:19 [PATCH] nvme: Fix " Keith Busch
@ 2020-02-19 16:22 ` Christoph Hellwig
2020-02-20 7:43 ` Sagi Grimberg
1 sibling, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2020-02-19 16:22 UTC (permalink / raw)
To: Keith Busch; +Cc: Arnd Bergmann, sagi, linux-nvme, hch
On Thu, Feb 20, 2020 at 01:19:50AM +0900, Keith Busch wrote:
> gcc may detect a false positive on nvme using an unintialized variable
> if setting features fails. Since this is not a fast path, explicitly
> initialize this variable to suppress the warning.
>
> Reported-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] nvme: Fix uninitialized-variable warning
2020-02-19 16:19 [PATCH] nvme: Fix " Keith Busch
2020-02-19 16:22 ` Christoph Hellwig
@ 2020-02-20 7:43 ` Sagi Grimberg
1 sibling, 0 replies; 9+ messages in thread
From: Sagi Grimberg @ 2020-02-20 7:43 UTC (permalink / raw)
To: Keith Busch, linux-nvme, hch; +Cc: Arnd Bergmann
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-02-20 7:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-07 21:42 [PATCH] nvme: fix uninitialized-variable warning Arnd Bergmann
2020-01-30 15:04 ` Christoph Hellwig
2020-01-30 15:36 ` Arnd Bergmann
2020-01-30 15:48 ` Christoph Hellwig
2020-02-13 19:51 ` Keith Busch
2020-02-19 15:21 ` Christoph Hellwig
2020-02-19 16:19 [PATCH] nvme: Fix " Keith Busch
2020-02-19 16:22 ` Christoph Hellwig
2020-02-20 7:43 ` Sagi Grimberg
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).