]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
format: Do not return directly without freeing fd
authorMinwoo Im <minwoo.im.dev@gmail.com>
Thu, 25 Apr 2019 14:15:56 +0000 (23:15 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Sat, 27 Apr 2019 05:10:25 +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 f4c027bcbb21eb572802de4c859c77b9ee8b5013..c8be120d060687221d20e2ea9ca365a3ed6a9151 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -3176,14 +3176,16 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
        if (cfg.lbaf != 0xff && cfg.bs !=0) {
                fprintf(stderr,
                        "Invalid specification of both LBAF 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"), must be a power of two\n",
                                       (uint64_t) cfg.bs);
-                               return EINVAL;
+                       err = -EINVAL;
+                       goto close_fd;
                }
        }
        if (S_ISBLK(nvme_stat.st_mode)) {
@@ -3202,7 +3204,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                                fprintf(stderr, "identify failed\n");
                                show_nvme_status(err);
                        }
-                       return err;
+                       goto close_fd;
                }
                prev_lbaf = ns.flbas & 0xf;
 
@@ -3220,7 +3222,8 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                                        (uint64_t)cfg.bs, lbads);
                                fprintf(stderr,
                                        "Please correct block size, or specify LBAF directly\n");
-                               return EINVAL;
+                               err = -EINVAL;
+                               goto close_fd;
                        }
                } else  if (cfg.lbaf == 0xff)
                        cfg.lbaf = prev_lbaf;