[PATCH 1/4] clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind

From: Guangshuo Li

Date: Thu Nov 26 2026 - 03:26:14 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 dividers and PLLs during removal.

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

Fixes: b27284336aa4 ("clk: mediatek: mt8167: Move apmixedsys as platform_driver in new file")
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8167-apmixedsys.c b/drivers/clk/mediatek/clk-mt8167-apmixedsys.c
index fb6c21bbeef8..70fc5e5215e5 100644
--- a/drivers/clk/mediatek/clk-mt8167-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8167-apmixedsys.c
@@ -118,6 +118,8 @@ static int clk_mt8167_apmixed_probe(struct platform_device *pdev)
if (ret)
goto unregister_dividers;

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

unregister_dividers:
@@ -128,6 +130,15 @@ static int clk_mt8167_apmixed_probe(struct platform_device *pdev)
return ret;
}

+static void clk_mt8167_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_dividers(adj_divs, ARRAY_SIZE(adj_divs), clk_data);
+ mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
static const struct of_device_id of_match_clk_mt8167_apmixed[] = {
{ .compatible = "mediatek,mt8167-apmixedsys" },
{ /* sentinel */ }
@@ -136,6 +147,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8167_apmixed);

static struct platform_driver clk_mt8167_apmixed_drv = {
.probe = clk_mt8167_apmixed_probe,
+ .remove = clk_mt8167_apmixed_remove,
.driver = {
.name = "clk-mt8167-apmixed",
.of_match_table = of_match_clk_mt8167_apmixed,
--
2.43.0