[PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()

Yang Ruibin posted 1 patch 1 year, 5 months ago
lib/test_fpu_glue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
Posted by Yang Ruibin 1 year, 5 months ago
The debugfs_create_dir() function returns error pointers.
It never returns NULL. So use IS_ERR() to check it.

Signed-off-by: Yang Ruibin <11162571@vivo.com>
---
 lib/test_fpu_glue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/test_fpu_glue.c b/lib/test_fpu_glue.c
index 074f30301f29..c0596426370a 100644
--- a/lib/test_fpu_glue.c
+++ b/lib/test_fpu_glue.c
@@ -42,7 +42,7 @@ static int __init test_fpu_init(void)
 		return -EINVAL;
 
 	selftest_dir = debugfs_create_dir("selftest_helpers", NULL);
-	if (!selftest_dir)
+	if (IS_ERR(selftest_dir))
 		return -ENOMEM;
 
 	debugfs_create_file_unsafe("test_fpu", 0444, selftest_dir, NULL,
-- 
2.34.1
Re: [PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
Posted by Andy Shevchenko 1 year, 5 months ago
Wed, Aug 21, 2024 at 03:34:40AM -0400, Yang Ruibin kirjoitti:
> The debugfs_create_dir() function returns error pointers.
> It never returns NULL. So use IS_ERR() to check it.

>  	selftest_dir = debugfs_create_dir("selftest_helpers", NULL);
> -	if (!selftest_dir)
> +	if (IS_ERR(selftest_dir))
>  		return -ENOMEM;

With this you most likely want to propagate error code to the caller

		return PTR_ERR(selftest_dir);

BUT, we usually don't check debugfs error codes as the program should work
anyway. Does this test case actually _rely_ on debugfs to be functional?

-- 
With Best Regards,
Andy Shevchenko