]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Correct checking if file descriptors are valid
authorMateusz Grzonka <mateusz.grzonka@intel.com>
Wed, 24 Nov 2021 10:48:33 +0000 (11:48 +0100)
committerJes Sorensen <jsorensen@fb.com>
Wed, 24 Nov 2021 12:07:12 +0000 (07:07 -0500)
In some cases file descriptors equal to 0 are treated as invalid.
Fix it.

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Assemble.c
Grow.c
Incremental.c
mdadm.c
super-ddf.c

index 20fd97b5980ded4db0997c7d9c95b8e012b00217..704b8293c07fecbe491f08cbff037096e6a12eb5 100644 (file)
@@ -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 70f26c7e41145df252b990d0348d256b6ff7205a..9c6fc95e42193cdc3aad870b76d1d9f4c29a68f1 100644 (file)
--- 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);
index 9cdd31f02d2e6d6703f8bb133601a4726fbdd42d..a57fc3235f0b5c3a00f67a3f02f0dc15525c1ae2 100644 (file)
@@ -1702,8 +1702,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 a31ab99c0c2f23753c43cf1aef5622eea3d57d77..91e67467edc45eb4c21035ad313bf99f8f51c3a0 100644 (file)
--- 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);
 }
 
index d334a79ddcb446ed34e5f2e98b3ba78234588a9f..3f304cdcb90e4e0ef56940909772c3560f360ca9 100644 (file)
@@ -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;