Skip to content

Commit 5b83d2c

Browse files
Ram PaiLinus Torvalds
authored andcommitted
[PATCH] sanitize the interface of graft_tree().
Old semantics: graft_tree() grabs a reference on the vfsmount before returning success. New one: graft_tree() leaves that to caller. All the callers of graft_tree() immediately dropped that reference anyway. Changing the interface takes care of this unnecessary overhead. Idea proposed by Al Viro. Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b58fed8 commit 5b83d2c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/namespace.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
650650
attach_mnt(mnt, nd);
651651
list_add_tail(&head, &mnt->mnt_list);
652652
list_splice(&head, current->namespace->list.prev);
653-
mntget(mnt);
654653
err = 0;
655654
touch_namespace(current->namespace);
656655
}
@@ -702,8 +701,7 @@ static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
702701
spin_lock(&vfsmount_lock);
703702
umount_tree(mnt);
704703
spin_unlock(&vfsmount_lock);
705-
} else
706-
mntput(mnt);
704+
}
707705

708706
out:
709707
up_write(&current->namespace->sem);
@@ -857,15 +855,17 @@ int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
857855
goto unlock;
858856

859857
newmnt->mnt_flags = mnt_flags;
860-
newmnt->mnt_namespace = current->namespace;
861-
err = graft_tree(newmnt, nd);
858+
if ((err = graft_tree(newmnt, nd)))
859+
goto unlock;
862860

863-
if (err == 0 && fslist) {
861+
if (fslist) {
864862
/* add to the specified expiration list */
865863
spin_lock(&vfsmount_lock);
866864
list_add_tail(&newmnt->mnt_expire, fslist);
867865
spin_unlock(&vfsmount_lock);
868866
}
867+
up_write(&current->namespace->sem);
868+
return 0;
869869

870870
unlock:
871871
up_write(&current->namespace->sem);

0 commit comments

Comments
 (0)