Skip to content

Commit

Permalink
nvme: avoid unnecessary dup() + close() in io_mgmt_send()
Browse files Browse the repository at this point in the history
_cleanup_fd_ doesn't close STD{IN,OUT,ERR}_FILENO,
so don't bother creating a duplicate fd.

Signed-off-by: Caleb Sander Mateos <[email protected]>
Fixes: 7e1f679 ("nvme: use cleanup helper to close file descriptor")
  • Loading branch information
calebsander authored and igaw committed Jul 17, 2024
1 parent 4e61659 commit 03006b9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 03006b9

Please sign in to comment.