[PATCH] fix up new filp allocators
Some new uses of get_empty_filp() have crept in; switched to alloc_file() to make sure that pieces of initialization won't be missing. We really need to kill get_empty_filp(). [AV] fixed dentry leak on failure exit in anon_inode_getfd() Cc: Erez Zadok <ezk@cs.sunysb.edu> Cc: Trond Myklebust <trond.myklebust@fys.uio.no> Cc: "J Bruce Fields" <bfields@fieldses.org> Acked-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
@ -81,13 +81,10 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
|
||||
|
||||
if (IS_ERR(anon_inode_inode))
|
||||
return -ENODEV;
|
||||
file = get_empty_filp();
|
||||
if (!file)
|
||||
return -ENFILE;
|
||||
|
||||
error = get_unused_fd();
|
||||
if (error < 0)
|
||||
goto err_put_filp;
|
||||
return error;
|
||||
fd = error;
|
||||
|
||||
/*
|
||||
@ -114,14 +111,15 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
|
||||
dentry->d_flags &= ~DCACHE_UNHASHED;
|
||||
d_instantiate(dentry, anon_inode_inode);
|
||||
|
||||
file->f_path.mnt = mntget(anon_inode_mnt);
|
||||
file->f_path.dentry = dentry;
|
||||
error = -ENFILE;
|
||||
file = alloc_file(anon_inode_mnt, dentry,
|
||||
FMODE_READ | FMODE_WRITE, fops);
|
||||
if (!file)
|
||||
goto err_dput;
|
||||
file->f_mapping = anon_inode_inode->i_mapping;
|
||||
|
||||
file->f_pos = 0;
|
||||
file->f_flags = O_RDWR;
|
||||
file->f_op = fops;
|
||||
file->f_mode = FMODE_READ | FMODE_WRITE;
|
||||
file->f_version = 0;
|
||||
file->private_data = priv;
|
||||
|
||||
@ -132,10 +130,10 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
|
||||
*pfile = file;
|
||||
return 0;
|
||||
|
||||
err_dput:
|
||||
dput(dentry);
|
||||
err_put_unused_fd:
|
||||
put_unused_fd(fd);
|
||||
err_put_filp:
|
||||
put_filp(file);
|
||||
return error;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(anon_inode_getfd);
|
||||
|
Reference in New Issue
Block a user