]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
create-ns: Do not return directly without freeing fd
authorMinwoo Im <minwoo.im.dev@gmail.com>
Thu, 25 Apr 2019 14:20:29 +0000 (23:20 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Sat, 27 Apr 2019 05:10:49 +0000 (14:10 +0900)
It was returning an error value without freeding open fd for the device.
This patch replaces 'return' with 'goto' to free fd.

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
nvme.c

diff --git a/nvme.c b/nvme.c
index c8be120d060687221d20e2ea9ca365a3ed6a9151..9f088a611d9b262f4980786c82dffb8668971a5d 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -1200,14 +1200,16 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        if (cfg.flbas != 0xff && cfg.bs != 0x00) {
                fprintf(stderr,
                        "Invalid specification of both FLBAS and Block Size, please specify only one\n");
-                       return EINVAL;
+               err = -EINVAL;
+               goto close_fd;
        }
        if (cfg.bs) {
                if ((cfg.bs & (~cfg.bs + 1)) != cfg.bs) {
                        fprintf(stderr,
                                "Invalid value for block size (%"PRIu64"). Block size must be a power of two\n",
                                (uint64_t)cfg.bs);
-                       return EINVAL;
+                       err = -EINVAL;
+                       goto close_fd;
                }
                err = nvme_identify_ns(fd, NVME_NSID_ALL, 0, &ns);
                if (err) {
@@ -1217,7 +1219,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                                fprintf(stderr, "identify failed\n");
                                show_nvme_status(err);
                        }
-                       return err;
+                       goto close_fd;
                }
                for (i = 0; i < 16; ++i) {
                        if ((1 << ns.lbaf[i].ds) == cfg.bs && ns.lbaf[i].ms == 0) {
@@ -1233,7 +1235,9 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                        (uint64_t)cfg.bs);
                fprintf(stderr,
                        "Please correct block size, or specify FLBAS directly\n");
-               return EINVAL;
+
+               err = -EINVAL;
+               goto close_fd;
        }
 
 
@@ -1246,6 +1250,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        else
                perror("create namespace");
 
+close_fd:
        close(fd);
 
        return err;