mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind
@ 2026-11-26  8:26 Guangshuo Li
  2026-11-26  8:26 ` [PATCH 1/4] clk: mediatek: mt8167: " Guangshuo Li
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-26  8:26 UTC (permalink / raw)
  To: angelogioacchino.delregno, sboyd, bmasney+clk, jbrunet+clk,
	matthias.bgg, wenst, drinkcat, weiyi.lu, msp, fparent
  Cc: linux-clk, linux-mediatek, linux-kernel, linux-arm-kernel

Pair apmixedsys clock registration with removal on four MediaTek SoCs.

Guangshuo Li (4):
  clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind
  clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind
  clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind
  clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind
  2026-11-26  8:26 [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind Guangshuo Li
@ 2026-11-26  8:26 ` Guangshuo Li
  2026-11-26  8:26 ` [PATCH 2/4] clk: mediatek: mt8183: " Guangshuo Li
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-26  8:26 UTC (permalink / raw)
  To: angelogioacchino.delregno, sboyd, bmasney+clk, jbrunet+clk,
	matthias.bgg, wenst, drinkcat, weiyi.lu, msp, fparent
  Cc: linux-clk, linux-mediatek, linux-kernel, linux-arm-kernel

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@mail.sdu.edu.cn>
---
 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/4] clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind
  2026-11-26  8:26 [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind Guangshuo Li
  2026-11-26  8:26 ` [PATCH 1/4] clk: mediatek: mt8167: " Guangshuo Li
@ 2026-11-26  8:26 ` Guangshuo Li
  2026-11-26  8:26 ` [PATCH 3/4] clk: mediatek: mt8365: " Guangshuo Li
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-26  8:26 UTC (permalink / raw)
  To: angelogioacchino.delregno, sboyd, bmasney+clk, jbrunet+clk,
	matthias.bgg, wenst, drinkcat, weiyi.lu, msp, fparent
  Cc: linux-clk, linux-mediatek, linux-kernel, linux-arm-kernel

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 gates and PLLs during removal.

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

Fixes: acddfc2c261b ("clk: mediatek: Add MT8183 clock support")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8183-apmixedsys.c b/drivers/clk/mediatek/clk-mt8183-apmixedsys.c
index 6242d4f5376e..e1fc3f2beafa 100644
--- a/drivers/clk/mediatek/clk-mt8183-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8183-apmixedsys.c
@@ -168,6 +168,8 @@ static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
 	if (ret)
 		goto unregister_gates;
 
+	platform_set_drvdata(pdev, clk_data);
+
 	return 0;
 
 unregister_gates:
