]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
hw/nvme: verify uniqueness of reclaim unit handle identifiers
authorKlaus Jensen <k.jensen@samsung.com>
Wed, 24 May 2023 09:45:04 +0000 (11:45 +0200)
committerKlaus Jensen <k.jensen@samsung.com>
Wed, 28 Jun 2023 09:22:42 +0000 (11:22 +0200)
Verify that a reclaim unit handle identifier is only specified once in
fdp.ruhs.

Fixes: 73064edfb864 ("hw/nvme: flexible data placement emulation")
Reviewed-by: Jesper Wendel Devantier <j.devantier@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
hw/nvme/ns.c

index 050fdaf50fcdbe229e019dfbc21355055aef9fa7..c4ea2033bb1c0f02481bde5d93587f556feef227 100644 (file)
@@ -453,6 +453,17 @@ static bool nvme_ns_init_fdp(NvmeNamespace *ns, Error **errp)
 
     free(r);
 
+    /* verify that the ruhids are unique */
+    for (unsigned int i = 0; i < ns->fdp.nphs; i++) {
+        for (unsigned int j = i + 1; j < ns->fdp.nphs; j++) {
+            if (ruhids[i] == ruhids[j]) {
+                error_setg(errp, "duplicate reclaim unit handle identifier: %u",
+                           ruhids[i]);
+                return false;
+            }
+        }
+    }
+
     ph = ns->fdp.phs = g_new(uint16_t, ns->fdp.nphs);
 
     ruhid = ruhids;