Skip to contentSkip to conversation

hw/block: nvme: Fix a build error in nvme_get_feature()

PATCH Superseded Bin Meng 7 participants 11 messages Feb 10, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v2 1/1 hw/block: nvme: Fix a build error in nvme_get_feature()

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^

Explicitly initialize the result to fix it.

Fixes aa5e55e3b07e ("hw/block/nvme: open code for volatile write cache")

---

Changes in v2:
- update function name in the commit message

 hw/block/nvme.c | 1 +
 1 file changed, 1 insertion(+)
hw/block/nvme.c +1 -0
index 5ce21b7..c122ac0 100644
@@ -3228,6 +3228,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
         result = ns->features.err_rec;
         goto out;
     case NVME_VOLATILE_WRITE_CACHE:
+        result = 0;
         for (i = 1; i <= n->num_namespaces; i++) {
             ns = nvme_ns(n, i);
             if (!ns) {
Signature · 1 line
2.7.4
#1 lore raw

CC qemu-trivial.

Quoted 40 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^

Explicitly initialize the result to fix it.

Fixes aa5e55e3b07e ("hw/block/nvme: open code for volatile write cache")

---

Changes in v2:
- update function name in the commit message

 hw/block/nvme.c | 1 +
 1 file changed, 1 insertion(+)
hw/block/nvme.c +1 -0
index 5ce21b7..c122ac0 100644
@@ -3228,6 +3228,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
         result = ns->features.err_rec;
         goto out;
     case NVME_VOLATILE_WRITE_CACHE:
+        result = 0;
         for (i = 1; i <= n->num_namespaces; i++) {
             ns = nvme_ns(n, i);
             if (!ns) {
Signature · 1 line
2.7.4
#2 lore raw
In reply to Bin Meng
Quoted 11 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^
Quoted 4 lines

Explicitly initialize the result to fix it.

Fixes aa5e55e3b07e ("hw/block/nvme: open code for volatile write cache")

Bin,

Thanks for the fix!

#3 lore raw
In reply to Bin Meng

Hi Bin,

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^

Why isn't this catched by our CI? What is your host OS? Fedora 33?

Quoted 13 lines

Explicitly initialize the result to fix it.

Fixes aa5e55e3b07e ("hw/block/nvme: open code for volatile write cache")

---

Changes in v2:
- update function name in the commit message

 hw/block/nvme.c | 1 +
 1 file changed, 1 insertion(+)
author
#4 lore raw

Hi Philippe,

Quoted 8 lines · Philippe Mathieu-Daudé

Hi Bin,

Quoted 4 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

Quoted 9 lines
Quoted 6 lines

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^

Why isn't this catched by our CI? What is your host OS? Fedora 33?

I am using GCC 5.4 on Ubuntu 16.04. Please see some initial analysis from Peter about why newer version GCC does not report it.

Regards,
Bin

#5 lore raw
Quoted 19 lines · Bin Meng

Hi Philippe,

Quoted 15 lines · Philippe Mathieu-Daudé

Hi Bin,

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

   hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
          trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
          ^
   hw/block/nvme.c:3150:14: note: ‘result’ was declared here
      uint32_t result;
               ^
Quoted 5 lines
Quoted 2 lines

Why isn't this catched by our CI? What is your host OS? Fedora 33?

I am using GCC 5.4 on Ubuntu 16.04. Please see some initial analysis from Peter about why newer version GCC does not report it.

Please note that Ubuntu 16.04 is not a supported version by QEMU anymore, see https://qemu.readthedocs.io/en/latest/system/build-platforms.html and https://wiki.qemu.org/Supported_Build_Platforms for details.

Thomas

#6 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Hi Bin,

Quoted 4 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

Quoted 8 lines
Quoted 6 lines

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^

Why isn't this catched by our CI? What is your host OS? Fedora 33?

Just noticed v1 and Peter's explanation:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03528.html

Can you amend "default GCC 5.4 on a Ubuntu 16.04 host" information please?

Quoted 14 lines
Quoted 14 lines

Explicitly initialize the result to fix it.

Fixes aa5e55e3b07e ("hw/block/nvme: open code for volatile write cache")

---

Changes in v2:
- update function name in the commit message

 hw/block/nvme.c | 1 +
 1 file changed, 1 insertion(+)
author
#7 lore raw

Hi Philippe,

Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

Hi Bin,

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^
Quoted 8 lines
Quoted 1 line

Why isn't this catched by our CI? What is your host OS? Fedora 33?

Just noticed v1 and Peter's explanation:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03528.html

Can you amend "default GCC 5.4 on a Ubuntu 16.04 host" information please?

Sure.

Regards,
Bin

#8 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

Hi Bin,

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^
Quoted 7 lines
Quoted 1 line

Why isn't this catched by our CI? What is your host OS? Fedora 33?

Just noticed v1 and Peter's explanation:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03528.html

Can you amend "default GCC 5.4 on a Ubuntu 16.04 host" information please?

Well Ubuntu 16.04 hasn't been considered a supported build target for QEMU for a year now.

https://qemu.readthedocs.io/en/latest/system/build-platforms.html#linux-os-macos-freebsd-netbsd-openbsd

"The project aims to support the most recent major version
at all times. Support for the previous major version will be dropped 2 years after the new major version is released or when the vendor itself drops support, whichever comes first."

IOW, we only aim for QEMU to be buildable on Ubuntu LTS 20.04 and 18.04 at this point in time. 16.04 is explicitly dropped and we will increasingly introduce incompatibilities with it.

While this specific patch is simple, trying to keep QEMU git master working on 16.04 is not a goal, so I'd really suggest upgrading to a newer Ubuntu version at the soonest opportunity.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#9 lore raw
Quoted 35 lines · Daniel P. Berrangé
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

Hi Bin,

Quoted 10 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^
Quoted 7 lines
Quoted 1 line

Why isn't this catched by our CI? What is your host OS? Fedora 33?

Just noticed v1 and Peter's explanation:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg03528.html

Can you amend "default GCC 5.4 on a Ubuntu 16.04 host" information please?

Well Ubuntu 16.04 hasn't been considered a supported build target for QEMU for a year now.

https://qemu.readthedocs.io/en/latest/system/build-platforms.html#linux-os-macos-freebsd-netbsd-openbsd

"The project aims to support the most recent major version
at all times. Support for the previous major version will be dropped 2 years after the new major version is released or when the vendor itself drops support, whichever comes first."

Quoted 7 lines

IOW, we only aim for QEMU to be buildable on Ubuntu LTS 20.04 and 18.04 at this point in time. 16.04 is explicitly dropped and we will increasingly introduce incompatibilities with it.

While this specific patch is simple, trying to keep QEMU git master working on 16.04 is not a goal, so I'd really suggest upgrading to a newer Ubuntu version at the soonest opportunity.

In particular after 6.0 QEMU is released, we'll be dropping RHEL-7 and then likely setting the min required GCC to somewhere around 6.3 which will cut off Ubuntu 16.04 upfront.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw
In reply to Bin Meng
Quoted 30 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile:

hw/block/nvme.c:3242:9: error: ‘result’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

         trace_pci_nvme_getfeat_vwcache(result ? "enabled" : "disabled");
         ^
  hw/block/nvme.c:3150:14: note: ‘result’ was declared here
     uint32_t result;
              ^

Explicitly initialize the result to fix it.

Fixes aa5e55e3b07e ("hw/block/nvme: open code for volatile write cache")

---

Changes in v2:
- update function name in the commit message

 hw/block/nvme.c | 1 +
 1 file changed, 1 insertion(+)
hw/block/nvme.c +0 -0
index 5ce21b7..c122ac0 100644

hw/block/nvme.c static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)

Quoted 8 lines
hw/block/nvme.c +1 -1
@@ -3228,6 +3228,7 @@ static uint16_t nvme_get_feature(NvmeCtrl *n, NvmeRequest *req)
         result = ns->features.err_rec;
         goto out;
     case NVME_VOLATILE_WRITE_CACHE:
+        result = 0;
         for (i = 1; i <= n->num_namespaces; i++) {
             ns = nvme_ns(n, i);
             if (!ns) {
--

Also spotted by Coverity: CID 1446371

-- PMM