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

Yang Ruibin posted 1 patch 1 year, 5 months ago
drivers/bus/mvebu-mbus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v1] drivers:bus: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>
---
 drivers/bus/mvebu-mbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c
index 3c99d72087eb..42621838ba75 100644
--- a/drivers/bus/mvebu-mbus.c
+++ b/drivers/bus/mvebu-mbus.c
@@ -995,13 +995,13 @@ static __init int mvebu_mbus_debugfs_init(void)
 	s->debugfs_root = debugfs_create_dir("mvebu-mbus", NULL);
 	if(IS_ERR(s->debugfs_root))
 		return PTR_ERR(s->debugfs_root);
+
 	s->debugfs_sdram = debugfs_create_file("sdram", S_IRUGO,
 							s->debugfs_root, NULL,
 							&mvebu_sdram_debug_fops);
 	s->debugfs_devs = debugfs_create_file("devices", S_IRUGO,
 							s->debugfs_root, NULL,
 							&mvebu_devs_debug_fops);
-	}
 
 	return 0;
 }
-- 
2.34.1
Re: [PATCH v1] drivers:bus:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
Posted by Andrew Lunn 1 year, 5 months ago
On Wed, Aug 21, 2024 at 07:21:30AM -0400, Yang Ruibin wrote:
> 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>
> ---
>  drivers/bus/mvebu-mbus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/mvebu-mbus.c b/drivers/bus/mvebu-mbus.c
> index 3c99d72087eb..42621838ba75 100644
> --- a/drivers/bus/mvebu-mbus.c
> +++ b/drivers/bus/mvebu-mbus.c
> @@ -995,13 +995,13 @@ static __init int mvebu_mbus_debugfs_init(void)
>  	s->debugfs_root = debugfs_create_dir("mvebu-mbus", NULL);
>  	if(IS_ERR(s->debugfs_root))
>  		return PTR_ERR(s->debugfs_root);
> +

You are not supposed to check error codes from debugfs, since it is
optional. The code should just keep going, independent of failure or
success.

>  	s->debugfs_sdram = debugfs_create_file("sdram", S_IRUGO,
>  							s->debugfs_root, NULL,
>  							&mvebu_sdram_debug_fops);
>  	s->debugfs_devs = debugfs_create_file("devices", S_IRUGO,
>  							s->debugfs_root, NULL,
>  							&mvebu_devs_debug_fops);
> -	}

I'm surprised this code compiles without this close braces!

	Andrew