soc: amlogic: meson-clk-measure: fix debugfs directory leak on unbind
PATCH 1/1 soc: amlogic: meson-clk-measure: fix debugfs directory leak on unbind
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.
---
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(-)
drivers/soc/amlogic/meson-clk-measure.c +7 -1
@@ -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 = {
Signature · 1 line
2.47.3