mm: tiny-shmem fix lock ordering: mmap_sem vs i_mutex
tiny-shmem calls do_truncate in shmem_file_setup. do_truncate takes i_mutex, and shmem_file_setup is called with mmap_sem held. However i_mutex nests outside mmap_sem. Copy the code in shmem.c to avoid this problem. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Nick Piggin <npiggin@suse.de> Reported-and-tested-by: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Matt Mackall <mpm@selenic.com> Cc: Hugh Dickins <hugh@veritas.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
2d4c826677
commit
db203d53d4
1 changed files with 9 additions and 15 deletions
|
@ -65,31 +65,25 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
|
||||||
if (!dentry)
|
if (!dentry)
|
||||||
goto put_memory;
|
goto put_memory;
|
||||||
|
|
||||||
error = -ENOSPC;
|
|
||||||
inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
|
|
||||||
if (!inode)
|
|
||||||
goto put_dentry;
|
|
||||||
|
|
||||||
d_instantiate(dentry, inode);
|
|
||||||
error = -ENFILE;
|
error = -ENFILE;
|
||||||
file = alloc_file(shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
|
file = get_empty_filp();
|
||||||
&ramfs_file_operations);
|
|
||||||
if (!file)
|
if (!file)
|
||||||
goto put_dentry;
|
goto put_dentry;
|
||||||
|
|
||||||
inode->i_nlink = 0; /* It is unlinked */
|
error = -ENOSPC;
|
||||||
|
inode = ramfs_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0);
|
||||||
/* notify everyone as to the change of file size */
|
if (!inode)
|
||||||
error = do_truncate(dentry, size, 0, file);
|
|
||||||
if (error < 0)
|
|
||||||
goto close_file;
|
goto close_file;
|
||||||
|
|
||||||
|
d_instantiate(dentry, inode);
|
||||||
|
inode->i_size = size;
|
||||||
|
inode->i_nlink = 0; /* It is unlinked */
|
||||||
|
init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ,
|
||||||
|
&ramfs_file_operations);
|
||||||
return file;
|
return file;
|
||||||
|
|
||||||
close_file:
|
close_file:
|
||||||
put_filp(file);
|
put_filp(file);
|
||||||
return ERR_PTR(error);
|
|
||||||
|
|
||||||
put_dentry:
|
put_dentry:
|
||||||
dput(dentry);
|
dput(dentry);
|
||||||
put_memory:
|
put_memory:
|
||||||
|
|
Loading…
Reference in a new issue