From e1c0303727d0c31e1681f6747ed3e7e9859307dc Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sat, 24 Jan 2026 17:05:21 +0900 Subject: [PATCH 1/2] nvme: check chardev for resets and rescan Also change nvme_verify_chr() to return -EINVAL from -ENOTBLK. Signed-off-by: Tokunori Ikegami --- libnvme/src/nvme/ioctl.c | 2 +- nvme.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libnvme/src/nvme/ioctl.c b/libnvme/src/nvme/ioctl.c index ea21520f65..0ad051a359 100644 --- a/libnvme/src/nvme/ioctl.c +++ b/libnvme/src/nvme/ioctl.c @@ -38,7 +38,7 @@ static int nvme_verify_chr(struct nvme_transport_handle *hdl) return -errno; if (!S_ISCHR(nvme_stat.st_mode)) - return -ENOTBLK; + return -EINVAL; return 0; } diff --git a/nvme.c b/nvme.c index 4331db36a1..e0e76cec21 100644 --- a/nvme.c +++ b/nvme.c @@ -5349,6 +5349,11 @@ static int subsystem_reset(int argc, char **argv, struct command *acmd, struct p if (err) return err; + if (!nvme_transport_handle_is_chardev(hdl)) { + nvme_show_error("Only character device is allowed"); + return -EINVAL; + } + err = nvme_subsystem_reset(hdl); if (err < 0) { if (errno == ENOTTY) @@ -5375,6 +5380,11 @@ static int reset(int argc, char **argv, struct command *acmd, struct plugin *plu if (err) return err; + if (!nvme_transport_handle_is_chardev(hdl)) { + nvme_show_error("Only character device is allowed"); + return -EINVAL; + } + err = nvme_ctrl_reset(hdl); if (err < 0) nvme_show_error("Reset: %s", nvme_strerror(err)); @@ -5399,6 +5409,11 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin if (err) return err; + if (!nvme_transport_handle_is_chardev(hdl)) { + nvme_show_error("Only character device is allowed"); + return -EINVAL; + } + err = validate_output_format(nvme_cfg.output_format, &flags); if (err < 0) { nvme_show_error("Invalid output format"); From 7bb47ae16bf6237673e0da6e15d36492a6d7d677 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sat, 24 Jan 2026 20:47:10 +0900 Subject: [PATCH 2/2] nvme: Combine duplicated char dev error message string variables This change is for the maintainability. Signed-off-by: Tokunori Ikegami --- nvme.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nvme.c b/nvme.c index e0e76cec21..ac59f3d465 100644 --- a/nvme.c +++ b/nvme.c @@ -221,6 +221,7 @@ static const char *namespace_desired = "desired namespace"; static const char *namespace_id_desired = "identifier of desired namespace"; static const char *namespace_id_optional = "optional namespace attached to controller"; static const char *nssf = "NVMe Security Specific Field"; +static const char *only_char_dev = "Only character device is allowed"; static const char *prinfo = "PI and check field"; static const char *rae = "Retain an Asynchronous Event"; static const char *raw_directive = "show directive in binary format"; @@ -5350,7 +5351,7 @@ static int subsystem_reset(int argc, char **argv, struct command *acmd, struct p return err; if (!nvme_transport_handle_is_chardev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -5381,7 +5382,7 @@ static int reset(int argc, char **argv, struct command *acmd, struct plugin *plu return err; if (!nvme_transport_handle_is_chardev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -5410,7 +5411,7 @@ static int ns_rescan(int argc, char **argv, struct command *acmd, struct plugin return err; if (!nvme_transport_handle_is_chardev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -5755,7 +5756,7 @@ static int show_registers(int argc, char **argv, struct command *acmd, struct pl return err; if (nvme_transport_handle_is_blkdev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -6032,7 +6033,7 @@ static int get_register(int argc, char **argv, struct command *acmd, struct plug return err; if (nvme_transport_handle_is_blkdev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; } @@ -6336,7 +6337,7 @@ static int set_register(int argc, char **argv, struct command *acmd, struct plug return err; if (nvme_transport_handle_is_blkdev(hdl)) { - nvme_show_error("Only character device is allowed"); + nvme_show_error(only_char_dev); return -EINVAL; }