autofs-5.1.9 - refactor umount_subtree_mounts()

From: Ian Kent <raven@themaw.net>

This function has more checks than needed to do what it needs to do so
try and simplify it a bit.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG          |    1 +
 daemon/automount.c |   22 ++++++++++------------
 2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 39b8a0d71..6b39bcd22 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -62,6 +62,7 @@
 - move open close on exec functions to autofs library.
 - fix locking when setting master map reading.
 - eliminate master map parameter where possible.
+- refactor umount_subtree_mounts().
 
 02/11/2023 autofs-5.1.9
 - fix kernel mount status notification.
diff --git a/daemon/automount.c b/daemon/automount.c
index c48ec9831..e567daf82 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -556,7 +556,7 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
 	struct mapent *me;
 	unsigned int is_mm_root = 0;
 	int cur_state;
-	int left;
+	int left = 0;
 
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
 
@@ -572,17 +572,15 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
 	}
 
 	if (me) {
-		mc = me->mc;
-		is_mm_root = IS_MM_ROOT(me);
-	}
-
-	left = 0;
-
-	if (me && IS_MM(me)) {
 		char key[PATH_MAX + 1];
 		struct mapent *tmp;
 		int ret;
 
+		mc = me->mc;
+		is_mm_root = IS_MM_ROOT(me);
+		if (!IS_MM(me))
+			goto done;
+
 		ret = tree_mapent_umount_offsets(me);
 		if (!ret) {
 			warn(ap->logopt,
@@ -618,9 +616,9 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
 		if (ap->entry->maps &&
 		    (ap->entry->maps->flags & MAP_FLAG_FORMAT_AMD))
 			cache_pop_mapent(me);
-	}
-	if (me)
+done:
 		cache_unlock(mc);
+	}
 
 	pthread_setcancelstate(cur_state, NULL);
 
@@ -638,7 +636,7 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
 		if (umount_ent(ap, path)) {
 			warn(ap->logopt, "could not umount dir %s", path);
 			left++;
-			goto done;
+			return left;
 		}
 
 		/* Check for an external mount and umount if possible */
@@ -649,7 +647,7 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsi
 			mnts_put_mount(mnt);
 		}
 	}
-done:
+
 	return left;
 }
 
