[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for-6.0 4/7] hw/block/nvme: fix controller namespaces array index
From: |
Klaus Jensen |
Subject: |
[PATCH for-6.0 4/7] hw/block/nvme: fix controller namespaces array indexing |
Date: |
Wed, 24 Mar 2021 21:09:04 +0100 |
From: Klaus Jensen <k.jensen@samsung.com>
The controller namespaces array being 0-indexed requires 'nsid - 1'
everywhere. Something that is easy to miss. Align the controller
namespaces array with the subsystem namespaces array such that both are
1-indexed.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
hw/block/nvme.h | 8 ++++----
hw/block/nvme.c | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/hw/block/nvme.h b/hw/block/nvme.h
index 9edc86d79e98..c610ab30dc5c 100644
--- a/hw/block/nvme.h
+++ b/hw/block/nvme.h
@@ -217,7 +217,7 @@ typedef struct NvmeCtrl {
* Attached namespaces to this controller. If subsys is not given, all
* namespaces in this list will always be attached.
*/
- NvmeNamespace *namespaces[NVME_MAX_NAMESPACES];
+ NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1];
NvmeSQueue **sq;
NvmeCQueue **cq;
NvmeSQueue admin_sq;
@@ -232,7 +232,7 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t
nsid)
return NULL;
}
- return n->namespaces[nsid - 1];
+ return n->namespaces[nsid];
}
static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns)
@@ -253,7 +253,7 @@ static inline void nvme_ns_attach(NvmeCtrl *n,
NvmeNamespace *ns)
uint32_t nsid = nvme_nsid(ns);
assert(nsid && nsid <= NVME_MAX_NAMESPACES);
- n->namespaces[nsid - 1] = ns;
+ n->namespaces[nsid] = ns;
}
static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
@@ -261,7 +261,7 @@ static inline void nvme_ns_detach(NvmeCtrl *n,
NvmeNamespace *ns)
uint32_t nsid = nvme_nsid(ns);
assert(nsid && nsid <= NVME_MAX_NAMESPACES);
- n->namespaces[nsid - 1] = NULL;
+ n->namespaces[nsid] = NULL;
}
static inline NvmeCQueue *nvme_cq(NvmeRequest *req)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index 6842b01ab58b..7a7e793c6c26 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -5909,7 +5909,7 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace
*ns, Error **errp)
return -1;
}
} else {
- if (n->namespaces[nsid - 1]) {
+ if (n->namespaces[nsid]) {
error_setg(errp, "namespace id '%d' is already in use", nsid);
return -1;
}
--
2.31.0
[PATCH for-6.0 7/7] hw/block/nvme: fix handling of private namespaces, Klaus Jensen, 2021/03/24
[PATCH for-6.0 6/7] hw/block/nvme: update dmsrl limit on namespace detachment, Klaus Jensen, 2021/03/24
[PATCH for-6.0 4/7] hw/block/nvme: fix controller namespaces array indexing,
Klaus Jensen <=
[PATCH for-6.0 5/7] hw/block/nvme: fix warning about legacy namespace configuration, Klaus Jensen, 2021/03/24