[PATCH 3/4] clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind

From: Guangshuo Li

Date: Thu Nov 26 2026 - 03:26:20 EST


The apmixedsys driver leaves the OF provider and clocks registered
on unbind. The clock table is device-managed, so the provider can
retain a pointer to released storage.

Remove the provider and unregister the PLLs during removal.

This issue was found by our static analysis tool under development.

Fixes: d46adccb7966 ("clk: mediatek: add driver for MT8365 SoC")
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8365-apmixedsys.c b/drivers/clk/mediatek/clk-mt8365-apmixedsys.c
index e331aa28a4bd..386b0c66bf4f 100644
--- a/drivers/clk/mediatek/clk-mt8365-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8365-apmixedsys.c
@@ -141,6 +141,8 @@ static int clk_mt8365_apmixed_probe(struct platform_device *pdev)
if (ret)
goto unregister_plls;

+ platform_set_drvdata(pdev, clk_data);
+
return 0;

unregister_plls:
@@ -149,6 +151,14 @@ static int clk_mt8365_apmixed_probe(struct platform_device *pdev)
return ret;
}

+static void clk_mt8365_apmixed_remove(struct platform_device *pdev)
+{
+ struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+
+ of_clk_del_provider(pdev->dev.of_node);
+ mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
static const struct of_device_id of_match_clk_mt8365_apmixed[] = {
{ .compatible = "mediatek,mt8365-apmixedsys" },
{ /* sentinel */ }
@@ -157,6 +167,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8365_apmixed);

static struct platform_driver clk_mt8365_apmixed_drv = {
.probe = clk_mt8365_apmixed_probe,
+ .remove = clk_mt8365_apmixed_remove,
.driver = {
.name = "clk-mt8365-apmixed",
.of_match_table = of_match_clk_mt8365_apmixed,
--
2.43.0