@@ -178,6 +180,16 @@ static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void clk_mt8183_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_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks),
+				 clk_data);
+	mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
 static const struct of_device_id of_match_clk_mt8183_apmixed[] = {
 	{ .compatible = "mediatek,mt8183-apmixedsys" },
 	{ /* sentinel */ }
@@ -186,6 +198,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8183_apmixed);
 
 static struct platform_driver clk_mt8183_apmixed_drv = {
 	.probe = clk_mt8183_apmixed_probe,
+	.remove = clk_mt8183_apmixed_remove,
 	.driver = {
 		.name = "clk-mt8183-apmixed",
 		.of_match_table = of_match_clk_mt8183_apmixed,
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/4] clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind
  2026-11-26  8:26 [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind Guangshuo Li
  2026-11-26  8:26 ` [PATCH 1/4] clk: mediatek: mt8167: " Guangshuo Li
  2026-11-26  8:26 ` [PATCH 2/4] clk: mediatek: mt8183: " Guangshuo Li
@ 2026-11-26  8:26 ` Guangshuo Li
  2026-11-26  8:26 ` [PATCH 4/4] clk: mediatek: mt8516: " Guangshuo Li
  2026-11-26  8:30 ` [PATCH 0/4] clk: mediatek: " Chen-Yu Tsai
  4 siblings, 0 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-26  8:26 UTC (permalink / raw)
  To: angelogioacchino.delregno, sboyd, bmasney+clk, jbrunet+clk,
	matthias.bgg, wenst, drinkcat, weiyi.lu, msp, fparent
  Cc: linux-clk, linux-mediatek, linux-kernel, linux-arm-kernel

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@mail.sdu.edu.cn>
---
 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/4] clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind
  2026-11-26  8:26 [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind Guangshuo Li
                   ` (2 preceding siblings ...)
  2026-11-26  8:26 ` [PATCH 3/4] clk: mediatek: mt8365: " Guangshuo Li
@ 2026-11-26  8:26 ` Guangshuo Li
  2026-11-26  8:30 ` [PATCH 0/4] clk: mediatek: " Chen-Yu Tsai
  4 siblings, 0 replies; 6+ messages in thread
From: Guangshuo Li @ 2026-11-26  8:26 UTC (permalink / raw)
  To: angelogioacchino.delregno, sboyd, bmasney+clk, jbrunet+clk,
	matthias.bgg, wenst, drinkcat, weiyi.lu, msp, fparent
  Cc: linux-clk, linux-mediatek, linux-kernel, linux-arm-kernel

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: f419069ad864 ("clk: mediatek: mt8516: Move apmixedsys clock driver to its own file")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
 drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/clk/mediatek/clk-mt8516-apmixedsys.c b/drivers/clk/mediatek/clk-mt8516-apmixedsys.c
index 2a6206cae2f0..abb2a626628c 100644
--- a/drivers/clk/mediatek/clk-mt8516-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8516-apmixedsys.c
@@ -95,6 +95,8 @@ static int clk_mt8516_apmixed_probe(struct platform_device *pdev)
 	if (ret)
 		goto unregister_plls;
 
+	platform_set_drvdata(pdev, clk_data);
+
 	return 0;
 
 unregister_plls:
@@ -103,6 +105,14 @@ static int clk_mt8516_apmixed_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void clk_mt8516_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_mt8516_apmixed[] = {
 	{ .compatible = "mediatek,mt8516-apmixedsys" },
 	{ /* sentinel */ }
@@ -111,6 +121,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8516_apmixed);
 
 static struct platform_driver clk_mt8516_apmixed_drv = {
 	.probe = clk_mt8516_apmixed_probe,
+	.remove = clk_mt8516_apmixed_remove,
 	.driver = {
 		.name = "clk-mt8516-apmixed",
 		.of_match_table = of_match_clk_mt8516_apmixed,
-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind
  2026-11-26  8:26 [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind Guangshuo Li
                   ` (3 preceding siblings ...)
  2026-11-26  8:26 ` [PATCH 4/4] clk: mediatek: mt8516: " Guangshuo Li
@ 2026-11-26  8:30 ` Chen-Yu Tsai
  4 siblings, 0 replies; 6+ messages in thread
From: Chen-Yu Tsai @ 2026-11-26  8:30 UTC (permalink / raw)
  To: Guangshuo Li
  Cc: angelogioacchino.delregno, sboyd, bmasney+clk, jbrunet+clk,
	matthias.bgg, wenst, drinkcat, weiyi.lu, msp, fparent, linux-clk,
	linux-mediatek, linux-kernel, linux-arm-kernel

On Thu, Nov 26, 2026 at 4:27 PM Guangshuo Li
<liguangshuo@mail.sdu.edu.cn> wrote:
>
> Pair apmixedsys clock registration with removal on four MediaTek SoCs.

You are checking the wrong tree.

This series is mostly obsoleted by the following commits:

c9c2fd1a53a4 clk: mediatek: mt8516-apmixedsys: Switch to common
probe/remove helpers
68d1fa487766 clk: mediatek: mt8183: Switch to common probe/remove helpers
9421b0b085c0 clk: mediatek: mt8167-apmixedsys: Switch to common
probe/remove helpers

> Guangshuo Li (4):
>   clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind
>   clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind
>   clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind

This is the only one that applies. But we probably want to convert it to
the common helpers as well.


ChenYu

>   clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind
>
> base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-26  8:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  8:26 [PATCH 0/4] clk: mediatek: Unregister apmixedsys clocks on unbind Guangshuo Li
2026-11-26  8:26 ` [PATCH 1/4] clk: mediatek: mt8167: " Guangshuo Li
2026-11-26  8:26 ` [PATCH 2/4] clk: mediatek: mt8183: " Guangshuo Li
2026-11-26  8:26 ` [PATCH 3/4] clk: mediatek: mt8365: " Guangshuo Li
2026-11-26  8:26 ` [PATCH 4/4] clk: mediatek: mt8516: " Guangshuo Li
2026-11-26  8:30 ` [PATCH 0/4] clk: mediatek: " Chen-Yu Tsai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®