@@ -2865,27 +2865,30 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
28652865 mutex_lock_nested (& nd .path .dentry -> d_inode -> i_mutex , I_MUTEX_PARENT );
28662866 dentry = lookup_hash (& nd );
28672867 if (IS_ERR (dentry ))
2868- goto fail ;
2868+ goto unlock ;
28692869
2870+ error = - EEXIST ;
28702871 if (dentry -> d_inode )
2871- goto eexist ;
2872+ goto fail ;
28722873 /*
28732874 * Special case - lookup gave negative, but... we had foo/bar/
28742875 * From the vfs_mknod() POV we just have a negative dentry -
28752876 * all is fine. Let's be bastards - you had / on the end, you've
28762877 * been asking for (non-existent) directory. -ENOENT for you.
28772878 */
28782879 if (unlikely (!is_dir && nd .last .name [nd .last .len ])) {
2879- dput (dentry );
2880- dentry = ERR_PTR (- ENOENT );
2880+ error = - ENOENT ;
28812881 goto fail ;
28822882 }
2883+ error = mnt_want_write (nd .path .mnt );
2884+ if (error )
2885+ goto fail ;
28832886 * path = nd .path ;
28842887 return dentry ;
2885- eexist :
2886- dput (dentry );
2887- dentry = ERR_PTR (- EEXIST );
28882888fail :
2889+ dput (dentry );
2890+ dentry = ERR_PTR (error );
2891+ unlock :
28892892 mutex_unlock (& nd .path .dentry -> d_inode -> i_mutex );
28902893out :
28912894 path_put (& nd .path );
@@ -2897,6 +2900,7 @@ void done_path_create(struct path *path, struct dentry *dentry)
28972900{
28982901 dput (dentry );
28992902 mutex_unlock (& path -> dentry -> d_inode -> i_mutex );
2903+ mnt_drop_write (path -> mnt );
29002904 path_put (path );
29012905}
29022906EXPORT_SYMBOL (done_path_create );
@@ -2974,12 +2978,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
29742978
29752979 if (!IS_POSIXACL (path .dentry -> d_inode ))
29762980 mode &= ~current_umask ();
2977- error = mnt_want_write (path .mnt );
2978- if (error )
2979- goto out_dput ;
29802981 error = security_path_mknod (& path , dentry , mode , dev );
29812982 if (error )
2982- goto out_drop_write ;
2983+ goto out ;
29832984 switch (mode & S_IFMT ) {
29842985 case 0 : case S_IFREG :
29852986 error = vfs_create (path .dentry -> d_inode ,dentry ,mode ,true);
@@ -2992,11 +2993,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
29922993 error = vfs_mknod (path .dentry -> d_inode ,dentry ,mode ,0 );
29932994 break ;
29942995 }
2995- out_drop_write :
2996- mnt_drop_write (path .mnt );
2997- out_dput :
2996+ out :
29982997 done_path_create (& path , dentry );
2999-
30002998 return error ;
30012999}
30023000
@@ -3042,16 +3040,9 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
30423040
30433041 if (!IS_POSIXACL (path .dentry -> d_inode ))
30443042 mode &= ~current_umask ();
3045- error = mnt_want_write (path .mnt );
3046- if (error )
3047- goto out_dput ;
30483043 error = security_path_mkdir (& path , dentry , mode );
3049- if (error )
3050- goto out_drop_write ;
3051- error = vfs_mkdir (path .dentry -> d_inode , dentry , mode );
3052- out_drop_write :
3053- mnt_drop_write (path .mnt );
3054- out_dput :
3044+ if (!error )
3045+ error = vfs_mkdir (path .dentry -> d_inode , dentry , mode );
30553046 done_path_create (& path , dentry );
30563047 return error ;
30573048}
@@ -3326,16 +3317,9 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
33263317 if (IS_ERR (dentry ))
33273318 goto out_putname ;
33283319
3329- error = mnt_want_write (path .mnt );
3330- if (error )
3331- goto out_dput ;
33323320 error = security_path_symlink (& path , dentry , from );
3333- if (error )
3334- goto out_drop_write ;
3335- error = vfs_symlink (path .dentry -> d_inode , dentry , from );
3336- out_drop_write :
3337- mnt_drop_write (path .mnt );
3338- out_dput :
3321+ if (!error )
3322+ error = vfs_symlink (path .dentry -> d_inode , dentry , from );
33393323 done_path_create (& path , dentry );
33403324out_putname :
33413325 putname (from );
@@ -3436,15 +3420,10 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
34363420 error = - EXDEV ;
34373421 if (old_path .mnt != new_path .mnt )
34383422 goto out_dput ;
3439- error = mnt_want_write (new_path .mnt );
3440- if (error )
3441- goto out_dput ;
34423423 error = security_path_link (old_path .dentry , & new_path , new_dentry );
34433424 if (error )
3444- goto out_drop_write ;
3425+ goto out_dput ;
34453426 error = vfs_link (old_path .dentry , new_path .dentry -> d_inode , new_dentry );
3446- out_drop_write :
3447- mnt_drop_write (new_path .mnt );
34483427out_dput :
34493428 done_path_create (& new_path , new_dentry );
34503429out :
0 commit comments