]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: avoid unnecessary dup() + close() in io_mgmt_send()
authorCaleb Sander Mateos <csander@purestorage.com>
Wed, 17 Jul 2024 02:04:04 +0000 (20:04 -0600)
committerDaniel Wagner <wagi@monom.org>
Wed, 17 Jul 2024 15:01:29 +0000 (17:01 +0200)
_cleanup_fd_ doesn't close STD{IN,OUT,ERR}_FILENO,
so don't bother creating a duplicate fd.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Fixes: 7e1f6799f8cd ("nvme: use cleanup helper to close file descriptor")
nvme.c

diff --git a/nvme.c b/nvme.c
index cb1de129739e8ecee6fa9b678c83f98e3aab6d39..4b0e2313b420e9cb50bd7d2db96384dd7e37f858 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2071,7 +2071,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;
-       _cleanup_fd_ int dfd = -1;
+       _cleanup_fd_ int dfd = STDIN_FILENO;
 
        struct config {
                __u16 mos;
@@ -2116,8 +2116,7 @@ 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) {