if (!inode_owner_or_capable(inode))
                return -EACCES;
 
+       ret = mnt_want_write_file(file);
+       if (ret)
+               return ret;
+
        mutex_lock(&inode->i_mutex);
 
        ip_oldflags = ip->flags;
                }
        }
 
-       ret = mnt_want_write_file(file);
-       if (ret)
-               goto out_unlock;
-
        if (flags & FS_SYNC_FL)
                ip->flags |= BTRFS_INODE_SYNC;
        else
                inode->i_flags = i_oldflags;
        }
 
-       mnt_drop_write_file(file);
  out_unlock:
        mutex_unlock(&inode->i_mutex);
+       mnt_drop_write_file(file);
        return ret;
 }
 
        struct dentry *dentry;
        int error;
 
+       error = mnt_want_write(parent->mnt);
+       if (error)
+               return error;
+
        mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
 
        dentry = lookup_one_len(name, parent->dentry, namelen);
        if (dentry->d_inode)
                goto out_dput;
 
-       error = mnt_want_write(parent->mnt);
-       if (error)
-               goto out_dput;
-
        error = btrfs_may_create(dir, dentry);
        if (error)
-               goto out_drop_write;
+               goto out_dput;
 
        down_read(&BTRFS_I(dir)->root->fs_info->subvol_sem);
 
                fsnotify_mkdir(dir, dentry);
 out_up_read:
        up_read(&BTRFS_I(dir)->root->fs_info->subvol_sem);
-out_drop_write:
-       mnt_drop_write(parent->mnt);
 out_dput:
        dput(dentry);
 out_unlock:
        mutex_unlock(&dir->i_mutex);
+       mnt_drop_write(parent->mnt);
        return error;
 }