mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
@ 2024-08-21  7:34 Yang Ruibin
  2024-08-22 21:24 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Ruibin @ 2024-08-21  7:34 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel; +Cc: opensource.kernel, Yang Ruibin

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
  2024-08-21  7:34 [PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir() Yang Ruibin
@ 2024-08-22 21:24 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2024-08-22 21:24 UTC (permalink / raw)
  To: Yang Ruibin; +Cc: Andrew Morton, linux-kernel, opensource.kernel

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-22 21:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21  7:34 [PATCH v1] lib:Fix the NULL vs IS_ERR() bug for debugfs_create_dir() Yang Ruibin
2024-08-22 21:24 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®