Skip to contentSkip to conversation

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

PATCH In review Bin Meng 2 participants 2 messages Feb 10, 2021

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v3 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 with the default GCC 5.4 on a Ubuntu 16.04 host:

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 v3:
- mention compiler and host information in the commit message

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
Reviewed-by on v3 1/1
#1 lore raw
Quoted 12 lines · Bin Meng

From: Bin Meng <[email protected]>

Current QEMU HEAD nvme.c does not compile with the default GCC 5.4 on a Ubuntu 16.04 host:

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 6 lines

Explicitly initialize the result to fix it.

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

---

Changes in v3:
- mention compiler and host information in the commit message

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