drivers/ras/cec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
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() calls to properly handle errors.
Fixes: 011d82611172 ("RAS: Add a Corrected Errors Collector")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
drivers/ras/cec.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index e440b15fbabc..fda289ef0610 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -489,21 +489,21 @@ static int __init create_debugfs_nodes(void)
}
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;
}
--
2.50.1.windows.1
> From: Haotian Zhang <vulab@iscas.ac.cn>
> Sent: Thursday, November 20, 2025 11:02 AM
> To: Luck, Tony <tony.luck@intel.com>; bp@alien8.de
> Cc: linux-edac@vger.kernel.org; linux-kernel@vger.kernel.org; Haotian Zhang
> <vulab@iscas.ac.cn>
> Subject: [PATCH] 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() calls to properly handle errors.
>
> Fixes: 011d82611172 ("RAS: Add a Corrected Errors Collector")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---
> [...]
I just quickly found that there are at least two more that need these similar fixes:
Maybe you can add these missing fixes to your patch as well.
diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index e440b15fbabc..9f6626380ea2 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -483,7 +483,7 @@ 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;
}
diff --git a/drivers/ras/debugfs.c b/drivers/ras/debugfs.c
index 42afd3de68b2..8f817bd9cb09 100644
--- a/drivers/ras/debugfs.c
+++ b/drivers/ras/debugfs.c
@@ -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,
© 2016 - 2025 Red Hat, Inc.