aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/capi
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@web.de>2010-02-08 05:12:05 -0500
committerDavid S. Miller <davem@davemloft.net>2010-02-16 19:01:17 -0500
commitc947862f9126983537a4cc11e07d26882d60b7e7 (patch)
tree335ae3483ea540877ff5230c3f43288847300417 /drivers/isdn/capi
parent54716e3beb0ab20c49471348dfe399a71bfc8fd3 (diff)
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: Jan Kiszka <jan.kiszka@web.de> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/isdn/capi')
-rw-r--r--drivers/isdn/capi/capifs.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/drivers/isdn/capi/capifs.c b/drivers/isdn/capi/capifs.c
index 9f8f67b6c07f..dc68fcb122a0 100644
--- a/drivers/isdn/capi/capifs.c
+++ b/drivers/isdn/capi/capifs.c
@@ -152,22 +152,33 @@ static struct dentry *get_node(int num)
152void capifs_new_ncci(unsigned int number, dev_t device) 152void capifs_new_ncci(unsigned int number, dev_t device)
153{ 153{
154 struct dentry *dentry; 154 struct dentry *dentry;
155 struct inode *inode = new_inode(capifs_mnt->mnt_sb); 155 struct inode *inode;
156 if (!inode)
157 return;
158 inode->i_ino = number+2;
159 156
160 dentry = get_node(number); 157 dentry = get_node(number);
158 if (IS_ERR(dentry))
159 goto unlock_out;
160
161 if (dentry->d_inode) {
162 dput(dentry);
163 goto unlock_out;
164 }
165
166 inode = new_inode(capifs_mnt->mnt_sb);
167 if (!inode) {
168 dput(dentry);
169 goto unlock_out;
170 }
161 171
162 /* config contents is protected by root's i_mutex */ 172 /* config contents is protected by root's i_mutex */
163 inode->i_uid = config.setuid ? config.uid : current_fsuid(); 173 inode->i_uid = config.setuid ? config.uid : current_fsuid();
164 inode->i_gid = config.setgid ? config.gid : current_fsgid(); 174 inode->i_gid = config.setgid ? config.gid : current_fsgid();
165 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 175 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
176 inode->i_ino = number + 2;
166 init_special_inode(inode, S_IFCHR|config.mode, device); 177 init_special_inode(inode, S_IFCHR|config.mode, device);
167 //inode->i_op = &capifs_file_inode_operations;
168 178
169 if (!IS_ERR(dentry) && !dentry->d_inode) 179 d_instantiate(dentry, inode);
170 d_instantiate(dentry, inode); 180
181unlock_out:
171 mutex_unlock(&capifs_root->d_inode->i_mutex); 182 mutex_unlock(&capifs_root->d_inode->i_mutex);
172} 183}
173 184