diff mbox series

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

Message ID 20201104102248.32168-2-its@irrelevant.dk
State New
Headers show
Series [for-5.2,1/3] hw/block/nvme: fix null ns in register namespace | expand

Commit Message

Klaus Jensen Nov. 4, 2020, 10:22 a.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Fix dereference after NULL check.

Reported-by: Coverity (CID 1436128)
Fixes: b20804946bce ("hw/block/nvme: update nsid when registered")
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/block/nvme.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Max Reitz Nov. 4, 2020, 10:57 a.m. UTC | #1
On 04.11.20 11:22, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>

> 

> Fix dereference after NULL check.

> 

> Reported-by: Coverity (CID 1436128)

> Fixes: b20804946bce ("hw/block/nvme: update nsid when registered")

> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>

> ---

>  hw/block/nvme.c | 3 +--

>  1 file changed, 1 insertion(+), 2 deletions(-)


Reviewed-by: Max Reitz <mreitz@redhat.com>
Philippe Mathieu-Daudé Nov. 4, 2020, 11:08 a.m. UTC | #2
On 11/4/20 11:22 AM, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> Fix dereference after NULL check.
> 
> Reported-by: Coverity (CID 1436128)
> Fixes: b20804946bce ("hw/block/nvme: update nsid when registered")
> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
> ---
>  hw/block/nvme.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/hw/block/nvme.c b/hw/block/nvme.c
> index fa2cba744b57..080d782f1c2b 100644
> --- a/hw/block/nvme.c
> +++ b/hw/block/nvme.c
> @@ -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.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>                  break;
>              }
>
diff mbox series

Patch

diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index fa2cba744b57..080d782f1c2b 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -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;
             }