Skip to content

Commit 7b745a4

Browse files
author
Al Viro
committed
unfuck sysfs_mount()
new_sb is left uninitialized in case of early failures in kernfs_mount_ns(), and while IS_ERR(root) is true in all such cases, using IS_ERR(root) || !new_sb is not a solution - IS_ERR(root) is true in some cases when new_sb is true. Make sure new_sb is initialized (and matches the reality) in all cases and fix the condition for dropping kobj reference - we want it done precisely in those situations where the reference has not been transferred into a new super_block instance. Signed-off-by: Al Viro <[email protected]>
1 parent 82382ac commit 7b745a4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/sysfs/mount.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
2525
{
2626
struct dentry *root;
2727
void *ns;
28-
bool new_sb;
28+
bool new_sb = false;
2929

3030
if (!(flags & SB_KERNMOUNT)) {
3131
if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
@@ -35,9 +35,9 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
3535
ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
3636
root = kernfs_mount_ns(fs_type, flags, sysfs_root,
3737
SYSFS_MAGIC, &new_sb, ns);
38-
if (IS_ERR(root) || !new_sb)
38+
if (!new_sb)
3939
kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
40-
else if (new_sb)
40+
else if (!IS_ERR(root))
4141
root->d_sb->s_iflags |= SB_I_USERNS_VISIBLE;
4242

4343
return root;

0 commit comments

Comments
 (0)