[PATCH 2/2] crypto: rockchip - fix debugfs leak when stats are disabled

Timur Kussainov kusainov.timur at gmail.com
Sat Nov 28 12:47:45 PST 2026


Since commit 1a15d26c3131 ("crypto: rk3288 - Use new crypto_engine_op
interface") register_debugfs() creates /sys/kernel/debug/rk3288_crypto
unconditionally, but the dentry is only stored in rocklist, and only
removed in rk_crypto_remove(), when CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG is
enabled.

With the option disabled the directory is leaked on module removal.
Reading the stale "stats" file afterwards dereferences the freed module
and oopses, and a re-probe fails to create the directory again.

Create the debugfs entries only when CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG is
enabled, as the Kconfig help text describes, and remove them
unconditionally (debugfs_remove_recursive() handles NULL).

Fixes: 1a15d26c3131 ("crypto: rk3288 - Use new crypto_engine_op interface")
Signed-off-by: Timur Kussainov <kusainov.timur at gmail.com>
---
 drivers/crypto/rockchip/rk3288_crypto.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c
index b2b629fff..b600ef8b0 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -235,18 +235,15 @@ DEFINE_SHOW_ATTRIBUTE(rk_crypto_debugfs);
 
 static void register_debugfs(struct rk_crypto_info *crypto_info)
 {
-	struct dentry *dbgfs_dir __maybe_unused;
-	struct dentry *dbgfs_stats __maybe_unused;
+	if (!IS_ENABLED(CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG))
+		return;
 
 	/* Ignore error of debugfs */
-	dbgfs_dir = debugfs_create_dir("rk3288_crypto", NULL);
-	dbgfs_stats = debugfs_create_file("stats", 0444, dbgfs_dir, &rocklist,
-					  &rk_crypto_debugfs_fops);
-
-#ifdef CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG
-	rocklist.dbgfs_dir = dbgfs_dir;
-	rocklist.dbgfs_stats = dbgfs_stats;
-#endif
+	rocklist.dbgfs_dir = debugfs_create_dir("rk3288_crypto", NULL);
+	rocklist.dbgfs_stats = debugfs_create_file("stats", 0444,
+						   rocklist.dbgfs_dir,
+						   &rocklist,
+						   &rk_crypto_debugfs_fops);
 }
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -420,9 +417,7 @@ static void rk_crypto_remove(struct platform_device *pdev)
 	spin_unlock_bh(&rocklist.lock);
 
 	if (!first) {
-#ifdef CONFIG_CRYPTO_DEV_ROCKCHIP_DEBUG
 		debugfs_remove_recursive(rocklist.dbgfs_dir);
-#endif
 		rk_crypto_unregister();
 	}
 	rk_crypto_pm_exit(crypto_tmp);
-- 
2.47.3




More information about the Linux-rockchip mailing list