Skip to contentSkip to conversation

nvme: fix uninitialized-variable warning

PATCH In review Arnd Bergmann 4 participants 6 messages Jan 7, 2020 – Feb 19, 2020 NVMe

lore
Share & tools
lore
#0 lore raw

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.

Fixes mmtom ("init/Kconfig: enable -O3 for all arches")
---
 drivers/nvme/host/core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +4 -3
index 667f18f465be..6f0991e8c5cc 100644
@@ -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
#1 lore raw
Quoted 11 lines · Arnd Bergmann
Fixes mmtom ("init/Kconfig: enable -O3 for all arches")
---
 drivers/nvme/host/core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +0 -0
index 667f18f465be..6f0991e8c5cc 100644

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 -1
 	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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#2 lore raw
Quoted 15 lines · Christoph Hellwig
Quoted 13 lines · Arnd Bergmann
Fixes mmtom ("init/Kconfig: enable -O3 for all arches")
---
 drivers/nvme/host/core.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/host/core.c +0 -0
index 667f18f465be..6f0991e8c5cc 100644
@@ -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 -2
      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

#3 lore raw
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_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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

maintainer
#4 lore raw
Quoted 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_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:

---

drivers/nvme/host/core.c +1 -1
index 7f05deada7f4..4aeed750dab2 100644
@@ -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));

--

#5 lore raw
Quoted 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_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.

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?