diff options
Diffstat (limited to 'fs/debugfs/inode.c')
-rw-r--r-- | fs/debugfs/inode.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index adaaa04448b3..100186c2bf0a 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c | |||
@@ -305,11 +305,9 @@ static struct file_system_type debug_fs_type = { | |||
305 | }; | 305 | }; |
306 | MODULE_ALIAS_FS("debugfs"); | 306 | MODULE_ALIAS_FS("debugfs"); |
307 | 307 | ||
308 | static struct dentry *__create_file(const char *name, umode_t mode, | 308 | static struct dentry *start_creating(const char *name, struct dentry *parent) |
309 | struct dentry *parent, void *data, | ||
310 | const struct file_operations *fops) | ||
311 | { | 309 | { |
312 | struct dentry *dentry = NULL; | 310 | struct dentry *dentry; |
313 | int error; | 311 | int error; |
314 | 312 | ||
315 | pr_debug("debugfs: creating file '%s'\n",name); | 313 | pr_debug("debugfs: creating file '%s'\n",name); |
@@ -317,7 +315,7 @@ static struct dentry *__create_file(const char *name, umode_t mode, | |||
317 | error = simple_pin_fs(&debug_fs_type, &debugfs_mount, | 315 | error = simple_pin_fs(&debug_fs_type, &debugfs_mount, |
318 | &debugfs_mount_count); | 316 | &debugfs_mount_count); |
319 | if (error) | 317 | if (error) |
320 | goto exit; | 318 | return ERR_PTR(error); |
321 | 319 | ||
322 | /* If the parent is not specified, we create it in the root. | 320 | /* If the parent is not specified, we create it in the root. |
323 | * We need the root dentry to do this, which is in the super | 321 | * We need the root dentry to do this, which is in the super |
@@ -329,32 +327,51 @@ static struct dentry *__create_file(const char *name, umode_t mode, | |||
329 | 327 | ||
330 | mutex_lock(&parent->d_inode->i_mutex); | 328 | mutex_lock(&parent->d_inode->i_mutex); |
331 | dentry = lookup_one_len(name, parent, strlen(name)); | 329 | dentry = lookup_one_len(name, parent, strlen(name)); |
332 | if (!IS_ERR(dentry)) { | 330 | if (!IS_ERR(dentry) && dentry->d_inode) { |
333 | switch (mode & S_IFMT) { | ||
334 | case S_IFDIR: | ||
335 | error = debugfs_mkdir(dentry, mode); | ||
336 | |||
337 | break; | ||
338 | case S_IFLNK: | ||
339 | error = debugfs_link(dentry, mode, data); | ||
340 | break; | ||
341 | default: | ||
342 | error = debugfs_create(dentry, mode, data, fops); | ||
343 | break; | ||
344 | } | ||
345 | dput(dentry); | 331 | dput(dentry); |
346 | } else | 332 | dentry = ERR_PTR(-EEXIST); |
347 | error = PTR_ERR(dentry); | 333 | } |
348 | mutex_unlock(&parent->d_inode->i_mutex); | 334 | if (IS_ERR(dentry)) |
335 | mutex_unlock(&parent->d_inode->i_mutex); | ||
336 | return dentry; | ||
337 | } | ||
338 | |||
339 | static struct dentry *end_creating(struct dentry *dentry, int error) | ||
340 | { | ||
341 | mutex_unlock(&dentry->d_parent->d_inode->i_mutex); | ||
342 | dput(dentry); | ||
349 | 343 | ||
350 | if (error) { | 344 | if (error) { |
351 | dentry = NULL; | 345 | dentry = NULL; |
352 | simple_release_fs(&debugfs_mount, &debugfs_mount_count); | 346 | simple_release_fs(&debugfs_mount, &debugfs_mount_count); |
353 | } | 347 | } |
354 | exit: | ||
355 | return dentry; | 348 | return dentry; |
356 | } | 349 | } |
357 | 350 | ||
351 | static struct dentry *__create_file(const char *name, umode_t mode, | ||
352 | struct dentry *parent, void *data, | ||
353 | const struct file_operations *fops) | ||
354 | { | ||
355 | struct dentry *dentry = start_creating(name, parent); | ||
356 | int error; | ||
357 | |||
358 | if (IS_ERR(dentry)) | ||
359 | return NULL; | ||
360 | |||
361 | switch (mode & S_IFMT) { | ||
362 | case S_IFDIR: | ||
363 | error = debugfs_mkdir(dentry, mode); | ||
364 | break; | ||
365 | case S_IFLNK: | ||
366 | error = debugfs_link(dentry, mode, data); | ||
367 | break; | ||
368 | default: | ||
369 | error = debugfs_create(dentry, mode, data, fops); | ||
370 | break; | ||
371 | } | ||
372 | return end_creating(dentry, error); | ||
373 | } | ||
374 | |||
358 | /** | 375 | /** |
359 | * debugfs_create_file - create a file in the debugfs filesystem | 376 | * debugfs_create_file - create a file in the debugfs filesystem |
360 | * @name: a pointer to a string containing the name of the file to create. | 377 | * @name: a pointer to a string containing the name of the file to create. |