2023-07-12 14:28:41

by Wang Ming

[permalink] [raw]
Subject: [PATCH v1] lib:Fix an NULL vs IS_ERR() bug for debugfs_create_dir() in err_inject_init()

The debugfs_create_dir() function returns error pointers.
It never returns NULL. Most incorrect error checks were fixed,
but the one in err_inject_init() was forgotten.

Fix the remaining error check.

Signed-off-by: Wang Ming <[email protected]>
---
lib/notifier-error-inject.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c
index 2b24ea6c9497..c49354c23802 100644
--- a/lib/notifier-error-inject.c
+++ b/lib/notifier-error-inject.c
@@ -83,7 +83,7 @@ static int __init err_inject_init(void)
notifier_err_inject_dir =
debugfs_create_dir("notifier-error-inject", NULL);

- if (!notifier_err_inject_dir)
+ if (IS_ERR(notifier_err_inject_dir))
return -ENOMEM;

return 0;
--
2.25.1



2023-07-12 16:57:31

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v1] lib:Fix an NULL vs IS_ERR() bug for debugfs_create_dir() in err_inject_init()

On Wed, Jul 12, 2023 at 09:52:11PM +0800, Wang Ming wrote:
> The debugfs_create_dir() function returns error pointers.
> It never returns NULL. Most incorrect error checks were fixed,
> but the one in err_inject_init() was forgotten.
>
> Fix the remaining error check.
>
> Signed-off-by: Wang Ming <[email protected]>
> ---
> lib/notifier-error-inject.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c
> index 2b24ea6c9497..c49354c23802 100644
> --- a/lib/notifier-error-inject.c
> +++ b/lib/notifier-error-inject.c
> @@ -83,7 +83,7 @@ static int __init err_inject_init(void)
> notifier_err_inject_dir =
> debugfs_create_dir("notifier-error-inject", NULL);
>
> - if (!notifier_err_inject_dir)
> + if (IS_ERR(notifier_err_inject_dir))
> return -ENOMEM;

Please do not do any different codepath if a debugfs_*() call fails or
succeeds.

Why do you need to check this at all?

And why are you creating this directory at the root of debugfs?

thanks,

greg k-h