Skip to content

Commit 145900c

Browse files
Yuan Canwsakernel
authored andcommitted
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: 56a1485 ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Yuan Can <[email protected]> Reviewed-by: Tali Perry <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent f0c4d9f commit 145900c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/i2c/busses/i2c-npcm7xx.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,8 +2393,17 @@ static struct platform_driver npcm_i2c_bus_driver = {
23932393

23942394
static int __init npcm_i2c_init(void)
23952395
{
2396+
int ret;
2397+
23962398
npcm_i2c_debugfs_dir = debugfs_create_dir("npcm_i2c", NULL);
2397-
return platform_driver_register(&npcm_i2c_bus_driver);
2399+
2400+
ret = platform_driver_register(&npcm_i2c_bus_driver);
2401+
if (ret) {
2402+
debugfs_remove_recursive(npcm_i2c_debugfs_dir);
2403+
return ret;
2404+
}
2405+
2406+
return 0;
23982407
}
23992408
module_init(npcm_i2c_init);
24002409

0 commit comments

Comments
 (0)