From: Minwoo Im Date: Wed, 3 Apr 2019 15:02:05 +0000 (+0900) Subject: fabrics: Return negative errno to check remove_ctrl() is failed X-Git-Tag: v1.8~10^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=6a0ed973b1671e7dd88273fc4fab5944efd0d96d;p=users%2Fsagi%2Fnvme-cli.git fabrics: Return negative errno to check remove_ctrl() is failed 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 --- diff --git a/fabrics.c b/fabrics.c index 96f740b6..1a9a3fbc 100644 --- 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: