hw/block/nvme: fix null ns in register namespace

Fix dereference after NULL check.

Reported-by: Coverity (CID 1436128)
Fixes: b20804946b ("hw/block/nvme: update nsid when registered")
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Message-Id: <20201104102248.32168-2-its@irrelevant.dk>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
Klaus Jensen 2020-11-04 11:22:46 +01:00 committed by Max Reitz
parent 3441ad4bc4
commit 8ce648056f
1 changed files with 1 additions and 2 deletions

View File

@ -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;
}