Skip to content

Commit

Permalink
fat: Push mnt_want_write() outside of i_mutex
Browse files Browse the repository at this point in the history
When mnt_want_write() starts to handle freezing it will get a full lock
semantics requiring proper lock ordering. So push mnt_want_write() call
outside of i_mutex as in other places.

CC: OGAWA Hirofumi <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
jankara authored and Al Viro committed Jul 30, 2012
1 parent c30dabf commit e24f17d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions fs/fat/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
if (err)
goto out;

mutex_lock(&inode->i_mutex);
err = mnt_want_write_file(file);
if (err)
goto out_unlock_inode;
goto out;
mutex_lock(&inode->i_mutex);

/*
* ATTR_VOLUME and ATTR_DIR cannot be changed; this also
Expand All @@ -73,14 +73,14 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
/* The root directory has no attributes */
if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) {
err = -EINVAL;
goto out_drop_write;
goto out_unlock_inode;
}

if (sbi->options.sys_immutable &&
((attr | oldattr) & ATTR_SYS) &&
!capable(CAP_LINUX_IMMUTABLE)) {
err = -EPERM;
goto out_drop_write;
goto out_unlock_inode;
}

/*
Expand All @@ -90,12 +90,12 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
*/
err = security_inode_setattr(file->f_path.dentry, &ia);
if (err)
goto out_drop_write;
goto out_unlock_inode;

/* This MUST be done before doing anything irreversible... */
err = fat_setattr(file->f_path.dentry, &ia);
if (err)
goto out_drop_write;
goto out_unlock_inode;

fsnotify_change(file->f_path.dentry, ia.ia_valid);
if (sbi->options.sys_immutable) {
Expand All @@ -107,10 +107,9 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)

fat_save_attrs(inode, attr);
mark_inode_dirty(inode);
out_drop_write:
mnt_drop_write_file(file);
out_unlock_inode:
mutex_unlock(&inode->i_mutex);
mnt_drop_write_file(file);
out:
return err;
}
Expand Down

0 comments on commit e24f17d

Please sign in to comment.