[PATCH] bus: stm32_rifsc: clean up debugfs file with device state
Pengpeng Hou
pengpeng at iscas.ac.cn
Tue Jun 16 08:16:04 PDT 2026
stm32_rifsc_register_debugfs() creates a debugfs file whose private data
is devm-allocated RIFSC debug state. If a later probe step fails, or if
the device is removed, that debugfs file can outlive the private data it
dereferences.
Keep the created dentry and register a devm cleanup action so the file is
removed before the RIFSC state is released.
Signed-off-by: Pengpeng Hou <pengpeng at iscas.ac.cn>
---
drivers/bus/stm32_rifsc.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/bus/stm32_rifsc.c b/drivers/bus/stm32_rifsc.c
index 19d10379dcef..3877198e6eb9 100644
--- a/drivers/bus/stm32_rifsc.c
+++ b/drivers/bus/stm32_rifsc.c
@@ -602,11 +602,17 @@ static int stm32_rifsc_conf_dump_show(struct seq_file *s, void *data)
}
DEFINE_SHOW_ATTRIBUTE(stm32_rifsc_conf_dump);
+static void stm32_rifsc_remove_debugfs(void *data)
+{
+ debugfs_remove(data);
+}
+
static int stm32_rifsc_register_debugfs(struct stm32_firewall_controller *rifsc_controller,
u32 nb_risup, u32 nb_rimu, u32 nb_risal)
{
struct rifsc_dbg_private *rifsc_priv;
struct dentry *root = NULL;
+ struct dentry *file;
rifsc_priv = devm_kzalloc(rifsc_controller->dev, sizeof(*rifsc_priv), GFP_KERNEL);
if (!rifsc_priv)
@@ -625,9 +631,13 @@ static int stm32_rifsc_register_debugfs(struct stm32_firewall_controller *rifsc_
if (IS_ERR(root))
return PTR_ERR(root);
- debugfs_create_file("rifsc", 0444, root, rifsc_priv, &stm32_rifsc_conf_dump_fops);
+ file = debugfs_create_file("rifsc", 0444, root, rifsc_priv,
+ &stm32_rifsc_conf_dump_fops);
+ if (IS_ERR(file))
+ return PTR_ERR(file);
- return 0;
+ return devm_add_action_or_reset(rifsc_controller->dev,
+ stm32_rifsc_remove_debugfs, file);
}
#endif /* defined(CONFIG_DEBUG_FS) */
--
2.43.0
More information about the linux-arm-kernel
mailing list