Skip to contentSkip to conversation

hw/block/nvme: coverity fixes

PATCH In review Klaus Jensen 3 participants 13 messages Nov 4, 2020

lore
Share & tools
lore
#0 lore raw

cover hw/block/nvme: coverity fixes

From: Klaus Jensen <[email protected]>

Fix three issues reported by coverity (CIDs 1436128, 1436129 and 1436131).

Klaus Jensen (3):
hw/block/nvme: fix null ns in register namespace hw/block/nvme: fix uint16_t use of uint32_t sgls member hw/block/nvme: fix free of array-typed value

 hw/block/nvme.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Signature · 1 line
2.29.1
#1 lore raw

PATCH 1/3 hw/block/nvme: fix null ns in register namespace

From: Klaus Jensen <[email protected]>

Fix dereference after NULL check.

Reported-by Coverity (CID 1436128)
Fixes b20804946bce ("hw/block/nvme: update nsid when registered")
---
 hw/block/nvme.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/block/nvme.c +1 -2
index fa2cba744b57..080d782f1c2b 100644
@@ -2562,8 +2562,7 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
 
     if (!nsid) {
         for (int i = 1; i <= n->num_namespaces; i++) {
-            NvmeNamespace *ns = nvme_ns(n, i);
-            if (!ns) {
+            if (!nvme_ns(n, i)) {
                 nsid = ns->params.nsid = i;
                 break;
             }
Signature · 1 line
2.29.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH for-5.2 1/3] hw/block/nvme: fix null ns in register namespace

Quoted 10 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Fix dereference after NULL check.

Reported-by Coverity (CID 1436128)
Fixes b20804946bce ("hw/block/nvme: update nsid when registered")
---
 hw/block/nvme.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH for-5.2 1/3] hw/block/nvme: fix null ns in register namespace

In reply to Klaus Jensen
Quoted 16 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Fix dereference after NULL check.

Reported-by Coverity (CID 1436128)
Fixes b20804946bce ("hw/block/nvme: update nsid when registered")
---
 hw/block/nvme.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/block/nvme.c +0 -0
index fa2cba744b57..080d782f1c2b 100644

hw/block/nvme.c int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) · line 2566

