diff mbox series

[3/4] fs: simplify error handling

Message ID 20240607-vfs-listmount-reverse-v1-3-7877a2bfa5e5@kernel.org (mailing list archive)
State New
Headers show
Series fs: allow listmount() with reversed ordering | expand

Commit Message

Christian Brauner June 7, 2024, 2:55 p.m. UTC
Rely on cleanup helper and simplify error handling

Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/namespace.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/fs/namespace.c b/fs/namespace.c
index 72c6e884728b..507f310dbf33 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5083,10 +5083,11 @@  static ssize_t do_listmount(struct mount *first, struct path *orig,
 SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req, u64 __user *,
 		mnt_ids, size_t, nr_mnt_ids, unsigned int, flags)
 {
+	struct path root __free(path_put) = {};
 	struct mnt_namespace *ns = current->nsproxy->mnt_ns;
 	struct mnt_id_req kreq;
 	struct mount *first;
-	struct path root, orig;
+	struct path orig;
 	u64 mnt_parent_id, last_mnt_id;
 	const size_t maxcount = (size_t)-1 >> 3;
 	ssize_t ret;
@@ -5112,10 +5113,9 @@  SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req, u64 __user *,
 	if (mnt_parent_id == LSMT_ROOT) {
 		orig = root;
 	} else {
-		ret = -ENOENT;
 		orig.mnt = lookup_mnt_in_ns(mnt_parent_id, ns);
 		if (!orig.mnt)
-			goto err;
+			return -ENOENT;
 		orig.dentry = orig.mnt->mnt_root;
 	}
 	if (!last_mnt_id)
@@ -5123,10 +5123,7 @@  SYSCALL_DEFINE4(listmount, const struct mnt_id_req __user *, req, u64 __user *,
 	else
 		first = mnt_find_id_at(ns, last_mnt_id + 1);
 
-	ret = do_listmount(first, &orig, mnt_parent_id, mnt_ids, nr_mnt_ids, &root);
-err:
-	path_put(&root);
-	return ret;
+	return do_listmount(first, &orig, mnt_parent_id, mnt_ids, nr_mnt_ids, &root);
 }