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

Conor Dooley conor at kernel.org
Tue Jun 16 08:29:22 PDT 2026


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 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;

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
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-riscv/attachments/20260616/df6a091c/attachment.sig>


More information about the linux-riscv mailing list