From 31b3f02cbcada9be2a6b491372dd394794eef9b6 Mon Sep 17 00:00:00 2001 From: Martin George Date: Mon, 26 May 2025 21:59:29 +0530 Subject: [PATCH] nvme: update invalid device handling for list-subsys The list-subsys command fails to error out if one passes an invalid or non-existent ns device as part of the option. One would have ideally expected the nvme_match_device_filter() to catch this, but such cases would be better handled with a simple stat check for ns device validity before proceeding to the filter in the first place. That way, the stat check can take care of ns device validity whereas the filter can focus on filtering the subsystems and controllers, ignoring checking for invalid ns devices, as logically expected in a list subsystems command. Signed-off-by: Martin George --- nvme.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nvme.c b/nvme.c index 5992335418..c5b63b2a01 100644 --- a/nvme.c +++ b/nvme.c @@ -3460,6 +3460,14 @@ static int list_subsys(int argc, char **argv, struct command *cmd, if (devname) { int subsys_num; + struct stat st; + char path[512]; + + sprintf(path, "/dev/%s", devname); + if (stat(path, &st) != 0) { + nvme_show_error("%s does not exist", path); + return -EINVAL; + } if (sscanf(devname, "nvme%dn%d", &subsys_num, &nsid) != 2) { nvme_show_error("Invalid device name %s", devname);