qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Klaus Jensen <its@irrelevant.dk>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
	qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
	Max Reitz <mreitz@redhat.com>, Keith Busch <kbusch@kernel.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Klaus Jensen <its@irrelevant.dk>
Subject: [PATCH for-6.0 4/7] hw/block/nvme: fix controller namespaces array indexing
Date: Wed, 24 Mar 2021 21:09:04 +0100	[thread overview]
Message-ID: <20210324200907.408996-5-its@irrelevant.dk> (raw)
In-Reply-To: <20210324200907.408996-1-its@irrelevant.dk>

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



  parent reply	other threads:[~2021-03-24 20:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-24 20:09 [PATCH for-6.0 0/7] hw/block/nvme: misc fixes Klaus Jensen
2021-03-24 20:09 ` [PATCH for-6.0 1/7] hw/block/nvme: fix pi constraint check Klaus Jensen
     [not found]   ` <CGME20210329142606epcas5p45c24d24ea384e7bd68c368f1083c1b84@epcas5p4.samsung.com>
2021-03-29 14:22     ` Gollu Appalanaidu
2021-03-30  7:24       ` Klaus Jensen
2021-03-30 11:47         ` Gollu Appalanaidu
2021-03-24 20:09 ` [PATCH for-6.0 2/7] hw/block/nvme: fix missing string representation for ns attachment Klaus Jensen
     [not found]   ` <CGME20210329144714epcas5p4adab8d7549b97fcf3b838f18ab9e070a@epcas5p4.samsung.com>
2021-03-29 14:44     ` Gollu Appalanaidu
2021-03-24 20:09 ` [PATCH for-6.0 3/7] hw/block/nvme: fix the nsid 'invalid' value Klaus Jensen
2021-03-24 20:09 ` Klaus Jensen [this message]
2021-03-24 20:09 ` [PATCH for-6.0 5/7] hw/block/nvme: fix warning about legacy namespace configuration Klaus Jensen
     [not found]   ` <CGME20210330115514epcas5p20071ca07c66434dec11e4f8460267685@epcas5p2.samsung.com>
2021-03-30 11:52     ` Gollu Appalanaidu
2021-03-24 20:09 ` [PATCH for-6.0 6/7] hw/block/nvme: update dmsrl limit on namespace detachment Klaus Jensen
     [not found]   ` <CGME20210330115308epcas5p2f9a0bd130eccb2ce89cba840f2a10b41@epcas5p2.samsung.com>
2021-03-30 11:50     ` Gollu Appalanaidu
2021-03-24 20:09 ` [PATCH for-6.0 7/7] hw/block/nvme: fix handling of private namespaces Klaus Jensen
     [not found]   ` <CGME20210405123541epcas5p21088333e3cbaa1b40e10e7c20ab889aa@epcas5p2.samsung.com>
2021-04-05 12:32     ` Gollu Appalanaidu
2021-04-05 13:56       ` Klaus Jensen
2021-04-05 11:41 ` [PATCH for-6.0 0/7] hw/block/nvme: misc fixes Klaus Jensen
     [not found] ` <CGME20210405123641epcas5p25c0651272e4252ad5b4a96ab638371e7@epcas5p2.samsung.com>
2021-04-05 12:33   ` Gollu Appalanaidu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210324200907.408996-5-its@irrelevant.dk \
    --to=its@irrelevant.dk \
    --cc=fam@euphon.net \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).