Quoted 7 lines
hw/block/nvme.c +1 -2
@@ -2562,8 +2562,7 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
 
     if (!nsid) {
         for (int i = 1; i <= n->num_namespaces; i++) {
-            NvmeNamespace *ns = nvme_ns(n, i);
-            if (!ns) {
+            if (!nvme_ns(n, i)) {
                 nsid = ns->params.nsid = i;

Uh.

Quoted 3 lines
hw/block/nvme.c +0 -0
                 break;
             }
#4 lore raw

PATCH 2/3 hw/block/nvme: fix uint16_t use of uint32_t sgls member

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

nvme_map_sgl_data erroneously uses the sgls member of NvmeIdNs as a uint16_t.

Reported-by Coverity (CID 1436129)
Fixes cba0a8a344fe ("hw/block/nvme: add support for scatter gather lists")
---
 hw/block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +1 -1
index 080d782f1c2b..2bdc50eb6fce 100644
@@ -452,7 +452,7 @@ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, QEMUSGList *qsg,
              * segments and/or descriptors. The controller might accept
              * ignoring the rest of the SGL.
              */
-            uint16_t sgls = le16_to_cpu(n->id_ctrl.sgls);
+            uint32_t sgls = le32_to_cpu(n->id_ctrl.sgls);
             if (sgls & NVME_CTRL_SGLS_EXCESS_LENGTH) {
                 break;
             }
Signature · 1 line
2.29.1
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH for-5.2 2/3] hw/block/nvme: fix uint16_t use of uint32_t sgls member

Quoted 11 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

nvme_map_sgl_data erroneously uses the sgls member of NvmeIdNs as a uint16_t.

Reported-by Coverity (CID 1436129)
Fixes cba0a8a344fe ("hw/block/nvme: add support for scatter gather lists")
---
 hw/block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH for-5.2 2/3] hw/block/nvme: fix uint16_t use of uint32_t sgls member

In reply to Klaus Jensen
Quoted 17 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

nvme_map_sgl_data erroneously uses the sgls member of NvmeIdNs as a uint16_t.

Reported-by Coverity (CID 1436129)
Fixes cba0a8a344fe ("hw/block/nvme: add support for scatter gather lists")
---
 hw/block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +0 -0
index 080d782f1c2b..2bdc50eb6fce 100644

hw/block/nvme.c static uint16_t nvme_map_sgl_data(NvmeCtrl *n, QEMUSGList *qsg, · line 456

Quoted 6 lines
hw/block/nvme.c +1 -1
@@ -452,7 +452,7 @@ static uint16_t nvme_map_sgl_data(NvmeCtrl *n, QEMUSGList *qsg,
              * segments and/or descriptors. The controller might accept
              * ignoring the rest of the SGL.
              */
-            uint16_t sgls = le16_to_cpu(n->id_ctrl.sgls);
+            uint32_t sgls = le32_to_cpu(n->id_ctrl.sgls);
             if (sgls & NVME_CTRL_SGLS_EXCESS_LENGTH) {

I'm surprise the compiler doesn't warn here.

Quoted 3 lines
hw/block/nvme.c +0 -0
                 break;
             }
#7 lore raw

PATCH 3/3 hw/block/nvme: fix free of array-typed value

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

Since 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces"), the namespaces member of NvmeCtrl is no longer a dynamically allocated array. Remove the free.

Fixes 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces")
Reported-by Coverity (CID 1436131)
---
 hw/block/nvme.c | 1 -
 1 file changed, 1 deletion(-)
hw/block/nvme.c +0 -1
index 2bdc50eb6fce..01b657b1c5e2 100644
@@ -2799,7 +2799,6 @@ static void nvme_exit(PCIDevice *pci_dev)
     NvmeCtrl *n = NVME(pci_dev);
 
     nvme_clear_ctrl(n);
-    g_free(n->namespaces);
     g_free(n->cq);
     g_free(n->sq);
     g_free(n->aer_reqs);
Signature · 1 line
2.29.1
Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH for-5.2 3/3] hw/block/nvme: fix free of array-typed value

Quoted 6 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Since 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces"), the namespaces member of NvmeCtrl is no longer a dynamically allocated array. Remove the free.

Quoted 6 lines
Fixes 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces")
Reported-by Coverity (CID 1436131)
---
 hw/block/nvme.c | 1 -
 1 file changed, 1 deletion(-)
Reviewed-by on v1 3/3
#9 lore raw

Re: [PATCH for-5.2 3/3] hw/block/nvme: fix free of array-typed value

In reply to Klaus Jensen
Quoted 6 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Since 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces"), the namespaces member of NvmeCtrl is no longer a dynamically allocated array. Remove the free.

Quoted 6 lines
Fixes 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces")
Reported-by Coverity (CID 1436131)
---
 hw/block/nvme.c | 1 -
 1 file changed, 1 deletion(-)

Thanks! :)

#10 lore raw

Re: [PATCH for-5.2 3/3] hw/block/nvme: fix free of array-typed value

Quoted 14 lines · Max Reitz
Quoted 6 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Since 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces"), the namespaces member of NvmeCtrl is no longer a dynamically allocated array. Remove the free.

Quoted 6 lines
Fixes 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces")
Reported-by Coverity (CID 1436131)
---
 hw/block/nvme.c | 1 -
 1 file changed, 1 deletion(-)
Quoted 4 lines

Thanks! :)

Will Peter pick up fixes like this directly so we don't have to go through a pull request from nvme-next?

Did I correctly annotate with "for-5.2"? :)

#11 lore raw

Re: [PATCH for-5.2 3/3] hw/block/nvme: fix free of array-typed value

Quoted 15 lines · Klaus Jensen
Quoted 14 lines · Max Reitz
Quoted 12 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Since 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces"), the namespaces member of NvmeCtrl is no longer a dynamically allocated array. Remove the free.

Fixes 7f0f1acedf15 ("hw/block/nvme: support multiple namespaces")
Reported-by Coverity (CID 1436131)
---
 hw/block/nvme.c | 1 -
 1 file changed, 1 deletion(-)
Quoted 7 lines
Quoted 4 lines

Thanks! :)

Will Peter pick up fixes like this directly so we don't have to go through a pull request from nvme-next?

AFAIA, Peter only picks up build fixes. Since the build wasn’t broken, I think someone™ will have to send a pull request...

I understand you don’t necessarily want to be that someone, so I suppose I might as well.

Quoted 1 line

Did I correctly annotate with "for-5.2"? :)

Yes!

Max

#12 lore raw
In reply to Klaus Jensen
Quoted 5 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Fix three issues reported by coverity (CIDs 1436128, 1436129 and 1436131).

Quoted 7 lines

Klaus Jensen (3):
hw/block/nvme: fix null ns in register namespace hw/block/nvme: fix uint16_t use of uint32_t sgls member hw/block/nvme: fix free of array-typed value

 hw/block/nvme.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Thanks again, applied to my block branch:

https://git.xanclic.moe/XanClic/qemu/commits/branch/block

Max