All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eeprom: idt_89hpesx: Fix error handling in idt_init()
@ 2022-11-10  2:00 Yuan Can
  2022-11-10 12:14 ` Serge Semin
  0 siblings, 1 reply; 2+ messages in thread
From: Yuan Can @ 2022-11-10  2:00 UTC (permalink / raw)
  To: arnd, gregkh, wsa+renesas, benjamin.mugnier, dmitry.torokhov,
	cmo, u.kleine-koenig, error27, justinstitt, fancer.lancer,
	linux-kernel
  Cc: yuancan

A problem about idt_89hpesx create debugfs failed is triggered with the
following log given:

 [ 4973.269647] debugfs: Directory 'idt_csr' with parent '/' already present!

The reason is that idt_init() returns i2c_add_driver() directly without
checking its return value, if i2c_add_driver() failed, it returns without
destroy the newly created debugfs, resulting the debugfs of idt_csr can
never be created later.

 idt_init()
   debugfs_create_dir() # create debugfs directory
   i2c_add_driver()
     driver_register()
       bus_add_driver()
         priv = kzalloc(...) # OOM happened
   # return without destroy debugfs directory

Fix by removing debugfs when i2c_add_driver() returns error.

Fixes: cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/misc/eeprom/idt_89hpesx.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89hpesx.c
index bb3ed352b95f..367054e0ced4 100644
--- a/drivers/misc/eeprom/idt_89hpesx.c
+++ b/drivers/misc/eeprom/idt_89hpesx.c
@@ -1566,12 +1566,20 @@ static struct i2c_driver idt_driver = {
  */
 static int __init idt_init(void)
 {
+	int ret;
+
 	/* Create Debugfs directory first */
 	if (debugfs_initialized())
 		csr_dbgdir = debugfs_create_dir("idt_csr", NULL);
 
 	/* Add new i2c-device driver */
-	return i2c_add_driver(&idt_driver);
+	ret = i2c_add_driver(&idt_driver);
+	if (ret) {
+		debugfs_remove_recursive(csr_dbgdir);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(idt_init);
 
-- 
2.17.1


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

* Re: [PATCH] eeprom: idt_89hpesx: Fix error handling in idt_init()
  2022-11-10  2:00 [PATCH] eeprom: idt_89hpesx: Fix error handling in idt_init() Yuan Can
@ 2022-11-10 12:14 ` Serge Semin
  0 siblings, 0 replies; 2+ messages in thread
From: Serge Semin @ 2022-11-10 12:14 UTC (permalink / raw)
  To: Yuan Can
  Cc: arnd, gregkh, wsa+renesas, benjamin.mugnier, dmitry.torokhov,
	cmo, u.kleine-koenig, error27, justinstitt, linux-kernel

Hi Yuan,

On Thu, Nov 10, 2022 at 02:00:30AM +0000, Yuan Can wrote:
> A problem about idt_89hpesx create debugfs failed is triggered with the
> following log given:
> 
>  [ 4973.269647] debugfs: Directory 'idt_csr' with parent '/' already present!
> 
> The reason is that idt_init() returns i2c_add_driver() directly without
> checking its return value, if i2c_add_driver() failed, it returns without
> destroy the newly created debugfs, resulting the debugfs of idt_csr can
> never be created later.
> 
>  idt_init()
>    debugfs_create_dir() # create debugfs directory
>    i2c_add_driver()
>      driver_register()
>        bus_add_driver()
>          priv = kzalloc(...) # OOM happened
>    # return without destroy debugfs directory
> 
> Fix by removing debugfs when i2c_add_driver() returns error.
> 
> Fixes: cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")
> Signed-off-by: Yuan Can <yuancan@huawei.com>

Don't know what I was thinking back than. Thanks for fixing this.
Acked-by: Serge Semin <fancer.lancer@gmail.com>

-Sergey

> ---
>  drivers/misc/eeprom/idt_89hpesx.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/eeprom/idt_89hpesx.c b/drivers/misc/eeprom/idt_89hpesx.c
> index bb3ed352b95f..367054e0ced4 100644
> --- a/drivers/misc/eeprom/idt_89hpesx.c
> +++ b/drivers/misc/eeprom/idt_89hpesx.c
> @@ -1566,12 +1566,20 @@ static struct i2c_driver idt_driver = {
>   */
>  static int __init idt_init(void)
>  {
> +	int ret;
> +
>  	/* Create Debugfs directory first */
>  	if (debugfs_initialized())
>  		csr_dbgdir = debugfs_create_dir("idt_csr", NULL);
>  
>  	/* Add new i2c-device driver */
> -	return i2c_add_driver(&idt_driver);
> +	ret = i2c_add_driver(&idt_driver);
> +	if (ret) {
> +		debugfs_remove_recursive(csr_dbgdir);
> +		return ret;
> +	}
> +
> +	return 0;
>  }
>  module_init(idt_init);
>  
> -- 
> 2.17.1
> 

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

end of thread, other threads:[~2022-11-10 12:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  2:00 [PATCH] eeprom: idt_89hpesx: Fix error handling in idt_init() Yuan Can
2022-11-10 12:14 ` Serge Semin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.