hw/block/nvme: coverity fixes
PATCH 1/3 hw/block/nvme: fix null ns in register namespace
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
Fix dereference after NULL check.
--- hw/block/nvme.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
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;break ; }
Signature · 1 line
2.29.1
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
PATCH 2/3 hw/block/nvme: fix uint16_t use of uint32_t sgls member
From: Klaus Jensen <[email protected]>
nvme_map_sgl_data erroneously uses the sgls member of NvmeIdNs as a uint16_t.
--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 ) {break ; }
Signature · 1 line
2.29.1
PATCH 3/3 hw/block/nvme: fix free of array-typed value
In reply to Klaus JensenFrom: 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.
--- hw/block/nvme.c | 1 - 1 file changed, 1 deletion(-)
hw/block/nvme.c +0 -1
@@ -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
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)Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 1 - 1 file changed, 1 deletion(-)
Re: [PATCH for-5.2 1/3] hw/block/nvme: fix null ns in register namespace
In reply to Klaus JensenQuoted 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")Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Re: [PATCH for-5.2 3/3] hw/block/nvme: fix free of array-typed value
In reply to Klaus JensenQuoted 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)Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 1 - 1 file changed, 1 deletion(-)
Thanks! :)
Re: [PATCH for-5.2 2/3] hw/block/nvme: fix uint16_t use of uint32_t sgls member
In reply to Klaus JensenQuoted 11 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
nvme_map_sgl_dataerroneously uses the sgls member of NvmeIdNs as auint16_t.Reported-by Coverity (CID 1436129)Fixes cba0a8a344fe ("hw/block/nvme: add support for scatter gather lists")Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH for-5.2 3/3] hw/block/nvme: fix free of array-typed value
In reply to Max ReitzQuoted 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)Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 1 - 1 file changed, 1 deletion(-)
Quoted 4 lines
Thanks! :)
Reviewed-by Max Reitz <[email protected]>
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"? :)
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)Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 1 - 1 file changed, 1 deletion(-)
Quoted 7 lines
Quoted 4 lines
Thanks! :)
Reviewed-by Max Reitz <[email protected]>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
Re: [PATCH for-5.2 1/3] hw/block/nvme: fix null ns in register namespace
In reply to Klaus JensenQuoted 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")Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)hw/block/nvme.c +0
-0
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
-0break ; }
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: fixuint16_tuse ofuint32_tsgls member hw/block/nvme: fix free of array-typed valuehw/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
Re: [PATCH for-5.2 2/3] hw/block/nvme: fix uint16_t use of uint32_t sgls member
In reply to Klaus JensenQuoted 17 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
nvme_map_sgl_dataerroneously uses the sgls member of NvmeIdNs as auint16_t.Reported-by Coverity (CID 1436129)Fixes cba0a8a344fe ("hw/block/nvme: add support for scatter gather lists")Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/block/nvme.c +0
-0
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
-0break ; }