Skip to content

Commit

Permalink
clean shmem_file_setup() a bit
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Feb 23, 2013
1 parent 39b6525 commit 6b4d0b2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2873,23 +2873,22 @@ EXPORT_SYMBOL_GPL(shmem_truncate_range);
*/
struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags)
{
int error;
struct file *file;
struct file *res;
struct inode *inode;
struct path path;
struct dentry *root;
struct qstr this;

if (IS_ERR(shm_mnt))
return (void *)shm_mnt;
return ERR_CAST(shm_mnt);

if (size < 0 || size > MAX_LFS_FILESIZE)
return ERR_PTR(-EINVAL);

if (shmem_acct_size(flags, size))
return ERR_PTR(-ENOMEM);

error = -ENOMEM;
res = ERR_PTR(-ENOMEM);
this.name = name;
this.len = strlen(name);
this.hash = 0; /* will go */
Expand All @@ -2899,7 +2898,7 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
goto put_memory;
path.mnt = mntget(shm_mnt);

error = -ENOSPC;
res = ERR_PTR(-ENOSPC);
inode = shmem_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0, flags);
if (!inode)
goto put_dentry;
Expand All @@ -2909,23 +2908,23 @@ struct file *shmem_file_setup(const char *name, loff_t size, unsigned long flags
clear_nlink(inode); /* It is unlinked */
#ifndef CONFIG_MMU
error = ramfs_nommu_expand_for_mapping(inode, size);
res = ERR_PTR(error);
if (error)
goto put_dentry;
#endif

file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
res = alloc_file(&path, FMODE_WRITE | FMODE_READ,
&shmem_file_operations);
error = PTR_ERR(file);
if (IS_ERR(file))
if (IS_ERR(res))
goto put_dentry;

return file;
return res;

put_dentry:
path_put(&path);
put_memory:
shmem_unacct_size(flags, size);
return ERR_PTR(error);
return res;
}
EXPORT_SYMBOL_GPL(shmem_file_setup);

Expand Down

0 comments on commit 6b4d0b2

Please sign in to comment.