[PATCH] crypto: ccree - Fix error handling in ccree_init()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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")
Signed-off-by: Yuan Can <yuancan@xxxxxxxxxx>
---
 drivers/crypto/ccree/cc_debugfs.c | 2 +-
 drivers/crypto/ccree/cc_driver.c  | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/ccree/cc_debugfs.c b/drivers/crypto/ccree/cc_debugfs.c
index 7083767602fc..8f008f024f8f 100644
--- a/drivers/crypto/ccree/cc_debugfs.c
+++ b/drivers/crypto/ccree/cc_debugfs.c
@@ -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);
 }
diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c
index cadead18b59e..1969d1e6df40 100644
--- a/drivers/crypto/ccree/cc_driver.c
+++ b/drivers/crypto/ccree/cc_driver.c
@@ -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);
 
-- 
2.17.1




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux