]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: Return negative errno to check remove_ctrl() is failed
authorMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 3 Apr 2019 15:02:05 +0000 (00:02 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Wed, 3 Apr 2019 15:02:05 +0000 (00:02 +0900)
remove_ctrl() might fail due to a reason such as memory allocation
failure.  Once it fails, discovery should not proceed, but return the
errorno to the caller immediately.

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

index 96f740b61de8fc61de63c1cc9ee532a006cfedb8..1a9a3fbc994fe98a1c0169c1477c60d3adeb4c05 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -251,14 +251,14 @@ static int remove_ctrl_by_path(char *sysfs_path)
 
        fd = open(sysfs_path, O_WRONLY);
        if (fd < 0) {
-               ret = errno;
+               ret = -errno;
                fprintf(stderr, "Failed to open %s: %s\n", sysfs_path,
                                strerror(errno));
                goto out;
        }
 
        if (write(fd, "1", 1) != 1) {
-               ret = errno;
+               ret = -errno;
                goto out_close;
        }
 
@@ -276,7 +276,7 @@ static int remove_ctrl(int instance)
 
        if (asprintf(&sysfs_path, "/sys/class/nvme/nvme%d/delete_controller",
                        instance) < 0) {
-               ret = errno;
+               ret = -errno;
                goto out;
        }
 
@@ -845,7 +845,7 @@ static int do_discover(char *argstr, bool connect)
 {
        struct nvmf_disc_rsp_page_hdr *log = NULL;
        char *dev_name;
-       int instance, numrec = 0, ret;
+       int instance, numrec = 0, ret, err;
 
        instance = add_ctrl(argstr);
        if (instance < 0)
@@ -855,7 +855,9 @@ static int do_discover(char *argstr, bool connect)
                return -errno;
        ret = nvmf_get_log_page_discovery(dev_name, &log, &numrec);
        free(dev_name);
-       remove_ctrl(instance);
+       err = remove_ctrl(instance);
+       if (err)
+               return err;
 
        switch (ret) {
        case DISC_OK: