Skip to content

Commit 43e23b6

Browse files
committed
debugfs: log errors when something goes wrong
As it is not recommended that debugfs calls be checked, it was pointed out that major errors should still be logged somewhere so that developers and users have a chance to figure out what went wrong. To help with this, error logging has been added to the debugfs core so that it is not needed to be present in every individual file that calls debugfs. Reported-by: Mark Brown <broonie@kernel.org> Reported-by: Takashi Iwai <tiwai@suse.de> Reviewed-by: Mark Brown <broonie@kernel.org> Reviewed-by: Takashi Iwai <tiwai@suse.de> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20190703071653.2799-2-gregkh@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fb59b78 commit 43e23b6

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

‎fs/debugfs/inode.c‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
/*
33
* inode.c - part of debugfs, a tiny little debug file system
44
*
5-
* Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
5+
* Copyright (C) 2004,2019 Greg Kroah-Hartman <greg@kroah.com>
66
* Copyright (C) 2004 IBM Inc.
7+
* Copyright (C) 2019 Linux Foundation <gregkh@linuxfoundation.org>
78
*
89
* debugfs is for people to use instead of /proc or /sys.
910
* See ./Documentation/core-api/kernel-api.rst for more details.
@@ -292,8 +293,10 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
292293

293294
error = simple_pin_fs(&debug_fs_type, &debugfs_mount,
294295
&debugfs_mount_count);
295-
if (error)
296+
if (error) {
297+
pr_err("Unable to pin filesystem for file '%s'\n", name);
296298
return ERR_PTR(error);
299+
}
297300

298301
/* If the parent is not specified, we create it in the root.
299302
* We need the root dentry to do this, which is in the super
@@ -307,6 +310,7 @@ static struct dentry *start_creating(const char *name, struct dentry *parent)
307310
dentry = lookup_one_len(name, parent, strlen(name));
308311
if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
309312
dput(dentry);
313+
pr_err("File '%s' already present!\n", name);
310314
dentry = ERR_PTR(-EEXIST);
311315
}
312316

@@ -349,8 +353,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
349353
return dentry;
350354

351355
inode = debugfs_get_inode(dentry->d_sb);
352-
if (unlikely(!inode))
356+
if (unlikely(!inode)) {
357+
pr_err("out of free dentries, can not create file '%s'\n",
358+
name);
353359
return failed_creating(dentry);
360+
}
354361

355362
inode->i_mode = mode;
356363
inode->i_private = data;
@@ -511,8 +518,11 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
511518
return dentry;
512519

513520
inode = debugfs_get_inode(dentry->d_sb);
514-
if (unlikely(!inode))
521+
if (unlikely(!inode)) {
522+
pr_err("out of free dentries, can not create directory '%s'\n",
523+
name);
515524
return failed_creating(dentry);
525+
}
516526

517527
inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
518528
inode->i_op = &simple_dir_inode_operations;
@@ -550,8 +560,11 @@ struct dentry *debugfs_create_automount(const char *name,
550560
return dentry;
551561

552562
inode = debugfs_get_inode(dentry->d_sb);
553-
if (unlikely(!inode))
563+
if (unlikely(!inode)) {
564+
pr_err("out of free dentries, can not create automount '%s'\n",
565+
name);
554566
return failed_creating(dentry);
567+
}
555568

556569
make_empty_dir_inode(inode);
557570
inode->i_flags |= S_AUTOMOUNT;
@@ -606,6 +619,8 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
606619

607620
inode = debugfs_get_inode(dentry->d_sb);
608621
if (unlikely(!inode)) {
622+
pr_err("out of free dentries, can not create symlink '%s'\n",
623+
name);
609624
kfree(link);
610625
return failed_creating(dentry);
611626
}

0 commit comments

Comments
 (0)