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

Yang Ruibin posted 1 patch 1 year, 5 months ago
drivers/hsi/controllers/omap_ssi_core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH v1] drivers:controllers: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/hsi/controllers/omap_ssi_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hsi/controllers/omap_ssi_core.c b/drivers/hsi/controllers/omap_ssi_core.c
index 3140990a6164..f85d56e85c0f 100644
--- a/drivers/hsi/controllers/omap_ssi_core.c
+++ b/drivers/hsi/controllers/omap_ssi_core.c
@@ -116,14 +116,14 @@ static int ssi_debug_add_ctrl(struct hsi_controller *ssi)
 
 	/* SSI controller */
 	omap_ssi->dir = debugfs_create_dir(dev_name(&ssi->device), NULL);
-	if (!omap_ssi->dir)
+	if (IS_ERR(omap_ssi->dir))
 		return -ENOMEM;
 
 	debugfs_create_file("regs", S_IRUGO, omap_ssi->dir, ssi,
 								&ssi_regs_fops);
 	/* SSI GDD (DMA) */
 	dir = debugfs_create_dir("gdd", omap_ssi->dir);
-	if (!dir)
+	if (IS_ERR(dir))
 		goto rback;
 	debugfs_create_file("regs", S_IRUGO, dir, ssi, &ssi_gdd_regs_fops);
 
-- 
2.34.1
Re: [PATCH v1] drivers:controllers:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
Posted by Sebastian Reichel 1 year, 5 months ago
Hi,

On Wed, Aug 21, 2024 at 03:39:14AM GMT, 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>
> ---

Please remove all error handling from that function instead. The
functions can cope with prior errors being passed to them.

Greetings,

-- Sebastian

>  drivers/hsi/controllers/omap_ssi_core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hsi/controllers/omap_ssi_core.c b/drivers/hsi/controllers/omap_ssi_core.c
> index 3140990a6164..f85d56e85c0f 100644
> --- a/drivers/hsi/controllers/omap_ssi_core.c
> +++ b/drivers/hsi/controllers/omap_ssi_core.c
> @@ -116,14 +116,14 @@ static int ssi_debug_add_ctrl(struct hsi_controller *ssi)
>  
>  	/* SSI controller */
>  	omap_ssi->dir = debugfs_create_dir(dev_name(&ssi->device), NULL);
> -	if (!omap_ssi->dir)
> +	if (IS_ERR(omap_ssi->dir))
>  		return -ENOMEM;
>  
>  	debugfs_create_file("regs", S_IRUGO, omap_ssi->dir, ssi,
>  								&ssi_regs_fops);
>  	/* SSI GDD (DMA) */
>  	dir = debugfs_create_dir("gdd", omap_ssi->dir);
> -	if (!dir)
> +	if (IS_ERR(dir))
>  		goto rback;
>  	debugfs_create_file("regs", S_IRUGO, dir, ssi, &ssi_gdd_regs_fops);
>  
> -- 
> 2.34.1
>