[PATCH] cache: sifive_ccache: remove debugfs on driver register failure

Pengpeng Hou pengpeng at iscas.ac.cn
Tue Jun 16 08:13:14 PDT 2026


sifive_ccache_init() creates the debugfs injection file before
registering the platform driver. If platform_driver_register() fails, the
error path unmaps ccache_base while the debugfs file remains and its
write callback still uses that global mapping.

Remove the debugfs tree before unmapping the cache controller registers
on the registration failure path.

Signed-off-by: Pengpeng Hou <pengpeng at iscas.ac.cn>
---
 drivers/cache/sifive_ccache.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/cache/sifive_ccache.c b/drivers/cache/sifive_ccache.c
index a86800b123b9..cf7877d8e3e5 100644
--- a/drivers/cache/sifive_ccache.c
+++ b/drivers/cache/sifive_ccache.c
@@ -100,6 +100,12 @@ static void setup_sifive_debug(void)
 	debugfs_create_file("sifive_debug_inject_error", 0200,
 			    sifive_test, NULL, &ccache_fops);
 }
+
+static void remove_sifive_debug(void)
+{
+	debugfs_remove_recursive(sifive_test);
+	sifive_test = NULL;
+}
 #endif
 
 static void ccache_config_read(void)
@@ -336,12 +342,16 @@ static int __init sifive_ccache_init(void)
 
 	rc = platform_driver_register(&sifive_ccache_driver);
 	if (rc)
-		goto err_unmap;
+		goto err_remove_debug;
 
 	of_node_put(np);
 
 	return 0;
 
+err_remove_debug:
+#ifdef CONFIG_DEBUG_FS
+	remove_sifive_debug();
+#endif
 err_unmap:
 	iounmap(ccache_base);
 err_node_put:
-- 
2.43.0




More information about the linux-riscv mailing list