Skip to contentSkip to conversation

eeprom: idt_89hpesx: Fix error handling in idt_init()

PATCH In review Yuan Can 2 participants 2 messages Nov 10, 2022 Char and misc drivers

lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 eeprom: idt_89hpesx: Fix error handling in idt_init()

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")
---
 drivers/misc/eeprom/idt_89hpesx.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/misc/eeprom/idt_89hpesx.c +9 -1
index bb3ed352b95f..367054e0ced4 100644
@@ -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);
 
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw

Hi Yuan,

Quoted 16 lines · Yuan Can

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

Quoted 6 lines
   # return without destroy debugfs directory

Fix by removing debugfs when i2c_add_driver() returns error.

Fixes cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")

Don't know what I was thinking back than. Thanks for fixing this.

-Sergey

Quoted 33 lines
---
 drivers/misc/eeprom/idt_89hpesx.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/misc/eeprom/idt_89hpesx.c +9 -1
index bb3ed352b95f..367054e0ced4 100644
@@ -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);
 
Signature · 1 line
2.17.1