Skip to contentSkip to conversation

nvme-cli: make return negative value in nvme_get_nsid() when not blkdev

PATCH New Minwoo Im 1 participant 1 message Jan 26, 2018 NVMe

lore
Share & tools
lore

Minwoo Im

author
#0 lore raw

PATCH 1/1 nvme-cli: make return negative value in nvme_get_nsid() when not blkdev

If caller invokes get_nsid() with character device without checking whether a given device is block device or not, ENOTBLK is returned from nvme_get_nsid() which is a positive value, so that caller may treat this value as a valid nsid.

Make it return a negative vaelue with -ENOTBLK and add error checking to callers.

Signed-off-by Minwoo Im <minwoo.im.dev at gmail.com>
---
 nvme-ioctl.c |  2 +-
 nvme.c       | 54 +++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 44 insertions(+), 12 deletions(-)
nvme-ioctl.c +1 -1
index 6fdb636..180abe2 100644
@@ -79,7 +79,7 @@ int nvme_get_nsid(int fd)
 	if (!S_ISBLK(nvme_stat.st_mode)) {
 		fprintf(stderr,
 			"Error: requesting namespace-id from non-block device\n");
-		return ENOTBLK;
+		return -ENOTBLK;
 	}
 	return ioctl(fd, NVME_IOCTL_ID);
 }
nvme.c +43 -11

137 lines not on this page · raw message

Signature · 1 line
2.7.4