Commit c947862f authored by Jan Kiszka's avatar Jan Kiszka Committed by David S. Miller

CAPI: Fix leaks in capifs_new_ncci

When something went wrong during capifs_new_ncci, the looked up dentry
was not properly released. Neither was the allocated inode. Refactor the
function to avoid leaks.
Signed-off-by: default avatarJan Kiszka <jan.kiszka@web.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 54716e3b
...@@ -152,22 +152,33 @@ static struct dentry *get_node(int num) ...@@ -152,22 +152,33 @@ static struct dentry *get_node(int num)
void capifs_new_ncci(unsigned int number, dev_t device) void capifs_new_ncci(unsigned int number, dev_t device)
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode = new_inode(capifs_mnt->mnt_sb); struct inode *inode;
if (!inode)
return;
inode->i_ino = number+2;
dentry = get_node(number); dentry = get_node(number);
if (IS_ERR(dentry))
goto unlock_out;
if (dentry->d_inode) {
dput(dentry);
goto unlock_out;
}
inode = new_inode(capifs_mnt->mnt_sb);
if (!inode) {
dput(dentry);
goto unlock_out;
}
/* config contents is protected by root's i_mutex */ /* config contents is protected by root's i_mutex */
inode->i_uid = config.setuid ? config.uid : current_fsuid(); inode->i_uid = config.setuid ? config.uid : current_fsuid();
inode->i_gid = config.setgid ? config.gid : current_fsgid(); inode->i_gid = config.setgid ? config.gid : current_fsgid();
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_ino = number + 2;
init_special_inode(inode, S_IFCHR|config.mode, device); init_special_inode(inode, S_IFCHR|config.mode, device);
//inode->i_op = &capifs_file_inode_operations;
if (!IS_ERR(dentry) && !dentry->d_inode) d_instantiate(dentry, inode);
d_instantiate(dentry, inode);
unlock_out:
mutex_unlock(&capifs_root->d_inode->i_mutex); mutex_unlock(&capifs_root->d_inode->i_mutex);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment