Skip to content

Commit 17e7016

Browse files
committed
fs: simplify error handling
Rely on cleanup helper and simplify error handling Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent cb54ef4 commit 17e7016

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

fs/namespace.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5050,7 +5050,7 @@ static struct mount *listmnt_next(struct mount *curr)
50505050
static ssize_t do_listmount(u64 mnt_parent_id, u64 last_mnt_id, u64 *mnt_ids,
50515051
size_t nr_mnt_ids)
50525052
{
5053-
struct path root;
5053+
struct path root __free(path_put) = {};
50545054
struct mnt_namespace *ns = current->nsproxy->mnt_ns;
50555055
struct path orig;
50565056
struct mount *r, *first;
@@ -5063,10 +5063,8 @@ static ssize_t do_listmount(u64 mnt_parent_id, u64 last_mnt_id, u64 *mnt_ids,
50635063
orig = root;
50645064
} else {
50655065
orig.mnt = lookup_mnt_in_ns(mnt_parent_id, ns);
5066-
if (!orig.mnt) {
5067-
ret = -ENOENT;
5068-
goto err;
5069-
}
5066+
if (!orig.mnt)
5067+
return -ENOENT;
50705068
orig.dentry = orig.mnt->mnt_root;
50715069
}
50725070

@@ -5075,14 +5073,12 @@ static ssize_t do_listmount(u64 mnt_parent_id, u64 last_mnt_id, u64 *mnt_ids,
50755073
* mounts to show users.
50765074
*/
50775075
if (!is_path_reachable(real_mount(orig.mnt), orig.dentry, &root) &&
5078-
!ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN)) {
5079-
ret = -EPERM;
5080-
goto err;
5081-
}
5076+
!ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN))
5077+
return -EPERM;
50825078

50835079
ret = security_sb_statfs(orig.dentry);
50845080
if (ret)
5085-
goto err;
5081+
return ret;
50865082

50875083
if (!last_mnt_id)
50885084
first = node_to_mount(rb_first(&ns->mounts));
@@ -5099,8 +5095,6 @@ static ssize_t do_listmount(u64 mnt_parent_id, u64 last_mnt_id, u64 *mnt_ids,
50995095
nr_mnt_ids--;
51005096
ret++;
51015097
}
5102-
err:
5103-
path_put(&root);
51045098
return ret;
51055099
}
51065100

0 commit comments

Comments
 (0)