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

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

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 7cece5884b9c..030b7a063a0b 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -498,7 +498,7 @@ static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
 	if (!pkt_debugfs_root)
 		return;
 	pd->dfs_d_root = debugfs_create_dir(pd->disk->disk_name, pkt_debugfs_root);
-	if (!pd->dfs_d_root)
+	if (IS_ERR(pd->dfs_d_root))
 		return;
 
 	pd->dfs_f_info = debugfs_create_file("info", 0444, pd->dfs_d_root,
-- 
2.34.1
Re: [PATCH v1] drivers:block:Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
Posted by Damien Le Moal 1 year, 5 months ago
On 8/21/24 15:49, Yang Ruibin wrote:
> The debugfs_create_dir() function returns error pointers.
> It never returns NULL. So use IS_ERR() to check it.

...to check its return value.

And the patch title could be better. May be something like:

pktcdvd: Use IS_ERR() to check debugfs_create_dir() return value

> 
> Signed-off-by: Yang Ruibin <11162571@vivo.com>

This needs a Fixes tag.

> ---
>  drivers/block/pktcdvd.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
> index 7cece5884b9c..030b7a063a0b 100644
> --- a/drivers/block/pktcdvd.c
> +++ b/drivers/block/pktcdvd.c
> @@ -498,7 +498,7 @@ static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
>  	if (!pkt_debugfs_root)
>  		return;
>  	pd->dfs_d_root = debugfs_create_dir(pd->disk->disk_name, pkt_debugfs_root);
> -	if (!pd->dfs_d_root)
> +	if (IS_ERR(pd->dfs_d_root))
>  		return;
>  
>  	pd->dfs_f_info = debugfs_create_file("info", 0444, pd->dfs_d_root,

-- 
Damien Le Moal
Western Digital Research