提交 5233e311 编写于 作者: A Al Viro

debugfs: split end_creating() into success and failure cases

... and don't bother with dput(dentry) in the former and with
dget(dentry) preceding all its calls.
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 edac65ea
...@@ -256,15 +256,17 @@ static struct dentry *start_creating(const char *name, struct dentry *parent) ...@@ -256,15 +256,17 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
return dentry; return dentry;
} }
static struct dentry *end_creating(struct dentry *dentry, int error) static struct dentry *failed_creating(struct dentry *dentry)
{ {
mutex_unlock(&dentry->d_parent->d_inode->i_mutex); mutex_unlock(&dentry->d_parent->d_inode->i_mutex);
dput(dentry); dput(dentry);
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
return NULL;
}
if (error) { static struct dentry *end_creating(struct dentry *dentry)
dentry = NULL; {
simple_release_fs(&debugfs_mount, &debugfs_mount_count); mutex_unlock(&dentry->d_parent->d_inode->i_mutex);
}
return dentry; return dentry;
} }
...@@ -311,15 +313,14 @@ struct dentry *debugfs_create_file(const char *name, umode_t mode, ...@@ -311,15 +313,14 @@ struct dentry *debugfs_create_file(const char *name, umode_t mode,
inode = debugfs_get_inode(dentry->d_sb); inode = debugfs_get_inode(dentry->d_sb);
if (unlikely(!inode)) if (unlikely(!inode))
return end_creating(dentry, -ENOMEM); return failed_creating(dentry);
inode->i_mode = mode; inode->i_mode = mode;
inode->i_fop = fops ? fops : &debugfs_file_operations; inode->i_fop = fops ? fops : &debugfs_file_operations;
inode->i_private = data; inode->i_private = data;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dget(dentry);
fsnotify_create(dentry->d_parent->d_inode, dentry); fsnotify_create(dentry->d_parent->d_inode, dentry);
return end_creating(dentry, 0); return end_creating(dentry);
} }
EXPORT_SYMBOL_GPL(debugfs_create_file); EXPORT_SYMBOL_GPL(debugfs_create_file);
...@@ -351,7 +352,7 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) ...@@ -351,7 +352,7 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
inode = debugfs_get_inode(dentry->d_sb); inode = debugfs_get_inode(dentry->d_sb);
if (unlikely(!inode)) if (unlikely(!inode))
return end_creating(dentry, -ENOMEM); return failed_creating(dentry);
inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
inode->i_op = &simple_dir_inode_operations; inode->i_op = &simple_dir_inode_operations;
...@@ -360,10 +361,9 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) ...@@ -360,10 +361,9 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
/* directory inodes start off with i_nlink == 2 (for "." entry) */ /* directory inodes start off with i_nlink == 2 (for "." entry) */
inc_nlink(inode); inc_nlink(inode);
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dget(dentry);
inc_nlink(dentry->d_parent->d_inode); inc_nlink(dentry->d_parent->d_inode);
fsnotify_mkdir(dentry->d_parent->d_inode, dentry); fsnotify_mkdir(dentry->d_parent->d_inode, dentry);
return end_creating(dentry, 0); return end_creating(dentry);
} }
EXPORT_SYMBOL_GPL(debugfs_create_dir); EXPORT_SYMBOL_GPL(debugfs_create_dir);
...@@ -408,14 +408,13 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, ...@@ -408,14 +408,13 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
inode = debugfs_get_inode(dentry->d_sb); inode = debugfs_get_inode(dentry->d_sb);
if (unlikely(!inode)) { if (unlikely(!inode)) {
kfree(link); kfree(link);
return end_creating(dentry, -ENOMEM); return failed_creating(dentry);
} }
inode->i_mode = S_IFLNK | S_IRWXUGO; inode->i_mode = S_IFLNK | S_IRWXUGO;
inode->i_op = &debugfs_link_operations; inode->i_op = &debugfs_link_operations;
inode->i_private = link; inode->i_private = link;
d_instantiate(dentry, inode); d_instantiate(dentry, inode);
dget(dentry); return end_creating(dentry);
return end_creating(dentry, 0);
} }
EXPORT_SYMBOL_GPL(debugfs_create_symlink); EXPORT_SYMBOL_GPL(debugfs_create_symlink);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册