Skip to contentSkip to conversation

nvme-cli: code cleanup, minor fixes

PATCH New Chaitanya Kulkarni 2 participants 7 messages Aug 20, 2018 NVMe

lore
Share & tools
lore
#0 lore raw

cover nvme-cli: code cleanup, minor fixes

This patch-series has minor fixes and code cleanups for nvme-cli.

Regards,
Chaitanya

Chaitanya Kulkarni (5):
nvme-cli: fix scaandir() return value
nvme-cli: remove always true condition for u8
nvme-cli: code cleanup for passthru() handlers
nvme-cli: don't use unsigned for fd in lnvm-nvme.c
nvme-cli: fix dead-code nvmf log page discovery

 fabrics.c   |  2 +-
 lnvm-nvme.c |  3 ++-
 nvme.c      | 14 ++++++++------
 3 files changed, 11 insertions(+), 8 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

PATCH 1/5 nvme-cli: fix scaandir() return value

Don't use unsigned int for scandir() return value as it can return -1.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 nvme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
nvme.c +2 -2
index 99640cb..a893366 100644
@@ -1618,8 +1618,8 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
 	char path[264];
 	struct dirent **devices;
 	struct list_item *list_items;
-	unsigned int i, n, list_cnt = 0;
-	int fmt, ret, fd;
+	unsigned int list_cnt = 0;
+	int fmt, ret, fd, i, n;
 	const char *desc = "Retrieve basic information for the given device";
 	struct config {
 		char *output_format;
Signature · 1 line
2.14.1
#2 lore raw

PATCH 2/5 nvme-cli: remove always true condition for u8

In reply to Chaitanya Kulkarni

Get rid of the always true condition of (cfg.owpass >= 0) since cfg.owpass is defined as __u8.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
nvme.c +1 -1
index a893366..4233d9c 100644
@@ -2585,7 +2585,7 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *p
 	}
 
 	if (cfg.sanact == NVME_SANITIZE_ACT_OVERWRITE) {
-		if (!(cfg.owpass >= 0 && cfg.owpass <= 16)) {
+		if (cfg.owpass > 16) {
 			fprintf(stderr, "OWPASS out of range [0-16]\n");
 			ret = EINVAL;
 			goto close_fd;
Signature · 1 line
2.14.1
#3 lore raw

PATCH 3/5 nvme-cli: code cleanup for passthru() handlers

In reply to Chaitanya Kulkarni

Get rid of the duplicate free of the metadata pointer in case memory allocation fails for the data pointer.

Close wfd file in case of any resource allocation failure if applicable.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 nvme.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
nvme.c +5 -3
index 4233d9c..f149bab 100644
@@ -4451,13 +4451,11 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
 		if (!metadata) {
 			fprintf(stderr, "can not allocate metadata payload\n");
 			err = ENOMEM;
-			goto close_fd;
+			goto close_wfd;
 		}
 	}
 	if (cfg.data_len) {
 		if (posix_memalign(&data, getpagesize(), cfg.data_len)) {
-			if (metadata)
-				free(metadata);
 			fprintf(stderr, "can not allocate data payload\n");
 			err = ENOMEM;
 			goto free_metadata;
@@ -4524,6 +4522,10 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
  free_metadata:
 	if (cfg.metadata_len)
 		free(metadata);
+
+ close_wfd:
+	if (strlen(cfg.input_file))
+		close(wfd);
  close_fd:
 	close(fd);
 	return err;
Signature · 1 line
2.14.1
#4 lore raw

PATCH 4/5 nvme-cli: don't use unsigned for fd in lnvm-nvme.c

In reply to Chaitanya Kulkarni

Change the data type of the fd from unsigned int -> int.

Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 lnvm-nvme.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lnvm-nvme.c +2 -1
index 5130919..754931a 100644
@@ -95,7 +95,8 @@ static int lnvm_id_ns(int argc, char **argv, struct command *cmd, struct plugin
 	const char *raw_binary = "show infos in binary format";
 	const char *human_readable = "show infos in readable format";
 	const char *namespace_id = "identifier of desired namespace. default: 1";
-	unsigned int fd, flags = 0;
+	unsigned int flags = 0;
+	int fd;
 
 	struct config {
 		__u32 namespace_id;
Signature · 1 line
2.14.1
#5 lore raw

PATCH 5/5 nvme-cli: fix dead-code nvmf log page discovery

In reply to Chaitanya Kulkarni
Signed-off-by Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
 fabrics.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fabrics.c +1 -1
index 9bf2594..514082e 100644
@@ -353,9 +353,9 @@ static int nvmf_get_log_page_discovery(const char *dev_path,
 
 	/* needs to be freed by the caller */
 	*logp = log;
+	error = DISC_OK;
 	goto out_close;
 
-	error = DISC_OK;
 out_free_log:
 	free(log);
 out_close:
Signature · 1 line
2.14.1
#6 lore raw

cover nvme-cli: code cleanup, minor fixes

In reply to Chaitanya Kulkarni
Quoted 1 line · Chaitanya Kulkarni

This patch-series has minor fixes and code cleanups for nvme-cli.

Thanks, all of your patches have been applied.