[PATCH] soc: amlogic: meson-clk-measure: fix debugfs directory leak on unbind

Yi Ding posted 1 patch 5 days, 23 hours ago
drivers/soc/amlogic/meson-clk-measure.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
[PATCH] soc: amlogic: meson-clk-measure: fix debugfs directory leak on unbind
Posted by Yi Ding 5 days, 23 hours ago
meson_msr_probe() creates the "meson-clk-msr" debugfs directory (and its
"clks" subdirectory) but keeps the dentry only in a local variable, and
the driver has no remove callback. As it is registered with
module_platform_driver(), unbinding or unloading the driver leaks the
whole debugfs tree, and a subsequent probe then collides with the
already-existing "meson-clk-msr" directory.

Register a devm action that calls debugfs_remove_recursive() on the root
dentry when the device is unbound, tearing down the directory, its "clks"
subdirectory and all files.

Fixes: 2b45ebef39a2 ("soc: amlogic: Add Meson Clock Measure driver")
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Yi Ding <yi.s.ding@gmail.com>
---
Reproduced on an ODROID-N2 (Amlogic S922X, G12B), v6.18: the
"meson-clk-msr" debugfs directory survives an unbind, and rebinding the
device then warns:

  # echo ffd18000.clock-measure > /sys/bus/platform/drivers/meson_msr/unbind
  # echo ffd18000.clock-measure > /sys/bus/platform/drivers/meson_msr/bind
  debugfs: 'meson-clk-msr' already exists in '/'

 drivers/soc/amlogic/meson-clk-measure.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/amlogic/meson-clk-measure.c b/drivers/soc/amlogic/meson-clk-measure.c
index d862e30a2..1bcaac7b7 100644
--- a/drivers/soc/amlogic/meson-clk-measure.c
+++ b/drivers/soc/amlogic/meson-clk-measure.c
@@ -902,6 +902,11 @@ static struct regmap_config meson_clk_msr_regmap_config = {
 	.reg_stride = 4,
 };
 
+static void meson_msr_debugfs_remove(void *data)
+{
+	debugfs_remove_recursive(data);
+}
+
 static int meson_msr_probe(struct platform_device *pdev)
 {
 	const struct meson_msr_data *match_data;
@@ -967,7 +972,8 @@ static int meson_msr_probe(struct platform_device *pdev)
 				    &priv->data.msr_table[i], &clk_msr_fops);
 	}
 
-	return 0;
+	return devm_add_action_or_reset(&pdev->dev, meson_msr_debugfs_remove,
+					root);
 }
 
 static const struct msr_reg_offset msr_reg_offset = {
-- 
2.47.3