]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-cli: code cleanup for passthru() handlers
authorChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Mon, 20 Aug 2018 00:36:05 +0000 (20:36 -0400)
committerKeith Busch <keith.busch@intel.com>
Mon, 20 Aug 2018 18:41:08 +0000 (12:41 -0600)
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@wdc.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index 029a5580d7ba79f9b49189e6df3cda6bf0e4f2cb..88e64af306377f9914abd29768e5bfe59b70c2bf 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -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;