]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
fix namespace checks for legacy list
authorKeith Busch <kbusch@kernel.org>
Thu, 10 Oct 2019 19:35:56 +0000 (04:35 +0900)
committerKeith Busch <kbusch@kernel.org>
Thu, 10 Oct 2019 19:35:56 +0000 (04:35 +0900)
First ensure the controller we're comparing with has been initialized, and then
compare the correct fields with each other. Previously had been comparing a
model number against the serial.

Link: http://lists.infradead.org/pipermail/linux-nvme/2019-October/027562.html
Reported-by: Jeff Lien <jeff.lien@wdc.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
nvme-topology.c

index 176619d38c03a952a1c7ff645a93f28536ec412b..13ab52c43cfb9cb0ab98fef17470e34a9343cb44 100644 (file)
@@ -263,7 +263,7 @@ static int verify_legacy_ns(struct nvme_namespace *n)
                return ret;
 
        if (memcmp(id.mn, c->id.mn, sizeof(id.mn)) ||
-           memcmp(id.sn, c->id.mn, sizeof(id.sn)))
+           memcmp(id.sn, c->id.sn, sizeof(id.sn)))
                return -ENODEV;
        return 0;
 }
@@ -307,6 +307,18 @@ static int legacy_list(struct nvme_topology *t)
                                           alphasort);
                c->namespaces = calloc(c->nr_namespaces, sizeof(*n));
 
+               ret = asprintf(&path, "%s%s", dev, c->name);
+               if (ret < 0)
+                       continue;
+               ret = 0;
+
+               fd = open(path, O_RDONLY);
+               if (fd > 0) {
+                       nvme_identify_ctrl(fd, &c->id);
+                       close(fd);
+               }
+               free(path);
+
                for (j = 0; j < c->nr_namespaces; j++) {
                        n = &c->namespaces[j];
                        n->name = strdup(namespaces[j]->d_name);
@@ -319,18 +331,6 @@ static int legacy_list(struct nvme_topology *t)
                while (j--)
                        free(namespaces[j]);
                free(namespaces);
-
-               ret = asprintf(&path, "%s%s", dev, c->name);
-               if (ret < 0)
-                       continue;
-               ret = 0;
-
-               fd = open(path, O_RDONLY);
-               if (fd > 0) {
-                       nvme_identify_ctrl(fd, &c->id);
-                       close(fd);
-               }
-               free(path);
        }
 
 free: