From: Keith Busch Date: Thu, 10 Oct 2019 19:35:56 +0000 (+0900) Subject: fix namespace checks for legacy list X-Git-Tag: v1.10~62 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1e858be6c25172f9946e4979ee724244bdd722b2;p=users%2Fhch%2Fnvme-cli.git fix namespace checks for legacy list 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 Signed-off-by: Keith Busch --- diff --git a/nvme-topology.c b/nvme-topology.c index 176619d..13ab52c 100644 --- a/nvme-topology.c +++ b/nvme-topology.c @@ -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: