Skip to content

Commit 1e858be

Browse files
committed
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 <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 62751f5 commit 1e858be

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

nvme-topology.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int verify_legacy_ns(struct nvme_namespace *n)
263263
return ret;
264264

265265
if (memcmp(id.mn, c->id.mn, sizeof(id.mn)) ||
266-
memcmp(id.sn, c->id.mn, sizeof(id.sn)))
266+
memcmp(id.sn, c->id.sn, sizeof(id.sn)))
267267
return -ENODEV;
268268
return 0;
269269
}
@@ -307,6 +307,18 @@ static int legacy_list(struct nvme_topology *t)
307307
alphasort);
308308
c->namespaces = calloc(c->nr_namespaces, sizeof(*n));
309309

310+
ret = asprintf(&path, "%s%s", dev, c->name);
311+
if (ret < 0)
312+
continue;
313+
ret = 0;
314+
315+
fd = open(path, O_RDONLY);
316+
if (fd > 0) {
317+
nvme_identify_ctrl(fd, &c->id);
318+
close(fd);
319+
}
320+
free(path);
321+
310322
for (j = 0; j < c->nr_namespaces; j++) {
311323
n = &c->namespaces[j];
312324
n->name = strdup(namespaces[j]->d_name);
@@ -319,18 +331,6 @@ static int legacy_list(struct nvme_topology *t)
319331
while (j--)
320332
free(namespaces[j]);
321333
free(namespaces);
322-
323-
ret = asprintf(&path, "%s%s", dev, c->name);
324-
if (ret < 0)
325-
continue;
326-
ret = 0;
327-
328-
fd = open(path, O_RDONLY);
329-
if (fd > 0) {
330-
nvme_identify_ctrl(fd, &c->id);
331-
close(fd);
332-
}
333-
free(path);
334334
}
335335

336336
free:

0 commit comments

Comments
 (0)