[dm-devel] [PATCH v2 81/84] multipath: check_path_valid(): eliminate some failure modes

mwilck at suse.com mwilck at suse.com
Wed Aug 12 11:35:58 UTC 2020


From: Martin Wilck <mwilck at suse.com>

The memory allocations can fail, and pathvec is not needed until the
path_discovery() call. Eliminate the failure modes by not setting up
pathvec before it's actually needed.

Signed-off-by: Martin Wilck <mwilck at suse.com>
---
 multipath/main.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/multipath/main.c b/multipath/main.c
index 9d6b482..9e65070 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -637,15 +637,6 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
 			 minor(devt));
 	}
 
-	pathvec = vector_alloc();
-	if (!pathvec)
-		goto fail;
-
-	if (store_path(pathvec, pp) != 0) {
-		free_path(pp);
-		goto fail;
-	}
-
 	if ((r == PATH_IS_VALID || r == PATH_IS_MAYBE_VALID) &&
 	    released_to_systemd())
 		r = PATH_IS_NOT_VALID;
@@ -684,6 +675,15 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
 		goto out;
 	}
 
+	pathvec = vector_alloc();
+	if (!pathvec)
+		goto fail;
+
+	if (store_path(pathvec, pp) != 0) {
+		free_path(pp);
+		goto fail;
+	}
+
 	/* For find_multipaths = SMART, if there is more than one path
 	 * matching the refwwid, then the path is valid */
 	if (path_discovery(pathvec, DI_SYSFS | DI_WWID) < 0)
-- 
2.28.0





More information about the dm-devel mailing list