From: mwilck@suse.com Subject: [PATCH v2 81/84] multipath: check_path_valid(): eliminate some failure modes Date: Wed, 12 Aug 2020 13:35:58 +0200 Message-ID: <20200812113601.26658-2-mwilck@suse.com> References: <20200812113601.26658-1-mwilck@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20200812113601.26658-1-mwilck@suse.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Christophe Varoqui , Benjamin Marzinski Cc: dm-devel@redhat.com, Martin Wilck List-Id: dm-devel.ids From: Martin Wilck 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 --- 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