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>
This commit is contained in:
Greg Kroah-Hartman 2019-07-03 09:16:53 +02:00
parent fb59b7824d
commit 43e23b6c0b
1 changed files with 20 additions and 5 deletions

View File

@ -2,8 +2,9 @@
/* /*
* inode.c - part of debugfs, a tiny little debug file system * inode.c - part of debugfs, a tiny little debug file system
* *
* Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com> * Copyright (C) 2004,2019 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2004 IBM Inc. * Copyright (C) 2004 IBM Inc.
* Copyright (C) 2019 Linux Foundation <gregkh@linuxfoundation.org>
* *
* debugfs is for people to use instead of /proc or /sys. * debugfs is for people to use instead of /proc or /sys.
* See ./Documentation/core-api/kernel-api.rst for more details. * 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)
error = simple_pin_fs(&debug_fs_type, &debugfs_mount, error = simple_pin_fs(&debug_fs_type, &debugfs_mount,
&debugfs_mount_count); &debugfs_mount_count);
if (error) if (error) {
pr_err("Unable to pin filesystem for file '%s'\n", name);
return ERR_PTR(error); return ERR_PTR(error);
}
/* If the parent is not specified, we create it in the root. /* If the parent is not specified, we create it in the root.
* We need the root dentry to do this, which is in the super * 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)
dentry = lookup_one_len(name, parent, strlen(name)); dentry = lookup_one_len(name, parent, strlen(name));
if (!IS_ERR(dentry) && d_really_is_positive(dentry)) { if (!IS_ERR(dentry) && d_really_is_positive(dentry)) {
dput(dentry); dput(dentry);
pr_err("File '%s' already present!\n", name);
dentry = ERR_PTR(-EEXIST); dentry = ERR_PTR(-EEXIST);
} }
@ -349,8 +353,11 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
return dentry; return dentry;
inode = debugfs_get_inode(dentry->d_sb); inode = debugfs_get_inode(dentry->d_sb);
if (unlikely(!inode)) if (unlikely(!inode)) {
pr_err("out of free dentries, can not create file '%s'\n",
name);
return failed_creating(dentry); return failed_creating(dentry);
}
inode->i_mode = mode; inode->i_mode = mode;
inode->i_private = data; inode->i_private = data;
@ -511,8 +518,11 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
return dentry; return dentry;
inode = debugfs_get_inode(dentry->d_sb); inode = debugfs_get_inode(dentry->d_sb);
if (unlikely(!inode)) if (unlikely(!inode)) {
pr_err("out of free dentries, can not create directory '%s'\n",
name);
return failed_creating(dentry); 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;
@ -550,8 +560,11 @@ struct dentry *debugfs_create_automount(const char *name,
return dentry; return dentry;
inode = debugfs_get_inode(dentry->d_sb); inode = debugfs_get_inode(dentry->d_sb);
if (unlikely(!inode)) if (unlikely(!inode)) {
pr_err("out of free dentries, can not create automount '%s'\n",
name);
return failed_creating(dentry); return failed_creating(dentry);
}
make_empty_dir_inode(inode); make_empty_dir_inode(inode);
inode->i_flags |= S_AUTOMOUNT; inode->i_flags |= S_AUTOMOUNT;
@ -606,6 +619,8 @@ 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)) {
pr_err("out of free dentries, can not create symlink '%s'\n",
name);
kfree(link); kfree(link);
return failed_creating(dentry); return failed_creating(dentry);
} }