move may_open() from __open_name_create() to do_last()
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 9 Mar 2011 05:17:27 +0000 (00:17 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 14 Mar 2011 13:15:26 +0000 (09:15 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namei.c

index 1f561dc495a1b9d4d19e87d0b6a25eaa4f715a39..def63e7c058dcc50cd4c72fa400536b71e72ebce 100644 (file)
@@ -2069,11 +2069,7 @@ out_unlock:
        mutex_unlock(&dir->d_inode->i_mutex);
        dput(nd->path.dentry);
        nd->path.dentry = path->dentry;
-
-       if (error)
-               return error;
-       /* Don't check for write permission, don't truncate */
-       return may_open(&nd->path, 0, open_flag & ~O_TRUNC);
+       return error;
 }
 
 /*
@@ -2239,6 +2235,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
                        mnt_drop_write(nd->path.mnt);
                        goto exit;
                }
+               /* Don't check for write permission, don't truncate */
+               error = may_open(&nd->path, 0, op->open_flag & ~O_TRUNC);
+               if (error) {
+                       mnt_drop_write(nd->path.mnt);
+                       goto exit;
+               }
                filp = nameidata_to_filp(nd);
                mnt_drop_write(nd->path.mnt);
                path_put(&nd->path);