From: Daniel Wagner Date: Thu, 4 Jul 2024 16:43:54 +0000 (+0200) Subject: nvme: use cleanup helper to close file descriptor X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=7e1f6799f8cd61b474fa12fa3b1de529e063b39c;p=users%2Fsagi%2Fnvme-cli.git nvme: use cleanup helper to close file descriptor io_mgmt_send uses a file descriptor. Let's use the cleanup helper to close it. Signed-off-by: Daniel Wagner --- diff --git a/nvme.c b/nvme.c index 0c18f4e1..17d3fac6 100644 --- a/nvme.c +++ b/nvme.c @@ -2096,7 +2096,7 @@ static int io_mgmt_send(int argc, char **argv, struct command *cmd, struct plugi _cleanup_nvme_dev_ struct nvme_dev *dev = NULL; _cleanup_free_ void *buf = NULL; int err = -1; - int dfd = STDIN_FILENO; + _cleanup_fd_ int dfd = -1; struct config { __u16 mos; @@ -2141,12 +2141,13 @@ static int io_mgmt_send(int argc, char **argv, struct command *cmd, struct plugi nvme_show_perror(cfg.file); return -errno; } - } + } else + dfd = dup(STDIN_FILENO); err = read(dfd, buf, cfg.data_len); if (err < 0) { nvme_show_perror("read"); - goto close_fd; + return err; } struct nvme_io_mgmt_send_args args = { @@ -2169,9 +2170,6 @@ static int io_mgmt_send(int argc, char **argv, struct command *cmd, struct plugi else nvme_show_perror("io-mgmt-send"); -close_fd: - if (cfg.file) - close(dfd); return err; }