ras: cec: Fix debugfs error checking
Subsystems (2)
PATCH v2 1/1 ras: cec: Fix debugfs error checking
The debugfs_create_dir() and debugfs_create_file() functions return ERR_PTR() on error, not NULL. The current null-checks fail to detect errors because ERR_PTR() encodes error codes as non-null pointer values.
Replace the null-checks with IS_ERR() for all debugfs_create_dir() and debugfs_create_file() and ras_get_debugfs_root calls to properly handle errors.
---
Changes in v2:
-Add fixes in create_debugfs_nodes() and ras_add_daemon_trace()
as suggested by Zhuo, Qiuxu.
--- drivers/ras/cec.c | 12 ++++++------ drivers/ras/debugfs.c | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/ras/cec.c +6 -6
@@ -483,27 +483,27 @@ static int __init create_debugfs_nodes(void)struct dentry *d, *pfn, *decay, *count, *array, *dfs; dfs =ras_get_debugfs_root (); -if (!dfs) { +if (IS_ERR (dfs)) {pr_warn ("Error getting RAS debugfs root!\n" );return -1 ; } d =debugfs_create_dir ("cec" , dfs); -if (!d) { +if (IS_ERR (d)) {pr_warn ("Error creating cec debugfs node!\n" );return -1 ; } decay =debugfs_create_file ("decay_interval" ,S_IRUSR |S_IWUSR , d, &decay_interval, &decay_interval_ops); -if (!decay) { +if (IS_ERR (decay)) {pr_warn ("Error creating decay_interval debugfs node!\n" ); goto err; } count =debugfs_create_file ("action_threshold" ,S_IRUSR |S_IWUSR , d, &action_threshold, &action_threshold_ops); -if (!count) { +if (IS_ERR (count)) {pr_warn ("Error creating action_threshold debugfs node!\n" ); goto err; }
@@ -512,13 +512,13 @@ static int __init create_debugfs_nodes(void)return 0 ; pfn =debugfs_create_file ("pfn" ,S_IRUSR |S_IWUSR , d, &dfs_pfn, &pfn_ops); -if (!pfn) { +if (IS_ERR (pfn)) {pr_warn ("Error creating pfn debugfs node!\n" ); goto err; } array =debugfs_create_file ("array" ,S_IRUSR , d,NULL , &array_fops); -if (!array) { +if (IS_ERR (array)) {pr_warn ("Error creating array debugfs node!\n" ); goto err; }
drivers/ras/debugfs.c +1 -1
@@ -47,7 +47,7 @@ int __init ras_add_daemon_trace(void) {struct dentry *fentry; -if (!ras_debugfs_dir) +if (IS_ERR (ras_debugfs_dir))return -ENOENT ; fentry = debugfs_create_file("daemon_active", S_IRUSR, ras_debugfs_dir,
Signature · 1 line
2.50.1.windows.1
Borislav Petkov
maintainerQuoted 9 lines · Haotian Zhang
The
debugfs_create_dir()anddebugfs_create_file()functions returnERR_PTR()on error, not NULL. The current null-checks fail to detect errors becauseERR_PTR()encodes error codes as non-null pointer values.Replace the null-checks with
IS_ERR()for alldebugfs_create_dir()anddebugfs_create_file()andras_get_debugfs_rootcalls to properly handle errors.Fixes 011d82611172 ("RAS: Add a Corrected Errors Collector")
git show 011d82611172:fs/debugfs/inode.c
...
struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
{
struct dentry *dentry = start_creating(name, parent);
struct inode *inode;
if (IS_ERR(dentry))
return NULL;
^^^^^^^^^^^So it used to return NULL at the time.
However,
/**
* debugfs_create_file - create a file in the debugfs filesystem
...
* NOTE: it's expected that most callers should _ignore_ the errors returned
* by this function. Other debugfs functions handle the fact that the "dentry"
* passed to them could be an error and they don't crash in that case.
* Drivers should generally work fine even if debugfs fails to init anyway. */
and the _dir() one has the same note. I've been hesitant to remove that error handling in cec.c until now but I think we can safely zap it. It is unnecessary clutter by now.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette