dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/examine-tidy-up-some-code.patch

2c1b57
From 36352fc95778677f0319f677ea079c49f7bbe9d0 Mon Sep 17 00:00:00 2001
2c1b57
From: NeilBrown <neilb@suse.com>
2c1b57
Date: Fri, 3 Mar 2017 10:57:00 +1100
2c1b57
Subject: [RHEL7.5 PATCH 006/169] examine: tidy up some code.
2c1b57
2c1b57
Michael Shigorin reports that the 'lcc' compiler isn't able
2c1b57
to deduce that 'st' must be initialized in
2c1b57
2c1b57
		if (c->SparcAdjust)
2c1b57
			st->ss->update_super(st, NULL, "sparc2.2",
2c1b57
2c1b57
just because the only times it isn't initialised, 'err' is set non-zero.
2c1b57
2c1b57
This results in a 'possibly uninitialised' warning.
2c1b57
While there is no bug in the code, this does suggest that maybe
2c1b57
the code could be made more obviously correct.
2c1b57
2c1b57
So this patch:
2c1b57
 1/ moves the "err" variable inside the for loop, so an error in
2c1b57
    one device doesn't stop the other devices from being processed
2c1b57
 2/ calls 'continue' early if the device cannot be opened, so that
2c1b57
    a level of indent can be removed, and so that it is clear that
2c1b57
    'st' is always initialised before being used
2c1b57
 3/ frees 'st' if an error occured in load_super or load_container.
2c1b57
2c1b57
Reported-by: Michael Shigorin <mike@altlinux.org>
2c1b57
Signed-off-by: NeilBrown <neilb@suse.com>
2c1b57
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
2c1b57
---
2c1b57
 Examine.c | 75 +++++++++++++++++++++++++++++++++------------------------------
2c1b57
 1 file changed, 39 insertions(+), 36 deletions(-)
2c1b57
2c1b57
diff --git a/Examine.c b/Examine.c
2c1b57
index 953b8ee..7013480 100644
2c1b57
--- a/Examine.c
2c1b57
+++ b/Examine.c
2c1b57
@@ -53,7 +53,6 @@ int Examine(struct mddev_dev *devlist,
2c1b57
 	 */
2c1b57
 	int fd;
2c1b57
 	int rv = 0;
2c1b57
-	int err = 0;
2c1b57
 
2c1b57
 	struct array {
2c1b57
 		struct supertype *st;
2c1b57
@@ -66,6 +65,8 @@ int Examine(struct mddev_dev *devlist,
2c1b57
 	for (; devlist ; devlist = devlist->next) {
2c1b57
 		struct supertype *st;
2c1b57
 		int have_container = 0;
2c1b57
+		int err = 0;
2c1b57
+		int container = 0;
2c1b57
 
2c1b57
 		fd = dev_open(devlist->devname, O_RDONLY);
2c1b57
 		if (fd < 0) {
2c1b57
@@ -74,44 +75,46 @@ int Examine(struct mddev_dev *devlist,
2c1b57
 				       devlist->devname, strerror(errno));
2c1b57
 				rv = 1;
2c1b57
 			}
2c1b57
-			err = 1;
2c1b57
+			continue;
2c1b57
 		}
2c1b57
-		else {
2c1b57
-			int container = 0;
2c1b57
-			if (forcest)
2c1b57
-				st = dup_super(forcest);
2c1b57
-			else if (must_be_container(fd)) {
2c1b57
-				/* might be a container */
2c1b57
-				st = super_by_fd(fd, NULL);
2c1b57
-				container = 1;
2c1b57
-			} else
2c1b57
-				st = guess_super(fd);
2c1b57
-			if (st) {
2c1b57
-				err = 1;
2c1b57
-				st->ignore_hw_compat = 1;
2c1b57
-				if (!container)
2c1b57
-					err = st->ss->load_super(st, fd,
2c1b57
-								 (c->brief||c->scan) ? NULL
2c1b57
-								 :devlist->devname);
2c1b57
-				if (err && st->ss->load_container) {
2c1b57
-					err = st->ss->load_container(st, fd,
2c1b57
-								 (c->brief||c->scan) ? NULL
2c1b57
-								 :devlist->devname);
2c1b57
-					if (!err)
2c1b57
-						have_container = 1;
2c1b57
-				}
2c1b57
-				st->ignore_hw_compat = 0;
2c1b57
-			} else {
2c1b57
-				if (!c->brief) {
2c1b57
-					pr_err("No md superblock detected on %s.\n", devlist->devname);
2c1b57
-					rv = 1;
2c1b57
-				}
2c1b57
-				err = 1;
2c1b57
+
2c1b57
+		if (forcest)
2c1b57
+			st = dup_super(forcest);
2c1b57
+		else if (must_be_container(fd)) {
2c1b57
+			/* might be a container */
2c1b57
+			st = super_by_fd(fd, NULL);
2c1b57
+			container = 1;
2c1b57
+		} else
2c1b57
+			st = guess_super(fd);
2c1b57
+		if (st) {
2c1b57
+			err = 1;
2c1b57
+			st->ignore_hw_compat = 1;
2c1b57
+			if (!container)
2c1b57
+				err = st->ss->load_super(st, fd,
2c1b57
+							 (c->brief||c->scan) ? NULL
2c1b57
+							 :devlist->devname);
2c1b57
+			if (err && st->ss->load_container) {
2c1b57
+				err = st->ss->load_container(st, fd,
2c1b57
+							     (c->brief||c->scan) ? NULL
2c1b57
+							     :devlist->devname);
2c1b57
+				if (!err)
2c1b57
+					have_container = 1;
2c1b57
 			}
2c1b57
-			close(fd);
2c1b57
+			st->ignore_hw_compat = 0;
2c1b57
+		} else {
2c1b57
+			if (!c->brief) {
2c1b57
+				pr_err("No md superblock detected on %s.\n", devlist->devname);
2c1b57
+				rv = 1;
2c1b57
+			}
2c1b57
+			err = 1;
2c1b57
 		}
2c1b57
-		if (err)
2c1b57
+		close(fd);
2c1b57
+
2c1b57
+		if (err) {
2c1b57
+			if (st)
2c1b57
+				st->ss->free_super(st);
2c1b57
 			continue;
2c1b57
+		}
2c1b57
 
2c1b57
 		if (c->SparcAdjust)
2c1b57
 			st->ss->update_super(st, NULL, "sparc2.2",
2c1b57
@@ -121,7 +124,7 @@ int Examine(struct mddev_dev *devlist,
2c1b57
 		if (c->brief && st->ss->brief_examine_super == NULL) {
2c1b57
 			if (!c->scan)
2c1b57
 				pr_err("No brief listing for %s on %s\n",
2c1b57
-					st->ss->name, devlist->devname);
2c1b57
+				       st->ss->name, devlist->devname);
2c1b57
 		} else if (c->brief) {
2c1b57
 			struct array *ap;
2c1b57
 			char *d;
2c1b57
-- 
2c1b57
2.7.4
2c1b57