Skip to contentSkip to conversation

crypto: ccree - Fix error handling in ccree_init()

PATCH New Yuan Can 1 participant 1 message Nov 13, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 crypto: ccree - Fix error handling in ccree_init()

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

 [  398.049333] debugfs: Directory 'ccree' with parent '/' already present!

The reason is that ccree_init() returns platform_driver_register() directly without checking its return value, if platform_driver_register() failed, it returns without remove debugfs of ccree, resulting the debugfs of ccree can never be created later.
A simple call graph is shown as below:

ccree_init()
cc_debugfs_global_init() # create debugfs ccree platform_driver_register()
driver_register()
bus_add_driver()
dev = kzalloc(...) # OOM happened

   # return without destroy debugfs ccree

Fix by removing debugfs when platform_driver_register() returns error.

Fixes 4c3f97276e15 ("crypto: ccree - introduce CryptoCell driver")
---
 drivers/crypto/ccree/cc_debugfs.c | 2 +-
 drivers/crypto/ccree/cc_driver.c  | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/crypto/ccree/cc_debugfs.c +1 -1
index 7083767602fc..8f008f024f8f 100644
@@ -55,7 +55,7 @@ void __init cc_debugfs_global_init(void)
 	cc_debugfs_dir = debugfs_create_dir("ccree", NULL);
 }
 
-void __exit cc_debugfs_global_fini(void)
+void cc_debugfs_global_fini(void)
 {
 	debugfs_remove(cc_debugfs_dir);
 }
drivers/crypto/ccree/cc_driver.c +7 -1
index cadead18b59e..1969d1e6df40 100644
@@ -651,9 +651,15 @@ static struct platform_driver ccree_driver = {
 
 static int __init ccree_init(void)
 {
+	int ret;
+
 	cc_debugfs_global_init();
 
-	return platform_driver_register(&ccree_driver);
+	ret = platform_driver_register(&ccree_driver);
+	if (ret)
+		cc_debugfs_global_fini();
+
+	return ret;
 }
 module_init(ccree_init);
 
Signature · 1 line
2.17.1