Allocating a file structure in function get_empty_filp() might fail because
of several reasons:
- not enough memory for file structures
- operation is not allowed
- user is over its limit
Currently the function returns NULL in all cases and we loose the exact
reason of the error. All callers of get_empty_filp() assume that the function
can fail with ENFILE only.
Return error through pointer. Change all callers to preserve this error code.
[AV: cleaned up a bit, carved the get_empty_filp() part out into a separate commit
(things remaining here deal with alloc_file()), removed pipe(2) behaviour change]
Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com>
Reviewed-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
d_add(path.dentry, inode);
file = alloc_file(&path, FMODE_READ, &pfm_file_ops);
d_add(path.dentry, inode);
file = alloc_file(&path, FMODE_READ, &pfm_file_ops);
- return ERR_PTR(-ENFILE);
}
file->f_flags = O_RDONLY;
}
file->f_flags = O_RDONLY;
struct qstr this;
struct path path;
struct file *file;
struct qstr this;
struct path path;
struct file *file;
if (IS_ERR(anon_inode_inode))
return ERR_PTR(-ENODEV);
if (IS_ERR(anon_inode_inode))
return ERR_PTR(-ENODEV);
* Link the inode to a directory entry by creating a unique name
* using the inode sequence number.
*/
* Link the inode to a directory entry by creating a unique name
* using the inode sequence number.
*/
+ file = ERR_PTR(-ENOMEM);
this.name = name;
this.len = strlen(name);
this.hash = 0;
this.name = name;
this.len = strlen(name);
this.hash = 0;
d_instantiate(path.dentry, anon_inode_inode);
d_instantiate(path.dentry, anon_inode_inode);
file = alloc_file(&path, OPEN_FMODE(flags), fops);
file = alloc_file(&path, OPEN_FMODE(flags), fops);
goto err_dput;
file->f_mapping = anon_inode_inode->i_mapping;
goto err_dput;
file->f_mapping = anon_inode_inode->i_mapping;
path_put(&path);
err_module:
module_put(fops->owner);
path_put(&path);
err_module:
module_put(fops->owner);
}
EXPORT_SYMBOL_GPL(anon_inode_getfile);
}
EXPORT_SYMBOL_GPL(anon_inode_getfile);
file = get_empty_filp();
if (IS_ERR(file))
file = get_empty_filp();
if (IS_ERR(file))
file->f_path = *path;
file->f_mapping = path->dentry->d_inode->i_mapping;
file->f_path = *path;
file->f_mapping = path->dentry->d_inode->i_mapping;
struct user_struct **user,
int creat_flags, int page_size_log)
{
struct user_struct **user,
int creat_flags, int page_size_log)
{
- int error = -ENOMEM;
- struct file *file;
+ struct file *file = ERR_PTR(-ENOMEM);
struct inode *inode;
struct path path;
struct dentry *root;
struct inode *inode;
struct path path;
struct dentry *root;
goto out_shm_unlock;
path.mnt = mntget(hugetlbfs_vfsmount[hstate_idx]);
goto out_shm_unlock;
path.mnt = mntget(hugetlbfs_vfsmount[hstate_idx]);
+ file = ERR_PTR(-ENOSPC);
inode = hugetlbfs_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0);
if (!inode)
goto out_dentry;
inode = hugetlbfs_get_inode(root->d_sb, NULL, S_IFREG | S_IRWXUGO, 0);
if (!inode)
goto out_dentry;
size += addr & ~huge_page_mask(hstate);
num_pages = ALIGN(size, huge_page_size(hstate)) >>
huge_page_shift(hstate);
size += addr & ~huge_page_mask(hstate);
num_pages = ALIGN(size, huge_page_size(hstate)) >>
huge_page_shift(hstate);
+ file = ERR_PTR(-ENOMEM);
if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
goto out_inode;
if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
goto out_inode;
inode->i_size = size;
clear_nlink(inode);
inode->i_size = size;
clear_nlink(inode);
file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
&hugetlbfs_file_operations);
file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
&hugetlbfs_file_operations);
goto out_dentry; /* inode is already attached */
return file;
goto out_dentry; /* inode is already attached */
return file;
user_shm_unlock(size, *user);
*user = NULL;
}
user_shm_unlock(size, *user);
*user = NULL;
}
}
static int __init init_hugetlbfs_fs(void)
}
static int __init init_hugetlbfs_fs(void)
err = -ENFILE;
f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops);
err = -ENFILE;
f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops);
goto err_dentry;
f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));
res[0] = alloc_file(&path, FMODE_READ, &read_pipefifo_fops);
goto err_dentry;
f->f_flags = O_WRONLY | (flags & (O_NONBLOCK | O_DIRECT));
res[0] = alloc_file(&path, FMODE_READ, &read_pipefifo_fops);
goto err_file;
path_get(&path);
goto err_file;
path_get(&path);
is_file_hugepages(shp->shm_file) ?
&shm_file_operations_huge :
&shm_file_operations);
is_file_hugepages(shp->shm_file) ?
&shm_file_operations_huge :
&shm_file_operations);
+ err = PTR_ERR(file);
+ if (IS_ERR(file))
goto out_free;
file->private_data = sfd;
goto out_free;
file->private_data = sfd;
file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
&shmem_file_operations);
file = alloc_file(&path, FMODE_WRITE | FMODE_READ,
&shmem_file_operations);
+ error = PTR_ERR(file);
+ if (IS_ERR(file))
goto put_dentry;
return file;
goto put_dentry;
return file;
file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
&socket_file_ops);
file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
&socket_file_ops);
+ if (unlikely(IS_ERR(file))) {
/* drop dentry, keep inode */
ihold(path.dentry->d_inode);
path_put(&path);
/* drop dentry, keep inode */
ihold(path.dentry->d_inode);
path_put(&path);
- return ERR_PTR(-ENFILE);