[PATCH v2] soc: mediatek: mtk-svs: remove the debugfs tree on teardown

Pengpeng Hou pengpeng at iscas.ac.cn
Fri Aug 14 00:51:03 PDT 2026


svs_create_debug_cmds() publishes a debugfs tree whose private data
points at devm-managed platform and bank state. Partial creation failure
and device teardown currently leave entries referring to state that is
about to be released.

Remove the complete tree on partial failure and register a devm action
after successful creation. The debugfs full-proxy lifetime rules keep
active file operations synchronized with removal, and the devm action
runs before the managed SVS state is freed.

Fixes: 13f1bbcfb582 ("soc: mediatek: SVS: add debug commands")
Assisted-by: Codex:gpt-5
Signed-off-by: Pengpeng Hou <pengpeng at iscas.ac.cn>
---
Changes since v1: https://lore.kernel.org/all/20260616151406.92529-1-pengpeng@iscas.ac.cn/
- remove the complete debugfs tree after partial creation failure
- register devm teardown for successful probes
- recheck open-file lifetime against the debugfs full proxy

The debugfs and devm lifetimes were reviewed statically; bind/unbind was
not exercised on MediaTek hardware.

 drivers/soc/mediatek/mtk-svs.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/mediatek/mtk-svs.c b/drivers/soc/mediatek/mtk-svs.c
index 99edecb204f2..7ebc680627c9 100644
--- a/drivers/soc/mediatek/mtk-svs.c
+++ b/drivers/soc/mediatek/mtk-svs.c
@@ -172,6 +172,11 @@ static DEFINE_SPINLOCK(svs_lock);
 	}
 
 #define svs_dentry_data(name)	{__stringify(name), &svs_##name##_debug_fops}
+
+static void svs_remove_debug_cmds(void *data)
+{
+	debugfs_remove(data);
+}
 #endif
 
 /**
@@ -887,7 +892,7 @@ static int svs_create_debug_cmds(struct svs_platform *svsp)
 		if (IS_ERR(file_entry)) {
 			dev_err(svsp->dev, "cannot create %s/%s: %ld\n",
 				d, svs_entries[i].name, PTR_ERR(file_entry));
-			return PTR_ERR(file_entry);
+			goto err_remove_debugfs;
 		}
 	}
 
@@ -901,7 +906,8 @@ static int svs_create_debug_cmds(struct svs_platform *svsp)
 		if (IS_ERR(svsb_dir)) {
 			dev_err(svsp->dev, "cannot create %s/%s: %ld\n",
 				d, svsb->name, PTR_ERR(svsb_dir));
-			return PTR_ERR(svsb_dir);
+			file_entry = svsb_dir;
+			goto err_remove_debugfs;
 		}
 
 		for (i = 0; i < ARRAY_SIZE(svsb_entries); i++) {
@@ -912,12 +918,17 @@ static int svs_create_debug_cmds(struct svs_platform *svsp)
 				dev_err(svsp->dev, "no %s/%s/%s?: %ld\n",
 					d, svsb->name, svsb_entries[i].name,
 					PTR_ERR(file_entry));
-				return PTR_ERR(file_entry);
+				goto err_remove_debugfs;
 			}
 		}
 	}
 
-	return 0;
+	return devm_add_action_or_reset(svsp->dev, svs_remove_debug_cmds,
+					svs_dir);
+
+err_remove_debugfs:
+	debugfs_remove(svs_dir);
+	return PTR_ERR(file_entry);
 }
 #endif /* CONFIG_DEBUG_FS */
 
-- 
2.50.1 (Apple Git-155)




More information about the Linux-mediatek mailing list