Skip to contentSkip to conversation

lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()

PATCH Applied Yang Ruibin 2 participants 2 messages Aug 21, 2024 – Aug 22, 2024 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()

The debugfs_create_dir() function returns error pointers. It never returns NULL. So use IS_ERR() to check it.

---
 lib/test_fpu_glue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_fpu_glue.c +1 -1
index 074f30301f29..c0596426370a 100644
@@ -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,
Signature · 1 line
2.34.1
#1 lore raw

Wed, Aug 21, 2024 at 03:34:40AM -0400, Yang Ruibin kirjoitti:

lib/test_fpu_glue.c static int __init test_fpu_init(void) · line 46

Quoted 7 lines

The debugfs_create_dir() function returns error pointers. It never returns NULL. So use IS_ERR() to check it.

lib/test_fpu_glue.c +1 -1
 	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?

Signature · 2 lines
With Best Regards,
Andy Shevchenko