Skip to contentSkip to conversation

i2c: npcm7xx: Fix error handling in npcm_i2c_init()

PATCH Applied Yuan Can 3 participants 3 messages Nov 9, 2022 – Nov 12, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 i2c: npcm7xx: Fix error handling in npcm_i2c_init()

A problem about i2c-npcm7xx create debugfs failed is triggered with the following log given:

 [  173.827310] debugfs: Directory 'npcm_i2c' with parent '/' already present!

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

npcm_i2c_init()
debugfs_create_dir() # create debugfs directory platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
---
 drivers/i2c/busses/i2c-npcm7xx.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-npcm7xx.c +10 -1
index 0c365b57d957..83457359ec45 100644
@@ -2393,8 +2393,17 @@ static struct platform_driver npcm_i2c_bus_driver = {
 
 static int __init npcm_i2c_init(void)
 {
+	int ret;
+
 	npcm_i2c_debugfs_dir = debugfs_create_dir("npcm_i2c", NULL);
-	return platform_driver_register(&npcm_i2c_bus_driver);
+
+	ret = platform_driver_register(&npcm_i2c_bus_driver);
+	if (ret) {
+		debugfs_remove_recursive(npcm_i2c_debugfs_dir);
+		return ret;
+	}
+
+	return 0;
 }
 module_init(npcm_i2c_init);
 
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 51 lines · Yuan Can

A problem about i2c-npcm7xx create debugfs failed is triggered with the following log given:

 [  173.827310] debugfs: Directory 'npcm_i2c' with parent '/' already present!

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

npcm_i2c_init()
debugfs_create_dir() # create debugfs directory platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

   # return without destroy debugfs directory

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")
---
 drivers/i2c/busses/i2c-npcm7xx.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-npcm7xx.c +10 -2
index 0c365b57d957..83457359ec45 100644
@@ -2393,8 +2393,17 @@ static struct platform_driver npcm_i2c_bus_driver = {
 
 static int __init npcm_i2c_init(void)
 {
+       int ret;
+
        npcm_i2c_debugfs_dir = debugfs_create_dir("npcm_i2c", NULL);
-       return platform_driver_register(&npcm_i2c_bus_driver);
+
+       ret = platform_driver_register(&npcm_i2c_bus_driver);
+       if (ret) {
+               debugfs_remove_recursive(npcm_i2c_debugfs_dir);
+               return ret;
+       }
+
+       return 0;
 }
 module_init(npcm_i2c_init);
 
--
Quoted 2 lines

2.17.1

Thanks Yuan!

Applied
#2 lore raw
In reply to Yuan Can
Quoted 16 lines · Yuan Can

A problem about i2c-npcm7xx create debugfs failed is triggered with the following log given:

 [  173.827310] debugfs: Directory 'npcm_i2c' with parent '/' already present!

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

npcm_i2c_init()
debugfs_create_dir() # create debugfs directory platform_driver_register()
driver_register()
bus_add_driver()
priv = kzalloc(...) # OOM happened

Quoted 6 lines
   # return without destroy debugfs directory

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver")

Applied to for-current, thanks!