* [PATCH] cache: sifive_ccache: remove debugfs on driver register failure
@ 2026-06-16 15:13 Pengpeng Hou
2026-06-16 15:29 ` Conor Dooley
0 siblings, 1 reply; 2+ messages in thread
From: Pengpeng Hou @ 2026-06-16 15:13 UTC (permalink / raw)
To: Conor Dooley
Cc: Jonathan Cameron, Paul Walmsley, Samuel Holland, linux-riscv,
linux-kernel, Pengpeng Hou
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@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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] cache: sifive_ccache: remove debugfs on driver register failure
2026-06-16 15:13 [PATCH] cache: sifive_ccache: remove debugfs on driver register failure Pengpeng Hou
@ 2026-06-16 15:29 ` Conor Dooley
0 siblings, 0 replies; 2+ messages in thread
From: Conor Dooley @ 2026-06-16 15:29 UTC (permalink / raw)
To: Pengpeng Hou
Cc: Jonathan Cameron, Paul Walmsley, Samuel Holland, linux-riscv,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1892 bytes --]
On Tue, Jun 16, 2026 at 11:13:14PM +0800, Pengpeng Hou wrote:
> 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@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;
Firstly, do we really need a function for this?
Secondly, is there any reason to actually explicitly NULL this after
we're done removing? The driver has failed to probe so it's not as if
something is going to refer to this dentry pointer anyway?
Am I missing something?
Cheers,
Conor.
> +}
> #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
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-16 15:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-16 15:13 [PATCH] cache: sifive_ccache: remove debugfs on driver register failure Pengpeng Hou
2026-06-16 15:29 ` Conor Dooley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®