DebugFS : more file/directory creation error handling

Correct dentry count to handle creation errors.

This patch puts a dput at the file creation instead of the file removal :
lookup_one_len already returns a dentry with reference count of 1. Then,
the dget() in simple_mknod increments it when the dentry is associated
with a file. In a scenario where simple_create or simple_mkdir returns
an error, this would lead to an unwanted increment of the reference
counter, therefore making file removal impossible.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Mathieu Desnoyers and committed by Greg Kroah-Hartman 65c33336 63223a06

+10 -4
+10 -4
fs/debugfs/inode.c
··· 162 error = debugfs_mkdir(parent->d_inode, *dentry, mode); 163 else 164 error = debugfs_create(parent->d_inode, *dentry, mode); 165 } else 166 error = PTR_ERR(*dentry); 167 mutex_unlock(&parent->d_inode->i_mutex); ··· 274 void debugfs_remove(struct dentry *dentry) 275 { 276 struct dentry *parent; 277 278 if (!dentry) 279 return; ··· 286 mutex_lock(&parent->d_inode->i_mutex); 287 if (debugfs_positive(dentry)) { 288 if (dentry->d_inode) { 289 - if (S_ISDIR(dentry->d_inode->i_mode)) 290 - simple_rmdir(parent->d_inode, dentry); 291 - else 292 simple_unlink(parent->d_inode, dentry); 293 - dput(dentry); 294 } 295 } 296 mutex_unlock(&parent->d_inode->i_mutex);
··· 162 error = debugfs_mkdir(parent->d_inode, *dentry, mode); 163 else 164 error = debugfs_create(parent->d_inode, *dentry, mode); 165 + dput(*dentry); 166 } else 167 error = PTR_ERR(*dentry); 168 mutex_unlock(&parent->d_inode->i_mutex); ··· 273 void debugfs_remove(struct dentry *dentry) 274 { 275 struct dentry *parent; 276 + int ret = 0; 277 278 if (!dentry) 279 return; ··· 284 mutex_lock(&parent->d_inode->i_mutex); 285 if (debugfs_positive(dentry)) { 286 if (dentry->d_inode) { 287 + if (S_ISDIR(dentry->d_inode->i_mode)) { 288 + ret = simple_rmdir(parent->d_inode, dentry); 289 + if (ret) 290 + printk(KERN_ERR 291 + "DebugFS rmdir on %s failed : " 292 + "directory not empty.\n", 293 + dentry->d_name.name); 294 + } else 295 simple_unlink(parent->d_inode, dentry); 296 } 297 } 298 mutex_unlock(&parent->d_inode->i_mutex);