From: Mateusz Grzonka <mateusz.grzonka@intel.com>
To: linux-raid@vger.kernel.org
Cc: jes@trained-monkey.org
Subject: [PATCH] Correct checking if file descriptors are valid
Date: Wed, 24 Nov 2021 11:48:33 +0100 [thread overview]
Message-ID: <20211124104833.27368-1-mateusz.grzonka@intel.com> (raw)
In some cases file descriptors equal to 0 are treated as invalid.
Fix it.
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
---
Assemble.c | 3 +--
Grow.c | 5 +----
Incremental.c | 4 ++--
mdadm.c | 3 +--
super-ddf.c | 2 +-
5 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/Assemble.c b/Assemble.c
index 20fd97b5..704b8293 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -569,8 +569,7 @@ static int select_devices(struct mddev_dev *devlist,
if (dfd < 0 ||
st->ss->load_super(st, dfd, NULL))
tmpdev->used = 2;
- if (dfd > 0)
- close(dfd);
+ close_fd(&dfd);
}
}
diff --git a/Grow.c b/Grow.c
index 70f26c7e..9c6fc95e 100644
--- a/Grow.c
+++ b/Grow.c
@@ -2334,10 +2334,7 @@ size_change_error:
* number of devices (On-Line Capacity Expansion) must be
* performed at the level of the container
*/
- if (fd > 0) {
- close(fd);
- fd = -1;
- }
+ close_fd(&fd);
rv = reshape_container(container, devname, -1, st, &info,
c->force, c->backup_file, c->verbose,
0, 0, 0);
diff --git a/Incremental.c b/Incremental.c
index cd9cc0fc..d28925d6 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -1701,8 +1701,8 @@ int IncrementalRemove(char *devname, char *id_path, int verbose)
return 1;
}
mdfd = open_dev_excl(ent->devnm);
- if (mdfd > 0) {
- close(mdfd);
+ if (is_fd_valid(mdfd)) {
+ close_fd(&mdfd);
if (sysfs_get_str(&mdi, NULL, "array_state",
buf, sizeof(buf)) > 0) {
if (strncmp(buf, "active", 6) == 0 ||
diff --git a/mdadm.c b/mdadm.c
index a31ab99c..91e67467 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -1770,8 +1770,7 @@ int main(int argc, char *argv[])
}
if (locked)
cluster_release_dlmlock();
- if (mdfd > 0)
- close(mdfd);
+ close_fd(&mdfd);
exit(rv);
}
diff --git a/super-ddf.c b/super-ddf.c
index d334a79d..3f304cdc 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -4914,7 +4914,7 @@ static int raid10_degraded(struct mdinfo *info)
pr_err("BUG: invalid raid disk\n");
goto out;
}
- if (d->state_fd > 0)
+ if (is_fd_valid(d->state_fd))
found[i]++;
}
ret = 2;
--
2.26.2
next reply other threads:[~2021-11-24 11:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 10:48 Mateusz Grzonka [this message]
2021-11-24 12:07 ` [PATCH] Correct checking if file descriptors are valid Jes Sorensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124104833.27368-1-mateusz.grzonka@intel.com \
--to=mateusz.grzonka@intel.com \
--cc=jes@trained-monkey.org \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox