* [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks
@ 2026-10-13 15:16 Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 01/35] clk: mediatek: mt2712: Fix memory leak on module removal Akari Tsuyukusa
` (34 more replies)
0 siblings, 35 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:16 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
This series migrates most MediaTek clock drivers to the common
probe/remove helpers provided by the MTK clock framework.
Key changes:
- Fix memory leaks on module removal caused by missing
platform_set_drvdata() calls (patches 1-6).
- Add missing MODULE_DEVICE_TABLE() (patches 7, 8).
- Add missing support for cpumux, PLL, FHCTL, and child-device
population to the common helpers (patches 12-15).
- Convert all compatible clock drivers to use struct mtk_clk_desc
and mtk_clk_simple_probe/remove (patches 16-35).
The memory leak and MODULE_DEVICE_TABLE() fixes are split from the
migration patches to allow backporting to stable.
Drivers not converted:
- MT6765 apmixedsys: requires direct register init.
- MT6795 apmixedsys: uses mtk_clk_register_ref2usb_tx().
- MT7629 eth/sgmiisys: uses a hacked probe sequence (multi-instance
sgmii gates).
- MT8173 apmixedsys: uses mtk_clk_register_ref2usb_tx() and custom
divider registration.
- MT8188/MT8195 topckgen: call devm_clk_hw_register_mux() and register
a notifier.
- MT8196 vlpckgen: requires direct register init.
- MT8365 apmixedsys: uses devm_clk_hw_register_gate().
Patches 1-6 are based on
"[PATCH v2 0/6] clk: mediatek: fix memory leak on module removal"
(In addition fixed a compilation error in mt8173-infracfg)
https://lore.kernel.org/linux-mediatek/20260707074839.240676-1-akkun11.open@gmail.com/
Patch 5 fixes the same issue mentioned below
"[PATCH] clk: mediatek: clk-mt8173-apmixedsys: Invoke platform_set_drvdata on probe"
https://lore.kernel.org/linux-mediatek/20261010160134.112136-1-l.scorcia@gmail.com/
Patch 12 is based on
"[PATCH 1/3] clk: mediatek: clk-mtk: Add cpumux support to common probe/remove helpers"
https://lore.kernel.org/lkml/20260304181024.738391-1-akkun11.open@gmail.com/
Changes in v2:
- Add two new fixes "Fix index in composite clock unwind path" and
"Fix memory leak in mtk_clk_register_gate()".
- Add new refactor "return 0 instead of r in __mtk_clk_simple_probe()"
- Fix missing `.data = &apmixed_desc` in the MT8167 and MT8195
apmixedsys drivers.
- Fix PLL registration and unregistration when
CONFIG_COMMON_CLK_MEDIATEK_FHCTL is disabled.
- Fix child-device population logic.
- Clarify the rationale in the SoC conversion commit messages.
- Minor fixes to several commit messages.
- Rebased onto `24a19b953e2a ("Linux 7.3-rc7")`
from `075b74841bd0 ("Linux 7.2-rc6")`
Link to v1:
https://lore.kernel.org/linux-mediatek/20260803141659.559129-1-akkun11.open@gmail.com/T/
Akari Tsuyukusa (35):
clk: mediatek: mt2712: Fix memory leak on module removal
clk: mediatek: mt6795: Fix memory leak on module removal
clk: mediatek: mt7622: Fix memory leak on module removal
clk: mediatek: mt8135: Fix memory leak on module removal
clk: mediatek: mt8173: Fix memory leak on module removal
clk: mediatek: mt8192: Fix memory leak on module removal
clk: mediatek: mt6735: Add missing MODULE_DEVICE_TABLE()
clk: mediatek: mt7988-apmixed: Add missing MODULE_DEVICE_TABLE()
clk: mediatek: Fix index in composite clock unwind path
clk: mediatek: Fix memory leak in mtk_clk_register_gate()
clk: mediatek: return 0 instead of r in __mtk_clk_simple_probe()
clk: mediatek: Add cpumux support to common probe/remove helpers
clk: mediatek: Add PLL support to common probe/remove helpers
clk: mediatek: Add child-device population to probe/remove helpers
clk: mediatek: Add FHCTL support to common probe/remove helpers
clk: mediatek: mt2701: Switch to common probe/remove helpers
clk: mediatek: mt2712-apmixedsys: Switch to common probe/remove
helpers
clk: mediatek: mt6735-apmixedsys: Switch to common probe/remove
helpers
clk: mediatek: mt6779: Switch to common probe/remove helpers
clk: mediatek: mt6795: Switch to common probe/remove helpers
clk: mediatek: mt6797: Switch to common probe/remove helpers
clk: mediatek: mt7622: Switch to common probe/remove helpers
clk: mediatek: mt7981-apmixed: Switch to common probe/remove helpers
clk: mediatek: mt7986-apmixed: Switch to common probe/remove helpers
clk: mediatek: mt7988-apmixed: Switch to common probe/remove helpers
clk: mediatek: mt8135-apmixedsys: Switch to common probe/remove
helpers
clk: mediatek: mt8167-apmixedsys: Switch to common probe/remove
helpers
clk: mediatek: mt8173-infracfg: Switch to common probe/remove helpers
clk: mediatek: mt8183: Switch to common probe/remove helpers
clk: mediatek: mt8186-apmixedsys: Switch to common probe/remove
helpers
clk: mediatek: mt8188-apmixedsys: Switch to common probe/remove
helpers
clk: mediatek: mt8192: Switch to common probe/remove helpers
clk: mediatek: mt8195: Switch to common probe/remove helpers
clk: mediatek: mt8196: Switch to common probe/remove helpers
clk: mediatek: mt8516-apmixedsys: Switch to common probe/remove
helpers
drivers/clk/mediatek/Kconfig | 34 +--
drivers/clk/mediatek/clk-gate.c | 4 +-
drivers/clk/mediatek/clk-mt2701-aud.c | 35 +--
drivers/clk/mediatek/clk-mt2701.c | 233 +++++--------------
drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 48 +---
drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 51 +---
drivers/clk/mediatek/clk-mt6735-imgsys.c | 1 +
drivers/clk/mediatek/clk-mt6735-mfgcfg.c | 1 +
drivers/clk/mediatek/clk-mt6779.c | 124 ++--------
drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +
drivers/clk/mediatek/clk-mt6795-infracfg.c | 70 +-----
drivers/clk/mediatek/clk-mt6795-pericfg.c | 71 +-----
drivers/clk/mediatek/clk-mt6797.c | 140 ++---------
drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 60 +----
drivers/clk/mediatek/clk-mt7622-aud.c | 35 +--
drivers/clk/mediatek/clk-mt7622-infracfg.c | 70 +-----
drivers/clk/mediatek/clk-mt7981-apmixed.c | 37 +--
drivers/clk/mediatek/clk-mt7986-apmixed.c | 37 +--
drivers/clk/mediatek/clk-mt7988-apmixed.c | 40 +---
drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 48 +---
drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 58 ++---
drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 +
drivers/clk/mediatek/clk-mt8173-infracfg.c | 98 ++------
drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 51 +---
drivers/clk/mediatek/clk-mt8183-audio.c | 26 +--
drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 59 +----
drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 60 +----
drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 67 ++----
drivers/clk/mediatek/clk-mt8192-aud.c | 26 +--
drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 75 ++----
drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 49 +---
drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 67 +-----
drivers/clk/mediatek/clk-mt8196-mcu.c | 96 +++-----
drivers/clk/mediatek/clk-mt8196-mfg.c | 84 ++-----
drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 42 +---
drivers/clk/mediatek/clk-mtk.c | 90 ++++++-
drivers/clk/mediatek/clk-mtk.h | 12 +
37 files changed, 496 insertions(+), 1607 deletions(-)
--
2.56.0
^ permalink raw reply [flat|nested] 50+ messages in thread
* [PATCH v2 01/35] clk: mediatek: mt2712: Fix memory leak on module removal
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 02/35] clk: mediatek: mt6795: " Akari Tsuyukusa
` (33 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable,
Brian Masney
clk_mt2712_apmixed_probe() in clk-mt2712-apmixedsys.c does not call
platform_set_drvdata(), but clk_mt2712_apmixed_remove() callback calls
platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to
calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Fixes: c6368ce86435 ("clk: mediatek: mt2712-apmixedsys: Add .remove() callback for module build")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
---
Changes in v2:
- Capitalize the first letter of the commit message: "fix" -> "Fix"
---
drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt2712-apmixedsys.c b/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
index 54b18e9f83f8..087cf574bcdc 100644
--- a/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
@@ -129,6 +129,8 @@ static int clk_mt2712_apmixed_probe(struct platform_device *pdev)
goto unregister_plls;
}
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_plls:
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 02/35] clk: mediatek: mt6795: Fix memory leak on module removal
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 01/35] clk: mediatek: mt2712: Fix memory leak on module removal Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:36 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 03/35] clk: mediatek: mt7622: " Akari Tsuyukusa
` (32 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable,
Brian Masney
clk-mt6795-apmixedsys.c, clk-mt6795-infracfg.c and clk-mt6795-pericfg.c
do not call platform_set_drvdata() during their driver probe callback,
but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to
calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Fixes: 0d363282bb0c ("clk: mediatek: Add MediaTek Helio X10 MT6795 clock drivers")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
---
Changes in v2:
- Capitalize the first letter of the commit message: "fix" -> "Fix"
---
drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 ++
drivers/clk/mediatek/clk-mt6795-infracfg.c | 2 ++
drivers/clk/mediatek/clk-mt6795-pericfg.c | 2 ++
3 files changed, 6 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt6795-apmixedsys.c b/drivers/clk/mediatek/clk-mt6795-apmixedsys.c
index 123d5d7fea85..239a3f5e1760 100644
--- a/drivers/clk/mediatek/clk-mt6795-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt6795-apmixedsys.c
@@ -175,6 +175,8 @@ static int clk_mt6795_apmixed_probe(struct platform_device *pdev)
dev_dbg(dev, "Performing initial setup for MD1\n");
clk_mt6795_apmixed_setup_md1(base);
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_ref2usb:
diff --git a/drivers/clk/mediatek/clk-mt6795-infracfg.c b/drivers/clk/mediatek/clk-mt6795-infracfg.c
index e4559569f5b0..914bb069aa85 100644
--- a/drivers/clk/mediatek/clk-mt6795-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt6795-infracfg.c
@@ -116,6 +116,8 @@ static int clk_mt6795_infracfg_probe(struct platform_device *pdev)
if (ret)
goto unregister_cpumuxes;
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_cpumuxes:
diff --git a/drivers/clk/mediatek/clk-mt6795-pericfg.c b/drivers/clk/mediatek/clk-mt6795-pericfg.c
index d48240eb2a67..27d0ef7d7b2f 100644
--- a/drivers/clk/mediatek/clk-mt6795-pericfg.c
+++ b/drivers/clk/mediatek/clk-mt6795-pericfg.c
@@ -125,6 +125,8 @@ static int clk_mt6795_pericfg_probe(struct platform_device *pdev)
if (ret)
goto unregister_composites;
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_composites:
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 03/35] clk: mediatek: mt7622: Fix memory leak on module removal
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 01/35] clk: mediatek: mt2712: Fix memory leak on module removal Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 02/35] clk: mediatek: mt6795: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:34 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 04/35] clk: mediatek: mt8135: " Akari Tsuyukusa
` (31 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable,
Brian Masney
clk-mt7622-apmixedsys.c and clk-mt7622-infracfg.c do not call
platform_set_drvdata() during their driver probe callback,
but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Fixes: c50e2ea6507b ("clk: mediatek: mt7622-apmixedsys: Add .remove() callback for module build")
Fixes: 838b86331c5e ("clk: mediatek: mt7622: Move infracfg to clk-mt7622-infracfg.c")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
---
Changes in v2:
- Capitalize the first letter of the commit message: "fix" -> "Fix"
---
drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 ++
drivers/clk/mediatek/clk-mt7622-infracfg.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt7622-apmixedsys.c b/drivers/clk/mediatek/clk-mt7622-apmixedsys.c
index 8a29eaab0cfc..fae8abda14b3 100644
--- a/drivers/clk/mediatek/clk-mt7622-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt7622-apmixedsys.c
@@ -109,6 +109,8 @@ static int clk_mt7622_apmixed_probe(struct platform_device *pdev)
if (ret)
goto unregister_gates;
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_gates:
diff --git a/drivers/clk/mediatek/clk-mt7622-infracfg.c b/drivers/clk/mediatek/clk-mt7622-infracfg.c
index cfdf3b07c3e0..cec19447d637 100644
--- a/drivers/clk/mediatek/clk-mt7622-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt7622-infracfg.c
@@ -90,6 +90,8 @@ static int clk_mt7622_infracfg_probe(struct platform_device *pdev)
if (ret)
goto unregister_cpumuxes;
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_cpumuxes:
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 04/35] clk: mediatek: mt8135: Fix memory leak on module removal
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (2 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 03/35] clk: mediatek: mt7622: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 05/35] clk: mediatek: mt8173: " Akari Tsuyukusa
` (30 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable,
Brian Masney
clk_mt8135_apmixed_probe() in clk-mt8135-apmixedsys.c does not call
platform_set_drvdata(), but clk_mt8135_apmixed_remove() callback calls
platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Fixes: 54b7026f011e ("clk: mediatek: mt8135-apmixedsys: Convert to platform_driver and module")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
---
Changes in v2:
- Capitalize the first letter of the commit message: "fix" -> "Fix"
---
drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt8135-apmixedsys.c b/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
index 19e4ee489ec3..e3b7dc13b458 100644
--- a/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
@@ -66,6 +66,8 @@ static int clk_mt8135_apmixed_probe(struct platform_device *pdev)
if (ret)
goto unregister_plls;
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_plls:
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 05/35] clk: mediatek: mt8173: Fix memory leak on module removal
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (3 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 04/35] clk: mediatek: mt8135: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 06/35] clk: mediatek: mt8192: " Akari Tsuyukusa
` (29 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable
clk-mt8173-apmixedsys.c and clk-mt8173-infracfg.c do not call
platform_set_drvdata() during their driver probe callback,
but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Fixes: 4c02c9af3cb9 ("clk: mediatek: mt8173: Break down clock drivers and allow module build")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Capitalize the first letter of the commit message: "fix" -> "Fix"
---
drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 2 ++
drivers/clk/mediatek/clk-mt8173-infracfg.c | 2 ++
2 files changed, 4 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt8173-apmixedsys.c b/drivers/clk/mediatek/clk-mt8173-apmixedsys.c
index d7d416172ab3..65dc4489a09c 100644
--- a/drivers/clk/mediatek/clk-mt8173-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8173-apmixedsys.c
@@ -179,6 +179,8 @@ static int clk_mt8173_apmixed_probe(struct platform_device *pdev)
if (r)
goto unregister_ref2usb;
+ platform_set_drvdata(pdev, clk_data);
+
return 0;
unregister_ref2usb:
diff --git a/drivers/clk/mediatek/clk-mt8173-infracfg.c b/drivers/clk/mediatek/clk-mt8173-infracfg.c
index fa2d1d557e04..9b8c35897789 100644
--- a/drivers/clk/mediatek/clk-mt8173-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt8173-infracfg.c
@@ -128,6 +128,8 @@ static int clk_mt8173_infracfg_probe(struct platform_device *pdev)
if (r)
goto unregister_clk_hw;
+ platform_set_drvdata(pdev, infra_clk_data);
+
return 0;
unregister_clk_hw:
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 06/35] clk: mediatek: mt8192: Fix memory leak on module removal
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (4 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 05/35] clk: mediatek: mt8173: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 07/35] clk: mediatek: mt6735: Add missing MODULE_DEVICE_TABLE() Akari Tsuyukusa
` (28 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable,
Brian Masney
clk_mt8192_apmixed_probe() in clk-mt8192-apmixedsys.c does not call
platform_set_drvdata(), but clk_mt8192_apmixed_remove() callback calls
platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.
Fix this by calling platform_set_drvdata() during probe.
Fixes: 124294ff468f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
---
Changes in v2:
- Capitalize the first letter of the commit message: "fix" -> "Fix"
---
drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt8192-apmixedsys.c b/drivers/clk/mediatek/clk-mt8192-apmixedsys.c
index b0563a285bd6..e6ac40e2f12d 100644
--- a/drivers/clk/mediatek/clk-mt8192-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8192-apmixedsys.c
@@ -176,6 +176,8 @@ static int clk_mt8192_apmixed_probe(struct platform_device *pdev)
if (r)
goto unregister_gates;
+ platform_set_drvdata(pdev, clk_data);
+
return r;
unregister_gates:
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 07/35] clk: mediatek: mt6735: Add missing MODULE_DEVICE_TABLE()
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (5 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 06/35] clk: mediatek: mt8192: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 08/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
` (27 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable
Add MODULE_DEVICE_TABLE() to the MT6735 clock drivers (imgsys, mfgcfg)
to export the Device Tree matching tables. This is required so that the
clock drivers can be automatically loaded when built as modules.
Fixes: 0bd9b1211f74 ("clk: mediatek: Add drivers for MT6735 syscon clock and reset controllers")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Removed wrong mentions of vdecsys, vencsys from the commit message.
---
drivers/clk/mediatek/clk-mt6735-imgsys.c | 1 +
drivers/clk/mediatek/clk-mt6735-mfgcfg.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt6735-imgsys.c b/drivers/clk/mediatek/clk-mt6735-imgsys.c
index c564f8f72432..813241d526cf 100644
--- a/drivers/clk/mediatek/clk-mt6735-imgsys.c
+++ b/drivers/clk/mediatek/clk-mt6735-imgsys.c
@@ -41,6 +41,7 @@ static const struct of_device_id of_match_mt6735_imgsys[] = {
{ .compatible = "mediatek,mt6735-imgsys", .data = &imgsys_clks },
{ /* sentinel */ }
};
+MODULE_DEVICE_TABLE(of, of_match_mt6735_imgsys);
static struct platform_driver clk_mt6735_imgsys = {
.probe = mtk_clk_simple_probe,
diff --git a/drivers/clk/mediatek/clk-mt6735-mfgcfg.c b/drivers/clk/mediatek/clk-mt6735-mfgcfg.c
index 1f5aedddf209..8a18ee244a4d 100644
--- a/drivers/clk/mediatek/clk-mt6735-mfgcfg.c
+++ b/drivers/clk/mediatek/clk-mt6735-mfgcfg.c
@@ -45,6 +45,7 @@ static const struct of_device_id of_match_mt6735_mfgcfg[] = {
{ .compatible = "mediatek,mt6735-mfgcfg", .data = &mfgcfg_clks },
{ /* sentinel */ }
};
+MODULE_DEVICE_TABLE(of, of_match_mt6735_mfgcfg);
static struct platform_driver clk_mt6735_mfgcfg = {
.probe = mtk_clk_simple_probe,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 08/35] clk: mediatek: mt7988-apmixed: Add missing MODULE_DEVICE_TABLE()
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (6 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 07/35] clk: mediatek: mt6735: Add missing MODULE_DEVICE_TABLE() Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 09/35] clk: mediatek: Fix index in composite clock unwind path Akari Tsuyukusa
` (26 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable
Add MODULE_DEVICE_TABLE() to the MT7988 apmixedsys clock driver to
export the Device Tree matching tables.
This is required so that the clock drivers can be automatically loaded
when built as modules.
Fixes: 4b4719437d85 ("clk: mediatek: add drivers for MT7988 SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
No changes in v2.
---
drivers/clk/mediatek/clk-mt7988-apmixed.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/clk/mediatek/clk-mt7988-apmixed.c b/drivers/clk/mediatek/clk-mt7988-apmixed.c
index 416a4b88d100..24f4e7b87a31 100644
--- a/drivers/clk/mediatek/clk-mt7988-apmixed.c
+++ b/drivers/clk/mediatek/clk-mt7988-apmixed.c
@@ -75,6 +75,7 @@ static const struct of_device_id of_match_clk_mt7988_apmixed[] = {
{ .compatible = "mediatek,mt7988-apmixedsys" },
{ /* sentinel */ }
};
+MODULE_DEVICE_TABLE(of, of_match_clk_mt7988_apmixed);
static int clk_mt7988_apmixed_probe(struct platform_device *pdev)
{
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 09/35] clk: mediatek: Fix index in composite clock unwind path
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (7 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 08/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:49 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 10/35] clk: mediatek: Fix memory leak in mtk_clk_register_gate() Akari Tsuyukusa
` (25 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable
When mtk_clk_register_composites() fails to register a clock, it
unwinds previously processed entries. The unwind guard incorrectly
checks clk_data->hws[mcs->id], which refers to the first descriptor,
instead of the current descriptor.
This can cause the unwind to skip entries that need unregistering
or pass an invalid pointer to mtk_clk_unregister_composite().
Check clk_data->hws[mc->id] instead.
Fixes: 3c3ba2ab0226 ("clk: mediatek: mtk: Implement error handling in register APIs")
Assisted-by: LLM
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Newly introduced in v2.
---
drivers/clk/mediatek/clk-mtk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 3dfdd3a422f8..0b10a4b14a6e 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -363,7 +363,7 @@ int mtk_clk_register_composites(struct device *dev,
while (--i >= 0) {
const struct mtk_composite *mc = &mcs[i];
- if (IS_ERR_OR_NULL(clk_data->hws[mcs->id]))
+ if (IS_ERR_OR_NULL(clk_data->hws[mc->id]))
continue;
mtk_clk_unregister_composite(clk_data->hws[mc->id]);
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 10/35] clk: mediatek: Fix memory leak in mtk_clk_register_gate()
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (8 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 09/35] clk: mediatek: Fix index in composite clock unwind path Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 11/35] clk: mediatek: return 0 instead of r in __mtk_clk_simple_probe() Akari Tsuyukusa
` (24 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa, stable
When a gate uses the hardware voter ops but the hardware voter
regmap is missing (e.g. the "mediatek,hardware-voter" phandle is
absent from the device tree), mtk_clk_register_gate() returns an
error without freeing the mtk_clk_gate structure allocated earlier.
Free cg on this error path.
Fixes: e504d3bdb3d0 ("clk: mediatek: clk-gate: Add ops for gates with HW voter")
Assisted-by: LLM
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Newly introduced in v2.
---
drivers/clk/mediatek/clk-gate.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c
index bd2fcd489a3f..0b1389993751 100644
--- a/drivers/clk/mediatek/clk-gate.c
+++ b/drivers/clk/mediatek/clk-gate.c
@@ -221,10 +221,12 @@ static struct clk_hw *mtk_clk_register_gate(struct device *dev,
init.parent_names = gate->parent_name ? &gate->parent_name : NULL;
init.num_parents = gate->parent_name ? 1 : 0;
init.ops = gate->ops;
- if (mtk_cg_uses_hwv(init.ops) && !regmap_hwv)
+ if (mtk_cg_uses_hwv(init.ops) && !regmap_hwv) {
+ kfree(cg);
return dev_err_ptr_probe(
dev, -ENXIO,
"regmap not found for hardware voter clocks\n");
+ }
cg->regmap = regmap;
cg->regmap_hwv = regmap_hwv;
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 11/35] clk: mediatek: return 0 instead of r in __mtk_clk_simple_probe()
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (9 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 10/35] clk: mediatek: Fix memory leak in mtk_clk_register_gate() Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 12/35] clk: mediatek: Add cpumux support to common probe/remove helpers Akari Tsuyukusa
` (23 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
In the successful path of __mtk_clk_simple_probe(), r is always 0.
"return r" is meaningless and confusing, so use "return 0" instead.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Newly introduced in v2.
---
drivers/clk/mediatek/clk-mtk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 0b10a4b14a6e..11741cc6ccc7 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -592,7 +592,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
if (mcd->need_runtime_pm)
pm_runtime_put(&pdev->dev);
- return r;
+ return 0;
unregister_clks:
if (mcd->clks)
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 12/35] clk: mediatek: Add cpumux support to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (10 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 11/35] clk: mediatek: return 0 instead of r in __mtk_clk_simple_probe() Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 13/35] clk: mediatek: Add PLL " Akari Tsuyukusa
` (22 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
Extend __mtk_clk_simple_probe() and __mtk_clk_simple_remove() to
support cpumux clocks. This reduces boilerplate code in drivers for
SoCs that require cpumux registration, such as mt6795-infracfg.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
---
No changes in v2.
---
drivers/clk/mediatek/clk-mtk.c | 18 +++++++++++++++++-
drivers/clk/mediatek/clk-mtk.h | 2 ++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 11741cc6ccc7..004098a839b2 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -19,6 +19,7 @@
#include "clk-mtk.h"
#include "clk-gate.h"
#include "clk-mux.h"
+#include "clk-cpumux.h"
const struct mtk_gate_regs cg_regs_dummy = { 0, 0, 0 };
EXPORT_SYMBOL_GPL(cg_regs_dummy);
@@ -513,6 +514,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
num_clks = mcd->num_clks + mcd->num_composite_clks;
num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
num_clks += mcd->num_mux_clks + mcd->num_divider_clks;
+ num_clks += mcd->num_cpumuxes;
clk_data = mtk_alloc_clk_data(num_clks);
if (!clk_data) {
@@ -542,6 +544,13 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
goto unregister_factors;
}
+ if (mcd->cpumuxes) {
+ r = mtk_clk_register_cpumuxes(&pdev->dev, node, mcd->cpumuxes,
+ mcd->num_cpumuxes, clk_data);
+ if (r)
+ goto unregister_muxes;
+ }
+
if (mcd->composite_clks) {
/* We don't check composite_lock because it's optional */
r = mtk_clk_register_composites(&pdev->dev,
@@ -549,7 +558,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
mcd->num_composite_clks,
base, mcd->clk_lock, clk_data);
if (r)
- goto unregister_muxes;
+ goto unregister_cpumuxes;
}
if (mcd->divider_clks) {
@@ -605,6 +614,10 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
if (mcd->composite_clks)
mtk_clk_unregister_composites(mcd->composite_clks,
mcd->num_composite_clks, clk_data);
+unregister_cpumuxes:
+ if (mcd->cpumuxes)
+ mtk_clk_unregister_cpumuxes(mcd->cpumuxes,
+ mcd->num_cpumuxes, clk_data);
unregister_muxes:
if (mcd->mux_clks)
mtk_clk_unregister_muxes(mcd->mux_clks,
@@ -643,6 +656,9 @@ static void __mtk_clk_simple_remove(struct platform_device *pdev,
if (mcd->composite_clks)
mtk_clk_unregister_composites(mcd->composite_clks,
mcd->num_composite_clks, clk_data);
+ if (mcd->cpumuxes)
+ mtk_clk_unregister_cpumuxes(mcd->cpumuxes,
+ mcd->num_cpumuxes, clk_data);
if (mcd->mux_clks)
mtk_clk_unregister_muxes(mcd->mux_clks,
mcd->num_mux_clks, clk_data);
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 5417b9264e6d..02fab4b166f2 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -252,6 +252,8 @@ struct mtk_clk_desc {
size_t num_factor_clks;
const struct mtk_mux *mux_clks;
size_t num_mux_clks;
+ const struct mtk_composite *cpumuxes;
+ size_t num_cpumuxes;
const struct mtk_clk_rst_desc *rst_desc;
spinlock_t *clk_lock;
bool shared_io;
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 13/35] clk: mediatek: Add PLL support to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (11 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 12/35] clk: mediatek: Add cpumux support to common probe/remove helpers Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:58 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 14/35] clk: mediatek: Add child-device population to " Akari Tsuyukusa
` (21 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
Extend __mtk_clk_simple_probe() and __mtk_clk_simple_remove() to
support PLLs. This reduces boilerplate code in apmixedsys drivers.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
No changes in v2.
---
drivers/clk/mediatek/clk-mtk.c | 19 ++++++++++++++++---
drivers/clk/mediatek/clk-mtk.h | 3 +++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 004098a839b2..e06cd40d995a 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -20,6 +20,7 @@
#include "clk-gate.h"
#include "clk-mux.h"
#include "clk-cpumux.h"
+#include "clk-pll.h"
const struct mtk_gate_regs cg_regs_dummy = { 0, 0, 0 };
EXPORT_SYMBOL_GPL(cg_regs_dummy);
@@ -486,7 +487,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
}
/* Composite and divider clocks needs us to pass iomem pointer */
- if (mcd->composite_clks || mcd->divider_clks) {
+ if (mcd->composite_clks || mcd->divider_clks || mcd->plls) {
if (!mcd->shared_io)
base = devm_platform_ioremap_resource(pdev, 0);
else
@@ -514,7 +515,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
num_clks = mcd->num_clks + mcd->num_composite_clks;
num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
num_clks += mcd->num_mux_clks + mcd->num_divider_clks;
- num_clks += mcd->num_cpumuxes;
+ num_clks += mcd->num_cpumuxes + mcd->num_plls;
clk_data = mtk_alloc_clk_data(num_clks);
if (!clk_data) {
@@ -522,11 +523,18 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
goto free_base;
}
+ if (mcd->plls) {
+ r = mtk_clk_register_plls(&pdev->dev, mcd->plls,
+ mcd->num_plls, clk_data);
+ if (r)
+ goto free_data;
+ }
+
if (mcd->fixed_clks) {
r = mtk_clk_register_fixed_clks(mcd->fixed_clks,
mcd->num_fixed_clks, clk_data);
if (r)
- goto free_data;
+ goto unregister_plls;
}
if (mcd->factor_clks) {
@@ -630,6 +638,9 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
if (mcd->fixed_clks)
mtk_clk_unregister_fixed_clks(mcd->fixed_clks,
mcd->num_fixed_clks, clk_data);
+unregister_plls:
+ if (mcd->plls)
+ mtk_clk_unregister_plls(mcd->plls, mcd->num_plls, clk_data);
free_data:
mtk_free_clk_data(clk_data);
free_base:
@@ -668,6 +679,8 @@ static void __mtk_clk_simple_remove(struct platform_device *pdev,
if (mcd->fixed_clks)
mtk_clk_unregister_fixed_clks(mcd->fixed_clks,
mcd->num_fixed_clks, clk_data);
+ if (mcd->plls)
+ mtk_clk_unregister_plls(mcd->plls, mcd->num_plls, clk_data);
mtk_free_clk_data(clk_data);
}
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 02fab4b166f2..b6504b3e77ed 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -23,6 +23,7 @@
#define MTK_WAIT_HWV_DONE_US 30
struct platform_device;
+struct mtk_pll_data;
/*
* We need the clock IDs to start from zero but to maintain devicetree
@@ -254,6 +255,8 @@ struct mtk_clk_desc {
size_t num_mux_clks;
const struct mtk_composite *cpumuxes;
size_t num_cpumuxes;
+ const struct mtk_pll_data *plls;
+ size_t num_plls;
const struct mtk_clk_rst_desc *rst_desc;
spinlock_t *clk_lock;
bool shared_io;
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 14/35] clk: mediatek: Add child-device population to probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (12 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 13/35] clk: mediatek: Add PLL " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:10 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 15/35] clk: mediatek: Add FHCTL support to common " Akari Tsuyukusa
` (20 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
MediaTek audio clock drivers call devm_of_platform_populate() after
mtk_clk_simple_probe(). Extend __mtk_clk_simple_probe() to run
of_platform_populate() when the new 'populate_children' flag is set,
reducing boilerplate.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Use non "devm_" helper (based on Chen-Yu Tsai's review)
---
drivers/clk/mediatek/clk-mtk.c | 18 +++++++++++++++++-
drivers/clk/mediatek/clk-mtk.h | 1 +
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index e06cd40d995a..1172e76516c0 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -12,6 +12,7 @@
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
@@ -603,7 +604,16 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
r = mtk_register_reset_controller_with_dev(&pdev->dev,
mcd->rst_desc);
if (r)
- goto unregister_clks;
+ goto unregister_provider;
+ }
+
+ if (mcd->populate_children) {
+ r = of_platform_populate(pdev->dev.of_node, NULL, NULL,
+ &pdev->dev);
+ if (r) {
+ of_platform_depopulate(&pdev->dev);
+ goto unregister_provider;
+ }
}
if (mcd->need_runtime_pm)
@@ -611,6 +621,9 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
return 0;
+unregister_provider:
+ of_clk_del_provider(node);
+ platform_set_drvdata(pdev, NULL);
unregister_clks:
if (mcd->clks)
mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
@@ -658,6 +671,9 @@ static void __mtk_clk_simple_remove(struct platform_device *pdev,
struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev);
+ if (mcd->populate_children)
+ of_platform_depopulate(&pdev->dev);
+
of_clk_del_provider(node);
if (mcd->clks)
mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index b6504b3e77ed..11939e3e0b38 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -265,6 +265,7 @@ struct mtk_clk_desc {
unsigned int mfg_clk_idx;
bool need_runtime_pm;
+ bool populate_children;
};
int mtk_clk_pdev_probe(struct platform_device *pdev);
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 15/35] clk: mediatek: Add FHCTL support to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (13 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 14/35] clk: mediatek: Add child-device population to " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:09 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 16/35] clk: mediatek: mt2701: Switch " Akari Tsuyukusa
` (19 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
Extend __mtk_clk_simple_probe() and __mtk_clk_simple_remove() to
support FHCTL.
This reduces boilerplate code in apmixedsys drivers with FHCTL support.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Handle PLL registration and unregistration correctly when
CONFIG_COMMON_CLK_MEDIATEK_FHCTL is disabled.
- Use "FHCTL" insted of "pllfh" in the commit message.
---
drivers/clk/mediatek/clk-mtk.c | 43 ++++++++++++++++++++++++++++++----
drivers/clk/mediatek/clk-mtk.h | 6 +++++
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 1172e76516c0..8fa81a8671ad 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -23,6 +23,10 @@
#include "clk-cpumux.h"
#include "clk-pll.h"
+#if IS_ENABLED(CONFIG_COMMON_CLK_MEDIATEK_FHCTL)
+#include "clk-fhctl.h"
+#endif
+
const struct mtk_gate_regs cg_regs_dummy = { 0, 0, 0 };
EXPORT_SYMBOL_GPL(cg_regs_dummy);
@@ -525,8 +529,18 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
}
if (mcd->plls) {
- r = mtk_clk_register_plls(&pdev->dev, mcd->plls,
+#if IS_ENABLED(CONFIG_COMMON_CLK_MEDIATEK_FHCTL)
+ if (mcd->fhctl_node) {
+ fhctl_parse_dt(mcd->fhctl_node, mcd->pllfhs,
+ mcd->num_pllfhs);
+ r = mtk_clk_register_pllfhs(&pdev->dev, mcd->plls,
+ mcd->num_plls, mcd->pllfhs,
+ mcd->num_pllfhs, clk_data);
+ } else
+#endif
+ r = mtk_clk_register_plls(&pdev->dev, mcd->plls,
mcd->num_plls, clk_data);
+
if (r)
goto free_data;
}
@@ -652,8 +666,17 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
mtk_clk_unregister_fixed_clks(mcd->fixed_clks,
mcd->num_fixed_clks, clk_data);
unregister_plls:
- if (mcd->plls)
- mtk_clk_unregister_plls(mcd->plls, mcd->num_plls, clk_data);
+ if (mcd->plls) {
+#if IS_ENABLED(CONFIG_COMMON_CLK_MEDIATEK_FHCTL)
+ if (mcd->fhctl_node)
+ mtk_clk_unregister_pllfhs(mcd->plls, mcd->num_plls,
+ mcd->pllfhs, mcd->num_pllfhs,
+ clk_data);
+ else
+#endif
+ mtk_clk_unregister_plls(mcd->plls, mcd->num_plls,
+ clk_data);
+ }
free_data:
mtk_free_clk_data(clk_data);
free_base:
@@ -695,8 +718,18 @@ static void __mtk_clk_simple_remove(struct platform_device *pdev,
if (mcd->fixed_clks)
mtk_clk_unregister_fixed_clks(mcd->fixed_clks,
mcd->num_fixed_clks, clk_data);
- if (mcd->plls)
- mtk_clk_unregister_plls(mcd->plls, mcd->num_plls, clk_data);
+ if (mcd->plls) {
+#if IS_ENABLED(CONFIG_COMMON_CLK_MEDIATEK_FHCTL)
+ if (mcd->fhctl_node)
+ mtk_clk_unregister_pllfhs(mcd->plls, mcd->num_plls,
+ mcd->pllfhs, mcd->num_pllfhs,
+ clk_data);
+ else
+#endif
+ mtk_clk_unregister_plls(mcd->plls, mcd->num_plls,
+ clk_data);
+ }
+
mtk_free_clk_data(clk_data);
}
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 11939e3e0b38..4e959ec68da0 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -15,6 +15,8 @@
#include "reset.h"
+#include "clk-fhctl.h"
+
#define MAX_MUX_GATE_BIT 31
#define INVALID_MUX_GATE_BIT (MAX_MUX_GATE_BIT + 1)
@@ -266,6 +268,10 @@ struct mtk_clk_desc {
bool need_runtime_pm;
bool populate_children;
+
+ const u8 *fhctl_node;
+ struct mtk_pllfh_data *pllfhs;
+ size_t num_pllfhs;
};
int mtk_clk_pdev_probe(struct platform_device *pdev);
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 16/35] clk: mediatek: mt2701: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (14 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 15/35] clk: mediatek: Add FHCTL support to common " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:23 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 17/35] clk: mediatek: mt2712-apmixedsys: " Akari Tsuyukusa
` (18 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT2701 topckgen and pericfg drivers register clock types already
supported by the common helpers, so their custom initialization
routines can be replaced with struct mtk_clk_desc.
The infracfg, apmixedsys, and audsys drivers additionally needed
CPU mux registration, PLL registration, and child-device population,
respectively. With these capabilities now supported by the common
helpers, these drivers can use mtk_clk_simple_probe() and
mtk_clk_simple_remove().
Drop the CLK_OF_DECLARE_DRIVER early init for infracfg; the kernel's
deferred probe mechanism ensures dependent drivers like cpufreq are
initialized correctly.
With the drivers converted to the common probe/remove helpers,
enable module builds by changing their Kconfig entries to "tristate".
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/Kconfig | 18 +-
drivers/clk/mediatek/clk-mt2701-aud.c | 35 +---
drivers/clk/mediatek/clk-mt2701.c | 233 ++++++--------------------
3 files changed, 65 insertions(+), 221 deletions(-)
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index b059d44577f1..486024be26a6 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -19,7 +19,7 @@ config COMMON_CLK_MEDIATEK_FHCTL
spread spectrum clocking features.
config COMMON_CLK_MT2701
- bool "Clock driver for MediaTek MT2701"
+ tristate "Clock driver for MediaTek MT2701"
depends on (ARCH_MEDIATEK && ARM) || COMPILE_TEST
select COMMON_CLK_MEDIATEK
default ARCH_MEDIATEK && ARM
@@ -27,49 +27,49 @@ config COMMON_CLK_MT2701
This driver supports MediaTek MT2701 basic clocks.
config COMMON_CLK_MT2701_MMSYS
- bool "Clock driver for MediaTek MT2701 mmsys"
+ tristate "Clock driver for MediaTek MT2701 mmsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 mmsys clocks.
config COMMON_CLK_MT2701_IMGSYS
- bool "Clock driver for MediaTek MT2701 imgsys"
+ tristate "Clock driver for MediaTek MT2701 imgsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 imgsys clocks.
config COMMON_CLK_MT2701_VDECSYS
- bool "Clock driver for MediaTek MT2701 vdecsys"
+ tristate "Clock driver for MediaTek MT2701 vdecsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 vdecsys clocks.
config COMMON_CLK_MT2701_HIFSYS
- bool "Clock driver for MediaTek MT2701 hifsys"
+ tristate "Clock driver for MediaTek MT2701 hifsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 hifsys clocks.
config COMMON_CLK_MT2701_ETHSYS
- bool "Clock driver for MediaTek MT2701 ethsys"
+ tristate "Clock driver for MediaTek MT2701 ethsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 ethsys clocks.
config COMMON_CLK_MT2701_BDPSYS
- bool "Clock driver for MediaTek MT2701 bdpsys"
+ tristate "Clock driver for MediaTek MT2701 bdpsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 bdpsys clocks.
config COMMON_CLK_MT2701_AUDSYS
- bool "Clock driver for Mediatek MT2701 audsys"
+ tristate "Clock driver for Mediatek MT2701 audsys"
depends on COMMON_CLK_MT2701
help
This driver supports Mediatek MT2701 audsys clocks.
config COMMON_CLK_MT2701_G3DSYS
- bool "Clock driver for MediaTek MT2701 g3dsys"
+ tristate "Clock driver for MediaTek MT2701 g3dsys"
depends on COMMON_CLK_MT2701
help
This driver supports MediaTek MT2701 g3dsys clocks.
diff --git a/drivers/clk/mediatek/clk-mt2701-aud.c b/drivers/clk/mediatek/clk-mt2701-aud.c
index e103121cf58e..533d35614661 100644
--- a/drivers/clk/mediatek/clk-mt2701-aud.c
+++ b/drivers/clk/mediatek/clk-mt2701-aud.c
@@ -128,6 +128,7 @@ static const struct mtk_gate audio_clks[] = {
static const struct mtk_clk_desc audio_desc = {
.clks = audio_clks,
.num_clks = ARRAY_SIZE(audio_clks),
+ .populate_children = true,
};
static const struct of_device_id of_match_clk_mt2701_aud[] = {
@@ -136,39 +137,9 @@ static const struct of_device_id of_match_clk_mt2701_aud[] = {
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt2701_aud);
-static int clk_mt2701_aud_probe(struct platform_device *pdev)
-{
- int r;
-
- r = mtk_clk_simple_probe(pdev);
- if (r) {
- dev_err(&pdev->dev,
- "could not register clock provider: %s: %d\n",
- pdev->name, r);
-
- return r;
- }
-
- r = devm_of_platform_populate(&pdev->dev);
- if (r)
- goto err_plat_populate;
-
- return 0;
-
-err_plat_populate:
- mtk_clk_simple_remove(pdev);
- return r;
-}
-
-static void clk_mt2701_aud_remove(struct platform_device *pdev)
-{
- of_platform_depopulate(&pdev->dev);
- mtk_clk_simple_remove(pdev);
-}
-
static struct platform_driver clk_mt2701_aud_drv = {
- .probe = clk_mt2701_aud_probe,
- .remove = clk_mt2701_aud_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt2701-aud",
.of_match_table = of_match_clk_mt2701_aud,
diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
index 710c4f2f9f30..5ea0c4acaf1b 100644
--- a/drivers/clk/mediatek/clk-mt2701.c
+++ b/drivers/clk/mediatek/clk-mt2701.c
@@ -6,6 +6,7 @@
#include <linux/clk-provider.h>
#include <linux/platform_device.h>
+#include <linux/module.h>
#include "clk-cpumux.h"
#include "clk-gate.h"
@@ -655,38 +656,19 @@ static const struct mtk_gate top_clks[] = {
28),
};
-static int mtk_topckgen_init(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- void __iomem *base;
- struct device_node *node = pdev->dev.of_node;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
- clk_data);
-
- mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs),
- clk_data);
-
- mtk_clk_register_composites(&pdev->dev, top_muxes,
- ARRAY_SIZE(top_muxes), base,
- &mt2701_clk_lock, clk_data);
-
- mtk_clk_register_dividers(&pdev->dev, top_adj_divs, ARRAY_SIZE(top_adj_divs),
- base, &mt2701_clk_lock, clk_data);
-
- mtk_clk_register_gates(&pdev->dev, node, top_clks,
- ARRAY_SIZE(top_clks), clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
+static const struct mtk_clk_desc topck_desc = {
+ .clks = top_clks,
+ .num_clks = ARRAY_SIZE(top_clks),
+ .fixed_clks = top_fixed_clks,
+ .num_fixed_clks = ARRAY_SIZE(top_fixed_clks),
+ .factor_clks = top_fixed_divs,
+ .num_factor_clks = ARRAY_SIZE(top_fixed_divs),
+ .composite_clks = top_muxes,
+ .num_composite_clks = ARRAY_SIZE(top_muxes),
+ .divider_clks = top_adj_divs,
+ .num_divider_clks = ARRAY_SIZE(top_adj_divs),
+ .clk_lock = &mt2701_clk_lock,
+};
static const struct mtk_gate_regs infra_cg_regs = {
.set_ofs = 0x0040,
@@ -725,81 +707,21 @@ static const struct mtk_fixed_factor infra_fixed_divs[] = {
static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
-static const struct mtk_clk_rst_desc clk_rst_desc[] = {
- /* infrasys */
- {
- .version = MTK_RST_SIMPLE,
- .rst_bank_ofs = infrasys_rst_ofs,
- .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
- },
- /* pericfg */
- {
- .version = MTK_RST_SIMPLE,
- .rst_bank_ofs = pericfg_rst_ofs,
- .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
- },
+static const struct mtk_clk_rst_desc infra_rst_desc = {
+ .version = MTK_RST_SIMPLE,
+ .rst_bank_ofs = infrasys_rst_ofs,
+ .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
};
-static struct clk_hw_onecell_data *infra_clk_data;
-
-static void __init mtk_infrasys_init_early(struct device_node *node)
-{
- int r, i;
-
- if (!infra_clk_data) {
- infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
- if (!infra_clk_data)
- return;
-
- for (i = 0; i < CLK_INFRA_NR; i++)
- infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
- }
-
- mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
- infra_clk_data);
-
- mtk_clk_register_cpumuxes(NULL, node, cpu_muxes, ARRAY_SIZE(cpu_muxes),
- infra_clk_data);
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
- infra_clk_data);
- if (r)
- pr_err("%s(): could not register clock provider: %d\n",
- __func__, r);
-}
-CLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt2701-infracfg",
- mtk_infrasys_init_early);
-
-static int mtk_infrasys_init(struct platform_device *pdev)
-{
- int r, i;
- struct device_node *node = pdev->dev.of_node;
-
- if (!infra_clk_data) {
- infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
- if (!infra_clk_data)
- return -ENOMEM;
- } else {
- for (i = 0; i < CLK_INFRA_NR; i++) {
- if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
- infra_clk_data->hws[i] = ERR_PTR(-ENOENT);
- }
- }
-
- mtk_clk_register_gates(&pdev->dev, node, infra_clks,
- ARRAY_SIZE(infra_clks), infra_clk_data);
- mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
- infra_clk_data);
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
- infra_clk_data);
- if (r)
- return r;
-
- mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[0]);
-
- return 0;
-}
+static const struct mtk_clk_desc infracfg_desc = {
+ .clks = infra_clks,
+ .num_clks = ARRAY_SIZE(infra_clks),
+ .factor_clks = infra_fixed_divs,
+ .num_factor_clks = ARRAY_SIZE(infra_fixed_divs),
+ .cpumuxes = cpu_muxes,
+ .num_cpumuxes = ARRAY_SIZE(cpu_muxes),
+ .rst_desc = &infra_rst_desc,
+};
static const struct mtk_gate_regs peri0_cg_regs = {
.set_ofs = 0x0008,
@@ -883,36 +805,20 @@ static const struct mtk_composite peri_muxs[] = {
0x40c, 3, 1),
};
-static int mtk_pericfg_init(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- void __iomem *base;
- int r;
- struct device_node *node = pdev->dev.of_node;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_PERI_NR);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_gates(&pdev->dev, node, peri_clks,
- ARRAY_SIZE(peri_clks), clk_data);
-
- mtk_clk_register_composites(&pdev->dev, peri_muxs,
- ARRAY_SIZE(peri_muxs), base,
- &mt2701_clk_lock, clk_data);
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- return r;
-
- mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[1]);
+static const struct mtk_clk_rst_desc peri_rst_desc = {
+ .version = MTK_RST_SIMPLE,
+ .rst_bank_ofs = pericfg_rst_ofs,
+ .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
+};
- return 0;
-}
+static const struct mtk_clk_desc pericfg_desc = {
+ .clks = peri_clks,
+ .num_clks = ARRAY_SIZE(peri_clks),
+ .composite_clks = peri_muxs,
+ .num_composite_clks = ARRAY_SIZE(peri_muxs),
+ .rst_desc = &peri_rst_desc,
+ .clk_lock = &mt2701_clk_lock,
+};
#define MT8590_PLL_FMAX (2000 * MHZ)
#define CON0_MT8590_RST_BAR BIT(27)
@@ -968,74 +874,41 @@ static const struct mtk_fixed_factor apmixed_fixed_divs[] = {
FACTOR(CLK_APMIXED_HDMI_REF, "hdmi_ref", "tvdpll", 1, 1),
};
-static int mtk_apmixedsys_init(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_plls(&pdev->dev, apmixed_plls, ARRAY_SIZE(apmixed_plls),
- clk_data);
- mtk_clk_register_factors(apmixed_fixed_divs, ARRAY_SIZE(apmixed_fixed_divs),
- clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
+static const struct mtk_clk_desc apmixedsys_desc = {
+ .plls = apmixed_plls,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .factor_clks = apmixed_fixed_divs,
+ .num_factor_clks = ARRAY_SIZE(apmixed_fixed_divs),
+};
static const struct of_device_id of_match_clk_mt2701[] = {
{
.compatible = "mediatek,mt2701-topckgen",
- .data = mtk_topckgen_init,
+ .data = &topck_desc,
}, {
.compatible = "mediatek,mt2701-infracfg",
- .data = mtk_infrasys_init,
+ .data = &infracfg_desc,
}, {
.compatible = "mediatek,mt2701-pericfg",
- .data = mtk_pericfg_init,
+ .data = &pericfg_desc,
}, {
.compatible = "mediatek,mt2701-apmixedsys",
- .data = mtk_apmixedsys_init,
+ .data = &apmixedsys_desc,
}, {
/* sentinel */
}
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt2701);
-static int clk_mt2701_probe(struct platform_device *pdev)
-{
- int (*clk_init)(struct platform_device *);
- int r;
-
- clk_init = of_device_get_match_data(&pdev->dev);
- if (!clk_init)
- return -EINVAL;
-
- r = clk_init(pdev);
- if (r)
- dev_err(&pdev->dev,
- "could not register clock provider: %s: %d\n",
- pdev->name, r);
-
- return r;
-}
-
static struct platform_driver clk_mt2701_drv = {
- .probe = clk_mt2701_probe,
.driver = {
.name = "clk-mt2701",
.of_match_table = of_match_clk_mt2701,
},
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
};
-
-static int __init clk_mt2701_init(void)
-{
- return platform_driver_register(&clk_mt2701_drv);
-}
-
-arch_initcall(clk_mt2701_init);
+module_platform_driver(clk_mt2701_drv);
MODULE_DESCRIPTION("MediaTek MT2701 main clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 17/35] clk: mediatek: mt2712-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (15 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 16/35] clk: mediatek: mt2701: Switch " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:20 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 18/35] clk: mediatek: mt6735-apmixedsys: " Akari Tsuyukusa
` (17 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT2712 apmixedsys driver previously needed custom probe/remove
callbacks to register and unregister PLLs. With PLL support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 50 +++-----------------
1 file changed, 7 insertions(+), 43 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt2712-apmixedsys.c b/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
index 087cf574bcdc..1e06f87e71d0 100644
--- a/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
@@ -109,56 +109,20 @@ static const struct mtk_pll_data plls[] = {
0, 31, 0x0300, 4, 0, 0, 0, 0x0304, 0),
};
-static int clk_mt2712_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- int r;
- struct device_node *node = pdev->dev.of_node;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
- if (r)
- goto free_clk_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r) {
- dev_err(&pdev->dev, "Cannot register clock provider: %d\n", r);
- goto unregister_plls;
- }
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt2712_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
- mtk_free_clk_data(clk_data);
-}
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
static const struct of_device_id of_match_clk_mt2712_apmixed[] = {
- { .compatible = "mediatek,mt2712-apmixedsys" },
+ { .compatible = "mediatek,mt2712-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt2712_apmixed);
static struct platform_driver clk_mt2712_apmixed_drv = {
- .probe = clk_mt2712_apmixed_probe,
- .remove = clk_mt2712_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt2712-apmixed",
.of_match_table = of_match_clk_mt2712_apmixed,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 18/35] clk: mediatek: mt6735-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (16 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 17/35] clk: mediatek: mt2712-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 19/35] clk: mediatek: mt6779: " Akari Tsuyukusa
` (16 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT6735 apmixedsys driver previously needed custom probe/remove
callbacks to register and unregister PLLs. With PLL support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
- Diff changed by 935ad6242c47
("clk: mediatek: mt6735: Unregister PLLs on probe failure")
---
drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 51 +++-----------------
1 file changed, 7 insertions(+), 44 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt6735-apmixedsys.c b/drivers/clk/mediatek/clk-mt6735-apmixedsys.c
index b6eb6a581c31..94cb0bee8bb4 100644
--- a/drivers/clk/mediatek/clk-mt6735-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt6735-apmixedsys.c
@@ -77,57 +77,20 @@ static const struct mtk_pll_data apmixedsys_plls[] = {
PLL(CLK_APMIXED_APLL2, "apll2", APLL2_CON0, APLL2_PWR_CON0, 0x00000001, 0, APLL2_CON0, 4, APLL2_CON2, AP_PLL_CON_5, 1, APLL2_CON1, 31, 0)
};
-static int clk_mt6735_apmixed_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- struct clk_hw_onecell_data *clk_data;
- int ret;
-
- base = devm_ioremap_resource(&pdev->dev, res);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_devm_alloc_clk_data(&pdev->dev, ARRAY_SIZE(apmixedsys_plls));
- if (!clk_data)
- return -ENOMEM;
- platform_set_drvdata(pdev, clk_data);
-
- ret = mtk_clk_register_plls(&pdev->dev, apmixedsys_plls,
- ARRAY_SIZE(apmixedsys_plls), clk_data);
- if (ret) {
- dev_err(&pdev->dev, "Failed to register PLLs: %d\n", ret);
- return ret;
- }
-
- ret = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get,
- clk_data);
- if (ret) {
- dev_err(&pdev->dev,
- "Failed to register clock provider: %d\n", ret);
- mtk_clk_unregister_plls(apmixedsys_plls, ARRAY_SIZE(apmixedsys_plls),
- clk_data);
- }
-
- return ret;
-}
-
-static void clk_mt6735_apmixed_remove(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- mtk_clk_unregister_plls(apmixedsys_plls, ARRAY_SIZE(apmixedsys_plls), clk_data);
-}
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = apmixedsys_plls,
+ .num_plls = ARRAY_SIZE(apmixedsys_plls),
+};
static const struct of_device_id of_match_mt6735_apmixedsys[] = {
- { .compatible = "mediatek,mt6735-apmixedsys" },
+ { .compatible = "mediatek,mt6735-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_mt6735_apmixedsys);
static struct platform_driver clk_mt6735_apmixedsys = {
- .probe = clk_mt6735_apmixed_probe,
- .remove = clk_mt6735_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt6735-apmixedsys",
.of_match_table = of_match_mt6735_apmixedsys,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 19/35] clk: mediatek: mt6779: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (17 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 18/35] clk: mediatek: mt6735-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:31 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 20/35] clk: mediatek: mt6795: " Akari Tsuyukusa
` (15 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT6779 apmixedsys driver used a custom probe to register PLLs.
With PLL registration now supported by the common helpers, it can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Consolidate the apmixedsys, topckgen, and infracfg match entries under
a single platform driver, using struct mtk_clk_desc for the clock
configurations. Replace the custom arch_initcall() registration with
module_platform_driver().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt6779.c | 124 ++++++------------------------
1 file changed, 22 insertions(+), 102 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt6779.c b/drivers/clk/mediatek/clk-mt6779.c
index 4b9dcb910b03..a806789ae27c 100644
--- a/drivers/clk/mediatek/clk-mt6779.c
+++ b/drivers/clk/mediatek/clk-mt6779.c
@@ -808,7 +808,7 @@ static const char * const i2s5_m_ck_parents[] = {
"aud_2_sel"
};
-static const struct mtk_composite top_aud_muxes[] = {
+static const struct mtk_composite top_aud_muxes_divs[] = {
MUX(CLK_TOP_I2S0_M_SEL, "i2s0_m_ck_sel", i2s0_m_ck_parents,
0x320, 8, 1),
MUX(CLK_TOP_I2S1_M_SEL, "i2s1_m_ck_sel", i2s1_m_ck_parents,
@@ -821,9 +821,7 @@ static const struct mtk_composite top_aud_muxes[] = {
0x320, 12, 1),
MUX(CLK_TOP_I2S5_M_SEL, "i2s5_m_ck_sel", i2s5_m_ck_parents,
0x328, 20, 1),
-};
-static struct mtk_composite top_aud_divs[] = {
DIV_GATE(CLK_TOP_APLL12_DIV0, "apll12_div0", "i2s0_m_ck_sel",
0x320, 2, 0x324, 8, 0),
DIV_GATE(CLK_TOP_APLL12_DIV1, "apll12_div1", "i2s1_m_ck_sel",
@@ -1211,125 +1209,47 @@ static const struct mtk_pll_data plls[] = {
0, 0, 32, 8, 0x02D4, 1, 0, 0x14, 1, 0x02D8, 0, 0x02D4),
};
-static int clk_mt6779_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
-
- mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
-
-static int clk_mt6779_top_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
- clk_data);
-
- mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
-
- mtk_clk_register_muxes(&pdev->dev, top_muxes,
- ARRAY_SIZE(top_muxes), node,
- &mt6779_clk_lock, clk_data);
-
- mtk_clk_register_composites(&pdev->dev, top_aud_muxes,
- ARRAY_SIZE(top_aud_muxes), base,
- &mt6779_clk_lock, clk_data);
-
- mtk_clk_register_composites(&pdev->dev, top_aud_divs,
- ARRAY_SIZE(top_aud_divs), base,
- &mt6779_clk_lock, clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
-
-static const struct of_device_id of_match_clk_mt6779[] = {
- {
- .compatible = "mediatek,mt6779-apmixed",
- .data = clk_mt6779_apmixed_probe,
- }, {
- .compatible = "mediatek,mt6779-topckgen",
- .data = clk_mt6779_top_probe,
- }, {
- /* sentinel */
- }
+static const struct mtk_clk_desc apmixed_desc = {
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
};
-static int clk_mt6779_probe(struct platform_device *pdev)
-{
- int (*clk_probe)(struct platform_device *pdev);
- int r;
-
- clk_probe = of_device_get_match_data(&pdev->dev);
- if (!clk_probe)
- return -EINVAL;
-
- r = clk_probe(pdev);
- if (r)
- dev_err(&pdev->dev,
- "could not register clock provider: %s: %d\n",
- pdev->name, r);
-
- return r;
-}
+static const struct mtk_clk_desc topck_desc = {
+ .fixed_clks = top_fixed_clks,
+ .num_fixed_clks = ARRAY_SIZE(top_fixed_clks),
+ .factor_clks = top_divs,
+ .num_factor_clks = ARRAY_SIZE(top_divs),
+ .mux_clks = top_muxes,
+ .num_mux_clks = ARRAY_SIZE(top_muxes),
+ .composite_clks = top_aud_muxes_divs,
+ .num_composite_clks = ARRAY_SIZE(top_aud_muxes_divs),
+ .clk_lock = &mt6779_clk_lock,
+};
static const struct mtk_clk_desc infra_desc = {
.clks = infra_clks,
.num_clks = ARRAY_SIZE(infra_clks),
};
-static const struct of_device_id of_match_clk_mt6779_infra[] = {
+static const struct of_device_id of_match_clk_mt6779[] = {
+ { .compatible = "mediatek,mt6779-apmixed", .data = &apmixed_desc },
+ { .compatible = "mediatek,mt6779-topckgen", .data = &topck_desc },
{ .compatible = "mediatek,mt6779-infracfg_ao", .data = &infra_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt6779);
-static struct platform_driver clk_mt6779_infra_drv = {
+static struct platform_driver clk_mt6779_drv = {
.probe = mtk_clk_simple_probe,
.remove = mtk_clk_simple_remove,
- .driver = {
- .name = "clk-mt6779-infra",
- .of_match_table = of_match_clk_mt6779_infra,
- },
-};
-
-static struct platform_driver clk_mt6779_drv = {
- .probe = clk_mt6779_probe,
.driver = {
.name = "clk-mt6779",
.of_match_table = of_match_clk_mt6779,
},
};
-
-static int __init clk_mt6779_init(void)
-{
- int ret = platform_driver_register(&clk_mt6779_drv);
-
- if (ret)
- return ret;
- return platform_driver_register(&clk_mt6779_infra_drv);
-}
-
-arch_initcall(clk_mt6779_init);
+module_platform_driver(clk_mt6779_drv);
MODULE_DESCRIPTION("MediaTek MT6779 main clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 20/35] clk: mediatek: mt6795: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (18 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 19/35] clk: mediatek: mt6779: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 21/35] clk: mediatek: mt6797: " Akari Tsuyukusa
` (14 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT6795 infracfg driver previously needed custom probe/remove
callbacks to register CPU muxes, which were not supported by the
common helpers. With CPU mux support now available, infracfg can
use mtk_clk_simple_probe() and mtk_clk_simple_remove().
The pericfg driver can also use the common helpers, which already
support its gate and composite clocks.
Keep the apmixedsys driver unchanged because it requires ref2usb_tx
clock handling, which is not yet supported by the common helpers.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt6795-infracfg.c | 72 ++++-----------------
drivers/clk/mediatek/clk-mt6795-pericfg.c | 73 ++++------------------
2 files changed, 23 insertions(+), 122 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt6795-infracfg.c b/drivers/clk/mediatek/clk-mt6795-infracfg.c
index 914bb069aa85..6aefc577ece5 100644
--- a/drivers/clk/mediatek/clk-mt6795-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt6795-infracfg.c
@@ -8,7 +8,6 @@
#include <dt-bindings/reset/mediatek,mt6795-resets.h>
#include <linux/module.h>
#include <linux/platform_device.h>
-#include "clk-cpumux.h"
#include "clk-gate.h"
#include "clk-mtk.h"
#include "reset.h"
@@ -77,76 +76,27 @@ static const struct mtk_clk_rst_desc clk_rst_desc = {
.rst_idx_map_nr = ARRAY_SIZE(infra_ao_idx_map),
};
+static const struct mtk_clk_desc infra_desc = {
+ .clks = infra_gates,
+ .num_clks = ARRAY_SIZE(infra_gates),
+ .cpumuxes = cpu_muxes,
+ .num_cpumuxes = ARRAY_SIZE(cpu_muxes),
+ .rst_desc = &clk_rst_desc,
+};
+
static const struct of_device_id of_match_clk_mt6795_infracfg[] = {
- { .compatible = "mediatek,mt6795-infracfg" },
+ { .compatible = "mediatek,mt6795-infracfg", .data = &infra_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt6795_infracfg);
-static int clk_mt6795_infracfg_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- void __iomem *base;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
- if (ret)
- goto free_clk_data;
-
- ret = mtk_clk_register_gates(&pdev->dev, node, infra_gates,
- ARRAY_SIZE(infra_gates), clk_data);
- if (ret)
- goto free_clk_data;
-
- ret = mtk_clk_register_cpumuxes(&pdev->dev, node, cpu_muxes,
- ARRAY_SIZE(cpu_muxes), clk_data);
- if (ret)
- goto unregister_gates;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_cpumuxes;
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_cpumuxes:
- mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
-unregister_gates:
- mtk_clk_unregister_gates(infra_gates, ARRAY_SIZE(infra_gates), clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
- return ret;
-}
-
-static void clk_mt6795_infracfg_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
- mtk_clk_unregister_gates(infra_gates, ARRAY_SIZE(infra_gates), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt6795_infracfg_drv = {
.driver = {
.name = "clk-mt6795-infracfg",
.of_match_table = of_match_clk_mt6795_infracfg,
},
- .probe = clk_mt6795_infracfg_probe,
- .remove = clk_mt6795_infracfg_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
};
module_platform_driver(clk_mt6795_infracfg_drv);
diff --git a/drivers/clk/mediatek/clk-mt6795-pericfg.c b/drivers/clk/mediatek/clk-mt6795-pericfg.c
index 27d0ef7d7b2f..53c79e830b6a 100644
--- a/drivers/clk/mediatek/clk-mt6795-pericfg.c
+++ b/drivers/clk/mediatek/clk-mt6795-pericfg.c
@@ -85,77 +85,28 @@ static const struct mtk_clk_rst_desc clk_rst_desc = {
.rst_idx_map_nr = ARRAY_SIZE(peri_idx_map),
};
+static const struct mtk_clk_desc pericfg_desc = {
+ .clks = peri_gates,
+ .num_clks = ARRAY_SIZE(peri_gates),
+ .composite_clks = peri_clks,
+ .num_composite_clks = ARRAY_SIZE(peri_clks),
+ .rst_desc = &clk_rst_desc,
+ .clk_lock = &mt6795_peri_clk_lock,
+};
+
static const struct of_device_id of_match_clk_mt6795_pericfg[] = {
- { .compatible = "mediatek,mt6795-pericfg" },
+ { .compatible = "mediatek,mt6795-pericfg", .data = &pericfg_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt6795_pericfg);
-static int clk_mt6795_pericfg_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- void __iomem *base;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
- if (ret)
- goto free_clk_data;
-
- ret = mtk_clk_register_gates(&pdev->dev, node, peri_gates,
- ARRAY_SIZE(peri_gates), clk_data);
- if (ret)
- goto free_clk_data;
-
- ret = mtk_clk_register_composites(&pdev->dev, peri_clks,
- ARRAY_SIZE(peri_clks), base,
- &mt6795_peri_clk_lock, clk_data);
- if (ret)
- goto unregister_gates;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_composites;
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_composites:
- mtk_clk_unregister_composites(peri_clks, ARRAY_SIZE(peri_clks), clk_data);
-unregister_gates:
- mtk_clk_unregister_gates(peri_gates, ARRAY_SIZE(peri_gates), clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
- return ret;
-}
-
-static void clk_mt6795_pericfg_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_composites(peri_clks, ARRAY_SIZE(peri_clks), clk_data);
- mtk_clk_unregister_gates(peri_gates, ARRAY_SIZE(peri_gates), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt6795_pericfg_drv = {
.driver = {
.name = "clk-mt6795-pericfg",
.of_match_table = of_match_clk_mt6795_pericfg,
},
- .probe = clk_mt6795_pericfg_probe,
- .remove = clk_mt6795_pericfg_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
};
module_platform_driver(clk_mt6795_pericfg_drv);
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 21/35] clk: mediatek: mt6797: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (19 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 20/35] clk: mediatek: mt6795: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:39 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 22/35] clk: mediatek: mt7622: " Akari Tsuyukusa
` (13 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT6797 topckgen and infracfg drivers use clock types already
supported by the common helpers. The apmixedsys driver can also use
them now that PLL registration and unregistration are supported.
Drop the CLK_OF_DECLARE_DRIVER early init for infracfg; the kernel's
deferred probe mechanism ensures dependent drivers like cpufreq are
initialized correctly.
Enable module builds by changing the Kconfig setting to "tristate".
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/Kconfig | 2 +-
drivers/clk/mediatek/clk-mt6797.c | 140 +++++-------------------------
2 files changed, 24 insertions(+), 118 deletions(-)
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index 486024be26a6..be522c43fa42 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -342,7 +342,7 @@ config COMMON_CLK_MT6795_VENCSYS
This driver supports MediaTek MT6795 vencsys clocks.
config COMMON_CLK_MT6797
- bool "Clock driver for MediaTek MT6797"
+ tristate "Clock driver for MediaTek MT6797"
depends on (ARCH_MEDIATEK && ARM64) || COMPILE_TEST
select COMMON_CLK_MEDIATEK
default ARCH_MEDIATEK && ARM64
diff --git a/drivers/clk/mediatek/clk-mt6797.c b/drivers/clk/mediatek/clk-mt6797.c
index ebf850ac57f5..1934420375e8 100644
--- a/drivers/clk/mediatek/clk-mt6797.c
+++ b/drivers/clk/mediatek/clk-mt6797.c
@@ -379,29 +379,13 @@ static const struct mtk_composite top_muxes[] = {
0x0104, 1, 2),
};
-static int mtk_topckgen_init(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- void __iomem *base;
- struct device_node *node = pdev->dev.of_node;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs),
- clk_data);
-
- mtk_clk_register_composites(&pdev->dev, top_muxes,
- ARRAY_SIZE(top_muxes), base,
- &mt6797_clk_lock, clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
+static const struct mtk_clk_desc topckgen_desc = {
+ .factor_clks = top_fixed_divs,
+ .num_factor_clks = ARRAY_SIZE(top_fixed_divs),
+ .composite_clks = top_muxes,
+ .num_composite_clks = ARRAY_SIZE(top_muxes),
+ .clk_lock = &mt6797_clk_lock,
+};
static const struct mtk_gate_regs infra0_cg_regs = {
.set_ofs = 0x0080,
@@ -539,58 +523,12 @@ static const struct mtk_fixed_factor infra_fixed_divs[] = {
FACTOR(CLK_INFRA_13M, "clk13m", "clk26m", 1, 2),
};
-static struct clk_hw_onecell_data *infra_clk_data;
-
-static void mtk_infrasys_init_early(struct device_node *node)
-{
- int r, i;
-
- if (!infra_clk_data) {
- infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
- if (!infra_clk_data)
- return;
-
- for (i = 0; i < CLK_INFRA_NR; i++)
- infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
- }
-
- mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
- infra_clk_data);
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
- infra_clk_data);
- if (r)
- pr_err("%s(): could not register clock provider: %d\n",
- __func__, r);
-}
-
-CLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt6797-infracfg",
- mtk_infrasys_init_early);
-
-static int mtk_infrasys_init(struct platform_device *pdev)
-{
- int i;
- struct device_node *node = pdev->dev.of_node;
-
- if (!infra_clk_data) {
- infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
- if (!infra_clk_data)
- return -ENOMEM;
- } else {
- for (i = 0; i < CLK_INFRA_NR; i++) {
- if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
- infra_clk_data->hws[i] = ERR_PTR(-ENOENT);
- }
- }
-
- mtk_clk_register_gates(&pdev->dev, node, infra_clks,
- ARRAY_SIZE(infra_clks), infra_clk_data);
- mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
- infra_clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
- infra_clk_data);
-}
+static const struct mtk_clk_desc infracfg_desc = {
+ .clks = infra_clks,
+ .num_clks = ARRAY_SIZE(infra_clks),
+ .factor_clks = infra_fixed_divs,
+ .num_factor_clks = ARRAY_SIZE(infra_fixed_divs),
+};
#define MT6797_PLL_FMAX (3000UL * MHZ)
@@ -646,68 +584,36 @@ static const struct mtk_pll_data plls[] = {
0x2B4, 4, 0x2BC, 0x2B8, 0),
};
-static int mtk_apmixedsys_init(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
-
- return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
-}
+static const struct mtk_clk_desc apmixedsys_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
static const struct of_device_id of_match_clk_mt6797[] = {
{
.compatible = "mediatek,mt6797-topckgen",
- .data = mtk_topckgen_init,
+ .data = &topckgen_desc,
}, {
.compatible = "mediatek,mt6797-infracfg",
- .data = mtk_infrasys_init,
+ .data = &infracfg_desc,
}, {
.compatible = "mediatek,mt6797-apmixedsys",
- .data = mtk_apmixedsys_init,
+ .data = &apmixedsys_desc,
}, {
/* sentinel */
}
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt6797);
-static int clk_mt6797_probe(struct platform_device *pdev)
-{
- int (*clk_init)(struct platform_device *);
- int r;
-
- clk_init = of_device_get_match_data(&pdev->dev);
- if (!clk_init)
- return -EINVAL;
-
- r = clk_init(pdev);
- if (r)
- dev_err(&pdev->dev,
- "could not register clock provider: %s: %d\n",
- pdev->name, r);
-
- return r;
-}
-
static struct platform_driver clk_mt6797_drv = {
- .probe = clk_mt6797_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt6797",
.of_match_table = of_match_clk_mt6797,
},
};
-
-static int __init clk_mt6797_init(void)
-{
- return platform_driver_register(&clk_mt6797_drv);
-}
-
-arch_initcall(clk_mt6797_init);
+module_platform_driver(clk_mt6797_drv);
MODULE_DESCRIPTION("MediaTek MT6797 main clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 22/35] clk: mediatek: mt7622: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (20 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 21/35] clk: mediatek: mt6797: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 23/35] clk: mediatek: mt7981-apmixed: " Akari Tsuyukusa
` (12 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT7622 apmixedsys driver used custom probe/remove callbacks to
register PLLs. The infracfg driver also needed CPU mux registration,
and the audsys driver needed child-device population.
With PLL, CPU mux, and child-device population support available in the
common helpers, all three drivers can use mtk_clk_simple_probe()
and mtk_clk_simple_remove().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 62 +++--------------
drivers/clk/mediatek/clk-mt7622-aud.c | 35 +---------
drivers/clk/mediatek/clk-mt7622-infracfg.c | 72 +++-----------------
3 files changed, 23 insertions(+), 146 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt7622-apmixedsys.c b/drivers/clk/mediatek/clk-mt7622-apmixedsys.c
index fae8abda14b3..e9f731eadace 100644
--- a/drivers/clk/mediatek/clk-mt7622-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt7622-apmixedsys.c
@@ -80,66 +80,22 @@ static const struct mtk_gate apmixed_clks[] = {
GATE_APMIXED_AO(CLK_APMIXED_MAIN_CORE_EN, "main_core_en", "mainpll", 5),
};
-static int clk_mt7622_apmixed_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- struct device *dev = &pdev->dev;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_devm_alloc_clk_data(dev, CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_clk_register_plls(dev, plls, ARRAY_SIZE(plls), clk_data);
- if (ret)
- return ret;
-
- ret = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
- if (ret)
- goto unregister_plls;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_gates;
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_gates:
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-
- return ret;
-}
-
-static void clk_mt7622_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(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 mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+};
static const struct of_device_id of_match_clk_mt7622_apmixed[] = {
- { .compatible = "mediatek,mt7622-apmixedsys" },
+ { .compatible = "mediatek,mt7622-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt7622_apmixed);
static struct platform_driver clk_mt7622_apmixed_drv = {
- .probe = clk_mt7622_apmixed_probe,
- .remove = clk_mt7622_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt7622-apmixed",
.of_match_table = of_match_clk_mt7622_apmixed,
diff --git a/drivers/clk/mediatek/clk-mt7622-aud.c b/drivers/clk/mediatek/clk-mt7622-aud.c
index a4ea5e20efa2..6004c58be1b5 100644
--- a/drivers/clk/mediatek/clk-mt7622-aud.c
+++ b/drivers/clk/mediatek/clk-mt7622-aud.c
@@ -110,38 +110,9 @@ static const struct mtk_gate audio_clks[] = {
static const struct mtk_clk_desc audio_desc = {
.clks = audio_clks,
.num_clks = ARRAY_SIZE(audio_clks),
+ .populate_children = true,
};
-static int clk_mt7622_aud_probe(struct platform_device *pdev)
-{
- int r;
-
- r = mtk_clk_simple_probe(pdev);
- if (r) {
- dev_err(&pdev->dev,
- "could not register clock provider: %s: %d\n",
- pdev->name, r);
-
- return r;
- }
-
- r = devm_of_platform_populate(&pdev->dev);
- if (r)
- goto err_plat_populate;
-
- return 0;
-
-err_plat_populate:
- mtk_clk_simple_remove(pdev);
- return r;
-}
-
-static void clk_mt7622_aud_remove(struct platform_device *pdev)
-{
- of_platform_depopulate(&pdev->dev);
- mtk_clk_simple_remove(pdev);
-}
-
static const struct of_device_id of_match_clk_mt7622_aud[] = {
{ .compatible = "mediatek,mt7622-audsys", .data = &audio_desc },
{ /* sentinel */ }
@@ -149,8 +120,8 @@ static const struct of_device_id of_match_clk_mt7622_aud[] = {
MODULE_DEVICE_TABLE(of, of_match_clk_mt7622_aud);
static struct platform_driver clk_mt7622_aud_drv = {
- .probe = clk_mt7622_aud_probe,
- .remove = clk_mt7622_aud_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt7622-aud",
.of_match_table = of_match_clk_mt7622_aud,
diff --git a/drivers/clk/mediatek/clk-mt7622-infracfg.c b/drivers/clk/mediatek/clk-mt7622-infracfg.c
index cec19447d637..2e463d1481d0 100644
--- a/drivers/clk/mediatek/clk-mt7622-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt7622-infracfg.c
@@ -9,7 +9,6 @@
#include <linux/module.h>
#include <linux/platform_device.h>
-#include "clk-cpumux.h"
#include "clk-gate.h"
#include "clk-mtk.h"
#include "reset.h"
@@ -51,76 +50,27 @@ static const struct mtk_clk_rst_desc clk_rst_desc = {
.rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
};
+static const struct mtk_clk_desc infra_desc = {
+ .clks = infra_clks,
+ .num_clks = ARRAY_SIZE(infra_clks),
+ .cpumuxes = cpu_muxes,
+ .num_cpumuxes = ARRAY_SIZE(cpu_muxes),
+ .rst_desc = &clk_rst_desc,
+};
+
static const struct of_device_id of_match_clk_mt7622_infracfg[] = {
- { .compatible = "mediatek,mt7622-infracfg" },
+ { .compatible = "mediatek,mt7622-infracfg", .data = &infra_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt7622_infracfg);
-static int clk_mt7622_infracfg_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- void __iomem *base;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
- if (ret)
- goto free_clk_data;
-
- ret = mtk_clk_register_gates(&pdev->dev, node, infra_clks,
- ARRAY_SIZE(infra_clks), clk_data);
- if (ret)
- goto free_clk_data;
-
- ret = mtk_clk_register_cpumuxes(&pdev->dev, node, cpu_muxes,
- ARRAY_SIZE(cpu_muxes), clk_data);
- if (ret)
- goto unregister_gates;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_cpumuxes;
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_cpumuxes:
- mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
-unregister_gates:
- mtk_clk_unregister_gates(infra_clks, ARRAY_SIZE(infra_clks), clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
- return ret;
-}
-
-static void clk_mt7622_infracfg_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
- mtk_clk_unregister_gates(infra_clks, ARRAY_SIZE(infra_clks), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt7622_infracfg_drv = {
.driver = {
.name = "clk-mt7622-infracfg",
.of_match_table = of_match_clk_mt7622_infracfg,
},
- .probe = clk_mt7622_infracfg_probe,
- .remove = clk_mt7622_infracfg_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
};
module_platform_driver(clk_mt7622_infracfg_drv);
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 23/35] clk: mediatek: mt7981-apmixed: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (21 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 22/35] clk: mediatek: mt7622: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 24/35] clk: mediatek: mt7986-apmixed: " Akari Tsuyukusa
` (11 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT7981 apmixedsys driver used a custom probe to register PLLs but
had no remove callback. With PLL registration and unregistration
handled by the common helpers,
the driver can use mtk_clk_simple_probe() and mtk_clk_simple_remove().
Switch to module_platform_driver() and change the Kconfig
setting to "tristate" to support module builds and ensure
that registered clocks are unregistered on module removal.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/Kconfig | 2 +-
drivers/clk/mediatek/clk-mt7981-apmixed.c | 37 ++++++-----------------
2 files changed, 10 insertions(+), 29 deletions(-)
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index be522c43fa42..54ecf2692607 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -427,7 +427,7 @@ config COMMON_CLK_MT7629_HIFSYS
to PCI-E and USB.
config COMMON_CLK_MT7981
- bool "Clock driver for MediaTek MT7981"
+ tristate "Clock driver for MediaTek MT7981"
depends on ARCH_MEDIATEK || COMPILE_TEST
select COMMON_CLK_MEDIATEK
default ARCH_MEDIATEK
diff --git a/drivers/clk/mediatek/clk-mt7981-apmixed.c b/drivers/clk/mediatek/clk-mt7981-apmixed.c
index 851d0bc7840a..810395aff253 100644
--- a/drivers/clk/mediatek/clk-mt7981-apmixed.c
+++ b/drivers/clk/mediatek/clk-mt7981-apmixed.c
@@ -59,45 +59,26 @@ static const struct mtk_pll_data plls[] = {
0x0278, 4, 0, 0x027C, 0),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
+
static const struct of_device_id of_match_clk_mt7981_apmixed[] = {
- { .compatible = "mediatek,mt7981-apmixedsys", },
+ { .compatible = "mediatek,mt7981-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt7981_apmixed);
-static int clk_mt7981_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int r;
-
- clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r) {
- pr_err("%s(): could not register clock provider: %d\n",
- __func__, r);
- goto free_apmixed_data;
- }
- return r;
-
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
static struct platform_driver clk_mt7981_apmixed_drv = {
- .probe = clk_mt7981_apmixed_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt7981-apmixed",
.of_match_table = of_match_clk_mt7981_apmixed,
},
};
-builtin_platform_driver(clk_mt7981_apmixed_drv);
+module_platform_driver(clk_mt7981_apmixed_drv);
MODULE_DESCRIPTION("MediaTek MT7981 apmixedsys clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 24/35] clk: mediatek: mt7986-apmixed: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (22 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 23/35] clk: mediatek: mt7981-apmixed: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 25/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
` (10 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT7986 apmixedsys driver used a custom probe to register PLLs but
had no remove callback. With PLL registration and unregistration
handled by the common helpers,
the driver can use mtk_clk_simple_probe() and mtk_clk_simple_remove().
Switch to module_platform_driver() to support module unloading and
ensure that registered clocks are unregistered on removal.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt7986-apmixed.c | 37 ++++++-----------------
1 file changed, 9 insertions(+), 28 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt7986-apmixed.c b/drivers/clk/mediatek/clk-mt7986-apmixed.c
index af3e002bbfb7..6df3e9555e4e 100644
--- a/drivers/clk/mediatek/clk-mt7986-apmixed.c
+++ b/drivers/clk/mediatek/clk-mt7986-apmixed.c
@@ -57,45 +57,26 @@ static const struct mtk_pll_data plls[] = {
0x0278, 4, 0, 0x027c, 0),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
+
static const struct of_device_id of_match_clk_mt7986_apmixed[] = {
- { .compatible = "mediatek,mt7986-apmixedsys", },
+ { .compatible = "mediatek,mt7986-apmixedsys", .data = &apmixed_desc },
{ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt7986_apmixed);
-static int clk_mt7986_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int r;
-
- clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
- if (!clk_data)
- return -ENOMEM;
-
- mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r) {
- pr_err("%s(): could not register clock provider: %d\n",
- __func__, r);
- goto free_apmixed_data;
- }
- return r;
-
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
static struct platform_driver clk_mt7986_apmixed_drv = {
- .probe = clk_mt7986_apmixed_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt7986-apmixed",
.of_match_table = of_match_clk_mt7986_apmixed,
},
};
-builtin_platform_driver(clk_mt7986_apmixed_drv);
+module_platform_driver(clk_mt7986_apmixed_drv);
MODULE_DESCRIPTION("MediaTek MT7986 apmixedsys clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 25/35] clk: mediatek: mt7988-apmixed: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (23 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 24/35] clk: mediatek: mt7986-apmixed: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:52 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 26/35] clk: mediatek: mt8135-apmixedsys: " Akari Tsuyukusa
` (9 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT7988 apmixedsys driver used a custom probe to register PLLs but
had no remove callback. With PLL registration and unregistration
handled by the common helpers,
the driver can use mtk_clk_simple_probe() and mtk_clk_simple_remove().
Switch to module_platform_driver() to support module unloading
and ensure that registered clocks are unregistered on removal.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt7988-apmixed.c | 39 ++++++-----------------
1 file changed, 9 insertions(+), 30 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt7988-apmixed.c b/drivers/clk/mediatek/clk-mt7988-apmixed.c
index 24f4e7b87a31..f7bb00e7d17a 100644
--- a/drivers/clk/mediatek/clk-mt7988-apmixed.c
+++ b/drivers/clk/mediatek/clk-mt7988-apmixed.c
@@ -71,47 +71,26 @@ static const struct mtk_pll_data plls[] = {
0, 0x0318, 0, 0x0314),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
+
static const struct of_device_id of_match_clk_mt7988_apmixed[] = {
- { .compatible = "mediatek,mt7988-apmixedsys" },
+ { .compatible = "mediatek,mt7988-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt7988_apmixed);
-static int clk_mt7988_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int r;
-
- clk_data = mtk_alloc_clk_data(ARRAY_SIZE(plls));
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
- if (r)
- goto free_apmixed_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
static struct platform_driver clk_mt7988_apmixed_drv = {
- .probe = clk_mt7988_apmixed_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt7988-apmixed",
.of_match_table = of_match_clk_mt7988_apmixed,
},
};
-builtin_platform_driver(clk_mt7988_apmixed_drv);
+module_platform_driver(clk_mt7988_apmixed_drv);
MODULE_DESCRIPTION("MediaTek MT7988 apmixedsys clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 26/35] clk: mediatek: mt8135-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (24 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 25/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 16:50 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 27/35] clk: mediatek: mt8167-apmixedsys: " Akari Tsuyukusa
` (8 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8135 apmixedsys driver previously needed custom probe/remove
callbacks to register and unregister PLLs. With PLL support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 50 +++-----------------
1 file changed, 7 insertions(+), 43 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8135-apmixedsys.c b/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
index e3b7dc13b458..fe868417de48 100644
--- a/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
@@ -47,56 +47,20 @@ static const struct mtk_pll_data plls[] = {
PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x304, 0x31c, 0x80000000, 0, 21, 0x2b0, 6, 0x0, 0x308, 0),
};
-static int clk_mt8135_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int ret;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls),
- clk_data);
- if (ret)
- goto free_clk_data;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
-
- return ret;
-}
-
-static void clk_mt8135_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
- mtk_free_clk_data(clk_data);
-}
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
static const struct of_device_id of_match_clk_mt8135_apmixed[] = {
- { .compatible = "mediatek,mt8135-apmixedsys" },
+ { .compatible = "mediatek,mt8135-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8135_apmixed);
static struct platform_driver clk_mt8135_apmixed_drv = {
- .probe = clk_mt8135_apmixed_probe,
- .remove = clk_mt8135_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8135-apmixed",
.of_match_table = of_match_clk_mt8135_apmixed,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 27/35] clk: mediatek: mt8167-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (25 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 26/35] clk: mediatek: mt8135-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 28/35] clk: mediatek: mt8173-infracfg: " Akari Tsuyukusa
` (7 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8167 apmixedsys driver used a custom probe to register PLLs and
divider clocks but had no remove callback. With PLL registration now
supported alongside the existing divider-clock support,
the driver can use mtk_clk_simple_probe() and mtk_clk_simple_remove().
Switch to module_platform_driver() to support module unloading and
ensure that registered clocks are unregistered on removal.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
- Add missing `.data = &apmixed_desc` entry to the OF match table.
---
drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 58 ++++++--------------
1 file changed, 16 insertions(+), 42 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8167-apmixedsys.c b/drivers/clk/mediatek/clk-mt8167-apmixedsys.c
index fb6c21bbeef8..aba33e5aafe6 100644
--- a/drivers/clk/mediatek/clk-mt8167-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8167-apmixedsys.c
@@ -89,59 +89,33 @@ static const struct mtk_clk_divider adj_divs[] = {
0x1c4, 24, 3, CLK_DIVIDER_POWER_OF_TWO),
};
-static int clk_mt8167_apmixed_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- struct device *dev = &pdev->dev;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_devm_alloc_clk_data(dev, MT8167_CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_clk_register_plls(dev, plls, ARRAY_SIZE(plls), clk_data);
- if (ret)
- return ret;
-
- ret = mtk_clk_register_dividers(dev, adj_divs, ARRAY_SIZE(adj_divs), base,
- &mt8167_apmixed_clk_lock, clk_data);
- if (ret)
- goto unregister_plls;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_dividers;
-
- return 0;
-
-unregister_dividers:
- mtk_clk_unregister_dividers(adj_divs, ARRAY_SIZE(adj_divs), clk_data);
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-
- return ret;
-}
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .divider_clks = adj_divs,
+ .num_divider_clks = ARRAY_SIZE(adj_divs),
+ .clk_lock = &mt8167_apmixed_clk_lock,
+};
static const struct of_device_id of_match_clk_mt8167_apmixed[] = {
- { .compatible = "mediatek,mt8167-apmixedsys" },
- { /* sentinel */ }
+ {
+ .compatible = "mediatek,mt8167-apmixedsys",
+ .data = &apmixed_desc,
+ }, {
+ /* sentinel */
+ },
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8167_apmixed);
static struct platform_driver clk_mt8167_apmixed_drv = {
- .probe = clk_mt8167_apmixed_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8167-apmixed",
.of_match_table = of_match_clk_mt8167_apmixed,
},
};
-builtin_platform_driver(clk_mt8167_apmixed_drv)
+module_platform_driver(clk_mt8167_apmixed_drv)
MODULE_DESCRIPTION("MediaTek MT8167 apmixedsys clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 28/35] clk: mediatek: mt8173-infracfg: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (26 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 27/35] clk: mediatek: mt8167-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 17:01 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 29/35] clk: mediatek: mt8183: " Akari Tsuyukusa
` (6 subsequent siblings)
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8173 infracfg driver previously needed custom probe/remove
callbacks to register and unregister cpumux. With cpumux support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Drop the CLK_OF_DECLARE_DRIVER early init for infracfg; the kernel's
deferred probe mechanism ensures dependent drivers like cpufreq are
initialized correctly.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8173-infracfg.c | 100 ++++-----------------
1 file changed, 16 insertions(+), 84 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8173-infracfg.c b/drivers/clk/mediatek/clk-mt8173-infracfg.c
index 9b8c35897789..fdd994736e83 100644
--- a/drivers/clk/mediatek/clk-mt8173-infracfg.c
+++ b/drivers/clk/mediatek/clk-mt8173-infracfg.c
@@ -17,22 +17,20 @@
GATE_MTK(_id, _name, _parent, &infra_cg_regs, \
_shift, &mtk_clk_gate_ops_setclr)
-static struct clk_hw_onecell_data *infra_clk_data;
-
static const struct mtk_gate_regs infra_cg_regs = {
.set_ofs = 0x0040,
.clr_ofs = 0x0044,
.sta_ofs = 0x0048,
};
-static const char * const ca53_parents[] __initconst = {
+static const char * const ca53_parents[] = {
"clk26m",
"armca7pll",
"mainpll",
"univpll"
};
-static const char * const ca72_parents[] __initconst = {
+static const char * const ca72_parents[] = {
"clk26m",
"armca15pll",
"mainpll",
@@ -44,7 +42,7 @@ static const struct mtk_composite cpu_muxes[] = {
MUX(CLK_INFRA_CA72SEL, "infra_ca72_sel", ca72_parents, 0x0000, 2, 2),
};
-static const struct mtk_fixed_factor infra_early_divs[] = {
+static const struct mtk_fixed_factor infra_divs[] = {
FACTOR(CLK_INFRA_CLK_13M, "clk13m", "clk26m", 1, 2),
};
@@ -70,95 +68,29 @@ static const struct mtk_clk_rst_desc clk_rst_desc = {
.rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
};
+static const struct mtk_clk_desc infracfg_desc = {
+ .clks = infra_gates,
+ .num_clks = ARRAY_SIZE(infra_gates),
+ .factor_clks = infra_divs,
+ .num_factor_clks = ARRAY_SIZE(infra_divs),
+ .cpumuxes = cpu_muxes,
+ .num_cpumuxes = ARRAY_SIZE(cpu_muxes),
+ .rst_desc = &clk_rst_desc,
+};
+
static const struct of_device_id of_match_clk_mt8173_infracfg[] = {
- { .compatible = "mediatek,mt8173-infracfg" },
+ { .compatible = "mediatek,mt8173-infracfg", .data = &infracfg_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8173_infracfg);
-static void clk_mt8173_infra_init_early(struct device_node *node)
-{
- int i;
-
- infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
- if (!infra_clk_data)
- return;
-
- for (i = 0; i < CLK_INFRA_NR_CLK; i++)
- infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
-
- mtk_clk_register_factors(infra_early_divs,
- ARRAY_SIZE(infra_early_divs), infra_clk_data);
-
- of_clk_add_hw_provider(node, of_clk_hw_onecell_get, infra_clk_data);
-}
-CLK_OF_DECLARE_DRIVER(mtk_infrasys, "mediatek,mt8173-infracfg",
- clk_mt8173_infra_init_early);
-
-static int clk_mt8173_infracfg_probe(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- int r, i;
-
- if (!infra_clk_data) {
- infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
- if (!infra_clk_data)
- return -ENOMEM;
- } else {
- for (i = 0; i < CLK_INFRA_NR_CLK; i++)
- if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
- infra_clk_data->hws[i] = ERR_PTR(-ENOENT);
- }
-
- r = mtk_clk_register_gates(&pdev->dev, node, infra_gates,
- ARRAY_SIZE(infra_gates), infra_clk_data);
- if (r)
- return r;
-
- r = mtk_clk_register_cpumuxes(&pdev->dev, node, cpu_muxes,
- ARRAY_SIZE(cpu_muxes), infra_clk_data);
- if (r)
- goto unregister_gates;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, infra_clk_data);
- if (r)
- goto unregister_cpumuxes;
-
- r = mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc);
- if (r)
- goto unregister_clk_hw;
-
- platform_set_drvdata(pdev, infra_clk_data);
-
- return 0;
-
-unregister_clk_hw:
- of_clk_del_provider(node);
-unregister_cpumuxes:
- mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), infra_clk_data);
-unregister_gates:
- mtk_clk_unregister_gates(infra_gates, ARRAY_SIZE(infra_gates), infra_clk_data);
- return r;
-}
-
-static void clk_mt8173_infracfg_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_cpumuxes(cpu_muxes, ARRAY_SIZE(cpu_muxes), clk_data);
- mtk_clk_unregister_gates(infra_gates, ARRAY_SIZE(infra_gates), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8173_infracfg_drv = {
.driver = {
.name = "clk-mt8173-infracfg",
.of_match_table = of_match_clk_mt8173_infracfg,
},
- .probe = clk_mt8173_infracfg_probe,
- .remove = clk_mt8173_infracfg_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
};
module_platform_driver(clk_mt8173_infracfg_drv);
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 29/35] clk: mediatek: mt8183: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (27 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 28/35] clk: mediatek: mt8173-infracfg: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 30/35] clk: mediatek: mt8186-apmixedsys: " Akari Tsuyukusa
` (5 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8183 apmixedsys driver used a custom probe to register PLLs and
gates but had no remove callback. The audiosys driver used custom
probe/remove callbacks to populate and depopulate child devices.
With PLL registration and child-device population supported by the
common helpers, both drivers can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Switch the apmixedsys driver to module_platform_driver() so its clocks
are properly unregistered on module removal.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 51 ++++----------------
drivers/clk/mediatek/clk-mt8183-audio.c | 26 ++--------
2 files changed, 13 insertions(+), 64 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8183-apmixedsys.c b/drivers/clk/mediatek/clk-mt8183-apmixedsys.c
index 6242d4f5376e..deb96537a3ab 100644
--- a/drivers/clk/mediatek/clk-mt8183-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8183-apmixedsys.c
@@ -139,59 +139,28 @@ static const struct mtk_pll_data plls[] = {
0, 0, 32, 8, 0x02B4, 1, 0x02BC, 0x0014, 1, 0x02B8, 0, 0x02B4),
};
-static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- struct device *dev = &pdev->dev;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_devm_alloc_clk_data(dev, CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_clk_register_plls(dev, plls, ARRAY_SIZE(plls), clk_data);
- if (ret)
- return ret;
-
- ret = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
- if (ret)
- goto unregister_plls;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_gates;
-
- return 0;
-
-unregister_gates:
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-
- return ret;
-}
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+};
static const struct of_device_id of_match_clk_mt8183_apmixed[] = {
- { .compatible = "mediatek,mt8183-apmixedsys" },
+ { .compatible = "mediatek,mt8183-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8183_apmixed);
static struct platform_driver clk_mt8183_apmixed_drv = {
- .probe = clk_mt8183_apmixed_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8183-apmixed",
.of_match_table = of_match_clk_mt8183_apmixed,
},
};
-builtin_platform_driver(clk_mt8183_apmixed_drv)
+module_platform_driver(clk_mt8183_apmixed_drv)
MODULE_DESCRIPTION("MediaTek MT8183 apmixedsys clocks driver");
MODULE_LICENSE("GPL");
diff --git a/drivers/clk/mediatek/clk-mt8183-audio.c b/drivers/clk/mediatek/clk-mt8183-audio.c
index 011d329ad30e..0a53b0408dcc 100644
--- a/drivers/clk/mediatek/clk-mt8183-audio.c
+++ b/drivers/clk/mediatek/clk-mt8183-audio.c
@@ -70,29 +70,9 @@ static const struct mtk_gate audio_clks[] = {
static const struct mtk_clk_desc audio_desc = {
.clks = audio_clks,
.num_clks = ARRAY_SIZE(audio_clks),
+ .populate_children = true,
};
-static int clk_mt8183_audio_probe(struct platform_device *pdev)
-{
- int r;
-
- r = mtk_clk_simple_probe(pdev);
- if (r)
- return r;
-
- r = devm_of_platform_populate(&pdev->dev);
- if (r)
- mtk_clk_simple_remove(pdev);
-
- return r;
-}
-
-static void clk_mt8183_audio_remove(struct platform_device *pdev)
-{
- of_platform_depopulate(&pdev->dev);
- mtk_clk_simple_remove(pdev);
-}
-
static const struct of_device_id of_match_clk_mt8183_audio[] = {
{ .compatible = "mediatek,mt8183-audiosys", .data = &audio_desc },
{ /* sentinel */ }
@@ -100,8 +80,8 @@ static const struct of_device_id of_match_clk_mt8183_audio[] = {
MODULE_DEVICE_TABLE(of, of_match_clk_mt8183_audio);
static struct platform_driver clk_mt8183_audio_drv = {
- .probe = clk_mt8183_audio_probe,
- .remove = clk_mt8183_audio_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8183-audio",
.of_match_table = of_match_clk_mt8183_audio,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 30/35] clk: mediatek: mt8186-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (28 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 29/35] clk: mediatek: mt8183: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 31/35] clk: mediatek: mt8188-apmixedsys: " Akari Tsuyukusa
` (4 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8186 apmixedsys driver previously needed custom probe/remove
callbacks to configure FHCTL for PLL frequency hopping and
register/unregister the affected PLL clocks. With PLL and FHCTL support
now available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 59 ++++----------------
1 file changed, 11 insertions(+), 48 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8186-apmixedsys.c b/drivers/clk/mediatek/clk-mt8186-apmixedsys.c
index d35dd2632e43..b674b1e581a5 100644
--- a/drivers/clk/mediatek/clk-mt8186-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8186-apmixedsys.c
@@ -132,60 +132,23 @@ static struct mtk_pllfh_data pllfhs[] = {
FH(CLK_APMIXED_MSDCPLL, FH_MSDCPLL, 0x0118),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .fhctl_node = "mediatek,mt8186-fhctl",
+ .pllfhs = pllfhs,
+ .num_pllfhs = ARRAY_SIZE(pllfhs),
+};
+
static const struct of_device_id of_match_clk_mt8186_apmixed[] = {
- { .compatible = "mediatek,mt8186-apmixedsys", },
+ { .compatible = "mediatek,mt8186-apmixedsys", .data = &apmixed_desc },
{}
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8186_apmixed);
-static int clk_mt8186_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const u8 *fhctl_node = "mediatek,mt8186-fhctl";
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs));
-
- r = mtk_clk_register_pllfhs(&pdev->dev, plls, ARRAY_SIZE(plls),
- pllfhs, ARRAY_SIZE(pllfhs), clk_data);
- if (r)
- goto free_apmixed_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8186_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8186_apmixed_drv = {
- .probe = clk_mt8186_apmixed_probe,
- .remove = clk_mt8186_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8186-apmixed",
.of_match_table = of_match_clk_mt8186_apmixed,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 31/35] clk: mediatek: mt8188-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (29 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 30/35] clk: mediatek: mt8186-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 32/35] clk: mediatek: mt8192: " Akari Tsuyukusa
` (3 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8188 apmixedsys driver previously needed custom probe/remove
callbacks to register and unregister PLLs. With PLL support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 60 ++++----------------
1 file changed, 10 insertions(+), 50 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8188-apmixedsys.c b/drivers/clk/mediatek/clk-mt8188-apmixedsys.c
index 48a2f61d4b77..3937d93cac34 100644
--- a/drivers/clk/mediatek/clk-mt8188-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8188-apmixedsys.c
@@ -89,62 +89,22 @@ static const struct mtk_pll_data plls[] = {
0, 0, 22, 0x0344, 24, 0, 0, 0, 0x0344, 0, 0, 0, 9),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+};
+
static const struct of_device_id of_match_clk_mt8188_apmixed[] = {
- { .compatible = "mediatek,mt8188-apmixedsys" },
+ { .compatible = "mediatek,mt8188-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8188_apmixed);
-static int clk_mt8188_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
- if (r)
- goto free_apmixed_data;
-
- r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
- if (r)
- goto unregister_plls;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_gates;
-
- platform_set_drvdata(pdev, clk_data);
-
- return 0;
-
-unregister_gates:
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8188_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8188_apmixed_drv = {
- .probe = clk_mt8188_apmixed_probe,
- .remove = clk_mt8188_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8188-apmixed",
.of_match_table = of_match_clk_mt8188_apmixed,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 32/35] clk: mediatek: mt8192: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (30 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 31/35] clk: mediatek: mt8188-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 33/35] clk: mediatek: mt8195: " Akari Tsuyukusa
` (2 subsequent siblings)
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8192 apmixedsys driver previously needed custom probe/remove
callbacks to configure FHCTL and register FHCTL clocks. With FHCTL
support now available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
The audsys driver can also use the common helpers, which now
support populating child devices.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 69 ++++----------------
drivers/clk/mediatek/clk-mt8192-aud.c | 26 +-------
2 files changed, 16 insertions(+), 79 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8192-apmixedsys.c b/drivers/clk/mediatek/clk-mt8192-apmixedsys.c
index e6ac40e2f12d..92593370f23b 100644
--- a/drivers/clk/mediatek/clk-mt8192-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8192-apmixedsys.c
@@ -143,72 +143,29 @@ static struct mtk_pllfh_data pllfhs[] = {
FH(CLK_APMIXED_TVDPLL, FH_TVDPLL, 0x154),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .fhctl_node = "mediatek,mt8192-fhctl",
+ .pllfhs = pllfhs,
+ .num_pllfhs = ARRAY_SIZE(pllfhs),
+};
+
static const struct of_device_id of_match_clk_mt8192_apmixed[] = {
- { .compatible = "mediatek,mt8192-apmixedsys" },
+ { .compatible = "mediatek,mt8192-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8192_apmixed);
-static int clk_mt8192_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const u8 *fhctl_node = "mediatek,mt8192-fhctl";
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs));
-
- r = mtk_clk_register_pllfhs(&pdev->dev, plls, ARRAY_SIZE(plls),
- pllfhs, ARRAY_SIZE(pllfhs), clk_data);
- if (r)
- goto free_clk_data;
-
- r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
- if (r)
- goto unregister_plls;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_gates;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_gates:
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
-unregister_plls:
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8192_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8192_apmixed_drv = {
.driver = {
.name = "clk-mt8192-apmixed",
.of_match_table = of_match_clk_mt8192_apmixed,
},
- .probe = clk_mt8192_apmixed_probe,
- .remove = clk_mt8192_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
};
module_platform_driver(clk_mt8192_apmixed_drv);
MODULE_DESCRIPTION("MediaTek MT8192 apmixed clocks driver");
diff --git a/drivers/clk/mediatek/clk-mt8192-aud.c b/drivers/clk/mediatek/clk-mt8192-aud.c
index f3ebf8713fbb..8625f656a2e4 100644
--- a/drivers/clk/mediatek/clk-mt8192-aud.c
+++ b/drivers/clk/mediatek/clk-mt8192-aud.c
@@ -80,29 +80,9 @@ static const struct mtk_gate aud_clks[] = {
static const struct mtk_clk_desc aud_desc = {
.clks = aud_clks,
.num_clks = ARRAY_SIZE(aud_clks),
+ .populate_children = true,
};
-static int clk_mt8192_aud_probe(struct platform_device *pdev)
-{
- int r;
-
- r = mtk_clk_simple_probe(pdev);
- if (r)
- return r;
-
- r = devm_of_platform_populate(&pdev->dev);
- if (r)
- mtk_clk_simple_remove(pdev);
-
- return r;
-}
-
-static void clk_mt8192_aud_remove(struct platform_device *pdev)
-{
- of_platform_depopulate(&pdev->dev);
- mtk_clk_simple_remove(pdev);
-}
-
static const struct of_device_id of_match_clk_mt8192_aud[] = {
{ .compatible = "mediatek,mt8192-audsys", .data = &aud_desc },
{ /* sentinel */ }
@@ -110,8 +90,8 @@ static const struct of_device_id of_match_clk_mt8192_aud[] = {
MODULE_DEVICE_TABLE(of, of_match_clk_mt8192_aud);
static struct platform_driver clk_mt8192_aud_drv = {
- .probe = clk_mt8192_aud_probe,
- .remove = clk_mt8192_aud_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8192-aud",
.of_match_table = of_match_clk_mt8192_aud,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 33/35] clk: mediatek: mt8195: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (31 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 32/35] clk: mediatek: mt8192: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 34/35] clk: mediatek: mt8196: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 35/35] clk: mediatek: mt8516-apmixedsys: " Akari Tsuyukusa
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8195 apmixedsys driver previously needed custom probe/remove
callbacks to configure FHCTL and register/unregister FHCTL clocks.
The apusys_pll driver also needed custom callbacks to register and
unregister regular PLLs. With FHCTL and PLL registration supported
by the common helpers, both drivers can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
Note that the topckgen driver is excluded from this conversion because
it requires devm_mtk_clk_mux_notifier_register(), which is not
currently supported by the common simple probe helper.
Enable module builds by changing the Kconfig setting to "tristate".
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
- Add missing `.data = &apmixed_desc` entry to the OF match table.
---
drivers/clk/mediatek/Kconfig | 12 ++--
drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 75 +++++---------------
drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 49 ++-----------
3 files changed, 31 insertions(+), 105 deletions(-)
diff --git a/drivers/clk/mediatek/Kconfig b/drivers/clk/mediatek/Kconfig
index 54ecf2692607..2a25cf6991fc 100644
--- a/drivers/clk/mediatek/Kconfig
+++ b/drivers/clk/mediatek/Kconfig
@@ -919,13 +919,13 @@ config COMMON_CLK_MT8192_VENCSYS
This driver supports MediaTek MT8192 vencsys clocks.
config COMMON_CLK_MT8195
- bool "Clock driver for MediaTek MT8195"
- depends on ARM64 || COMPILE_TEST
- select COMMON_CLK_MEDIATEK
+ tristate "Clock driver for MediaTek MT8195"
+ depends on ARM64 || COMPILE_TEST
+ select COMMON_CLK_MEDIATEK
select COMMON_CLK_MEDIATEK_FHCTL
- default ARCH_MEDIATEK
- help
- This driver supports MediaTek MT8195 clocks.
+ default ARCH_MEDIATEK
+ help
+ This driver supports MediaTek MT8195 clocks.
config COMMON_CLK_MT8195_APUSYS
tristate "Clock driver for MediaTek MT8195 apusys"
diff --git a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
index a120c3305547..b79a423d25f8 100644
--- a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
@@ -161,68 +161,29 @@ static struct mtk_pllfh_data pllfhs[] = {
FH(CLK_APMIXED_TVDPLL2, FH_TVDPLL1, 0x154),
};
+static const struct mtk_clk_desc apmixed_desc = {
+ .clks = apmixed_clks,
+ .num_clks = ARRAY_SIZE(apmixed_clks),
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+ .fhctl_node = "mediatek,mt8195-fhctl",
+ .pllfhs = pllfhs,
+ .num_pllfhs = ARRAY_SIZE(pllfhs),
+};
+
static const struct of_device_id of_match_clk_mt8195_apmixed[] = {
- { .compatible = "mediatek,mt8195-apmixedsys", },
- {}
+ {
+ .compatible = "mediatek,mt8195-apmixedsys",
+ .data = &apmixed_desc,
+ }, {
+ /* sentinel */
+ },
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8195_apmixed);
-static int clk_mt8195_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const u8 *fhctl_node = "mediatek,mt8195-fhctl";
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- fhctl_parse_dt(fhctl_node, pllfhs, ARRAY_SIZE(pllfhs));
-
- r = mtk_clk_register_pllfhs(&pdev->dev, plls, ARRAY_SIZE(plls),
- pllfhs, ARRAY_SIZE(pllfhs), clk_data);
- if (r)
- goto free_apmixed_data;
-
- r = mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
- ARRAY_SIZE(apmixed_clks), clk_data);
- if (r)
- goto unregister_plls;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_gates;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_gates:
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
-unregister_plls:
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8195_apmixed_remove(struct platform_device *pdev)
-{
- struct device_node *node = pdev->dev.of_node;
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
-
- of_clk_del_provider(node);
- mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
- mtk_clk_unregister_pllfhs(plls, ARRAY_SIZE(plls), pllfhs,
- ARRAY_SIZE(pllfhs), clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8195_apmixed_drv = {
- .probe = clk_mt8195_apmixed_probe,
- .remove = clk_mt8195_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8195-apmixed",
.of_match_table = of_match_clk_mt8195_apmixed,
diff --git a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
index a2d98ed58e34..36d358141ecb 100644
--- a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
+++ b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
@@ -56,55 +56,20 @@ static const struct mtk_pll_data apusys_plls[] = {
PLL(CLK_APUSYS_PLL_APUPLL2, "apusys_pll_apupll2", 0x038, 0x044, 0x03c, 0x03c),
};
-static int clk_mt8195_apusys_pll_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- int r;
-
- clk_data = mtk_alloc_clk_data(CLK_APUSYS_PLL_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, apusys_plls,
- ARRAY_SIZE(apusys_plls), clk_data);
- if (r)
- goto free_apusys_pll_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_plls(apusys_plls, ARRAY_SIZE(apusys_plls), clk_data);
-free_apusys_pll_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8195_apusys_pll_remove(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
- struct device_node *node = pdev->dev.of_node;
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(apusys_plls, ARRAY_SIZE(apusys_plls), clk_data);
- mtk_free_clk_data(clk_data);
-}
+static const struct mtk_clk_desc apu_pll_desc = {
+ .plls = apusys_plls,
+ .num_plls = ARRAY_SIZE(apusys_plls),
+};
static const struct of_device_id of_match_clk_mt8195_apusys_pll[] = {
- { .compatible = "mediatek,mt8195-apusys_pll", },
+ { .compatible = "mediatek,mt8195-apusys_pll", .data = &apu_pll_desc },
{}
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8195_apusys_pll);
static struct platform_driver clk_mt8195_apusys_pll_drv = {
- .probe = clk_mt8195_apusys_pll_probe,
- .remove = clk_mt8195_apusys_pll_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8195-apusys_pll",
.of_match_table = of_match_clk_mt8195_apusys_pll,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 34/35] clk: mediatek: mt8196: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (32 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 33/35] clk: mediatek: mt8195: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
2026-10-13 17:24 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 35/35] clk: mediatek: mt8516-apmixedsys: " Akari Tsuyukusa
34 siblings, 1 reply; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8196 apmixedsys, mcusys, and mfg drivers use
MT8196-specific PLL descriptors or pass PLL data directly
as match data, requiring custom probe/remove callbacks.
Represent these PLL configurations using struct mtk_clk_desc
so the drivers can use mtk_clk_simple_probe() and
mtk_clk_simple_remove().
Keep the vlpckgen driver unchanged because its probe callback
also initializes APLL tuner registers, which are not yet
supported by the common helpers.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 67 ++------------
drivers/clk/mediatek/clk-mt8196-mcu.c | 96 +++++++-------------
drivers/clk/mediatek/clk-mt8196-mfg.c | 84 +++++------------
3 files changed, 63 insertions(+), 184 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8196-apmixedsys.c b/drivers/clk/mediatek/clk-mt8196-apmixedsys.c
index c4ebb0170b82..a20fa02070a8 100644
--- a/drivers/clk/mediatek/clk-mt8196-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8196-apmixedsys.c
@@ -86,11 +86,6 @@
.ops = &mtk_pll_fenc_clr_set_ops, \
}
-struct mtk_pll_desc {
- const struct mtk_pll_data *clks;
- size_t num_clks;
-};
-
static const struct mtk_pll_data apmixed_plls[] = {
PLL_FENC(CLK_APMIXED_MAINPLL, "mainpll", MAINPLL_CON0, FENC_STATUS_CON0,
7, PLL_AO, MAINPLL_CON1, 24, MAINPLL_CON1, 0, 22, 0),
@@ -110,9 +105,9 @@ static const struct mtk_pll_data apmixed_plls[] = {
0, 0, SGMIIPLL_CON1, 24, SGMIIPLL_CON1, 0, 22, 7),
};
-static const struct mtk_pll_desc apmixed_desc = {
- .clks = apmixed_plls,
- .num_clks = ARRAY_SIZE(apmixed_plls),
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = apmixed_plls,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
};
static const struct mtk_pll_data apmixed2_plls[] = {
@@ -132,57 +127,11 @@ static const struct mtk_pll_data apmixed2_plls[] = {
0, 0, TVDPLL3_CON1, 24, TVDPLL3_CON1, 0, 22, 6),
};
-static const struct mtk_pll_desc apmixed2_desc = {
- .clks = apmixed2_plls,
- .num_clks = ARRAY_SIZE(apmixed2_plls),
+static const struct mtk_clk_desc apmixed2_desc = {
+ .plls = apmixed2_plls,
+ .num_plls = ARRAY_SIZE(apmixed2_plls),
};
-static int clk_mt8196_apmixed_probe(struct platform_device *pdev)
-{
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const struct mtk_pll_desc *mcd;
- int r;
-
- mcd = device_get_match_data(&pdev->dev);
- if (!mcd)
- return -EINVAL;
-
- clk_data = mtk_alloc_clk_data(mcd->num_clks);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, mcd->clks, mcd->num_clks,
- clk_data);
- if (r)
- goto free_apmixed_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_plls(mcd->clks, mcd->num_clks, clk_data);
-free_apmixed_data:
- mtk_free_clk_data(clk_data);
- return r;
-}
-
-static void clk_mt8196_apmixed_remove(struct platform_device *pdev)
-{
- const struct mtk_pll_desc *mcd = device_get_match_data(&pdev->dev);
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
- struct device_node *node = pdev->dev.of_node;
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(mcd->clks, mcd->num_clks, clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static const struct of_device_id of_match_clk_mt8196_apmixed[] = {
{ .compatible = "mediatek,mt8196-apmixedsys", .data = &apmixed_desc },
{ .compatible = "mediatek,mt8196-apmixedsys-gp2",
@@ -192,8 +141,8 @@ static const struct of_device_id of_match_clk_mt8196_apmixed[] = {
MODULE_DEVICE_TABLE(of, of_match_clk_mt8196_apmixed);
static struct platform_driver clk_mt8196_apmixed_drv = {
- .probe = clk_mt8196_apmixed_probe,
- .remove = clk_mt8196_apmixed_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8196-apmixed",
.of_match_table = of_match_clk_mt8196_apmixed,
diff --git a/drivers/clk/mediatek/clk-mt8196-mcu.c b/drivers/clk/mediatek/clk-mt8196-mcu.c
index 13642fc673c2..e392408c93b2 100644
--- a/drivers/clk/mediatek/clk-mt8196-mcu.c
+++ b/drivers/clk/mediatek/clk-mt8196-mcu.c
@@ -68,29 +68,44 @@
.pcwibits = MT8196_INTEGER_BITS, \
}
-static const struct mtk_pll_data cpu_bl_plls[] = {
- PLL(CLK_CPBL_ARMPLL_BL, "armpll-bl", ARMPLL_BL_CON0, ARMPLL_BL_CON0, 0,
- 0, PLL_AO, BIT(0), ARMPLL_BL_CON1, 24, 0, 0, 0, ARMPLL_BL_CON1, 0, 22),
+static const struct mtk_clk_desc cpu_bl_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_CPBL_ARMPLL_BL, "armpll-bl", ARMPLL_BL_CON0, ARMPLL_BL_CON0, 0,
+ 0, PLL_AO, BIT(0), ARMPLL_BL_CON1, 24, 0, 0, 0, ARMPLL_BL_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
-static const struct mtk_pll_data cpu_b_plls[] = {
- PLL(CLK_CPB_ARMPLL_B, "armpll-b", ARMPLL_B_CON0, ARMPLL_B_CON0, 0, 0,
- PLL_AO, BIT(0), ARMPLL_B_CON1, 24, 0, 0, 0, ARMPLL_B_CON1, 0, 22),
+static const struct mtk_clk_desc cpu_b_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_CPB_ARMPLL_B, "armpll-b", ARMPLL_B_CON0, ARMPLL_B_CON0, 0, 0,
+ PLL_AO, BIT(0), ARMPLL_B_CON1, 24, 0, 0, 0, ARMPLL_B_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
-static const struct mtk_pll_data cpu_ll_plls[] = {
- PLL(CLK_CPLL_ARMPLL_LL, "armpll-ll", ARMPLL_LL_CON0, ARMPLL_LL_CON0, 0,
- 0, PLL_AO, BIT(0), ARMPLL_LL_CON1, 24, 0, 0, 0, ARMPLL_LL_CON1, 0, 22),
+static const struct mtk_clk_desc cpu_ll_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_CPLL_ARMPLL_LL, "armpll-ll", ARMPLL_LL_CON0, ARMPLL_LL_CON0, 0,
+ 0, PLL_AO, BIT(0), ARMPLL_LL_CON1, 24, 0, 0, 0, ARMPLL_LL_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
-static const struct mtk_pll_data cci_plls[] = {
- PLL(CLK_CCIPLL, "ccipll", CCIPLL_CON0, CCIPLL_CON0, 0, 0, PLL_AO,
- BIT(0), CCIPLL_CON1, 24, 0, 0, 0, CCIPLL_CON1, 0, 22),
+static const struct mtk_clk_desc cci_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_CCIPLL, "ccipll", CCIPLL_CON0, CCIPLL_CON0, 0, 0, PLL_AO,
+ BIT(0), CCIPLL_CON1, 24, 0, 0, 0, CCIPLL_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
-static const struct mtk_pll_data ptp_plls[] = {
- PLL(CLK_PTPPLL, "ptppll", PTPPLL_CON0, PTPPLL_CON0, 0, 0, PLL_AO,
- BIT(0), PTPPLL_CON1, 24, 0, 0, 0, PTPPLL_CON1, 0, 22),
+static const struct mtk_clk_desc ptp_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_PTPPLL, "ptppll", PTPPLL_CON0, PTPPLL_CON0, 0, 0, PLL_AO,
+ BIT(0), PTPPLL_CON1, 24, 0, 0, 0, PTPPLL_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
static const struct of_device_id of_match_clk_mt8196_mcu[] = {
@@ -106,56 +121,9 @@ static const struct of_device_id of_match_clk_mt8196_mcu[] = {
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8196_mcu);
-static int clk_mt8196_mcu_probe(struct platform_device *pdev)
-{
- const struct mtk_pll_data *plls;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const int num_plls = 1;
- int r;
-
- plls = of_device_get_match_data(&pdev->dev);
- if (!plls)
- return -EINVAL;
-
- clk_data = mtk_alloc_clk_data(num_plls);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, plls, num_plls, clk_data);
- if (r)
- goto free_clk_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_plls(plls, num_plls, clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
-
- return r;
-}
-
-static void clk_mt8196_mcu_remove(struct platform_device *pdev)
-{
- const struct mtk_pll_data *plls = of_device_get_match_data(&pdev->dev);
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
- struct device_node *node = pdev->dev.of_node;
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(plls, 1, clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8196_mcu_drv = {
- .probe = clk_mt8196_mcu_probe,
- .remove = clk_mt8196_mcu_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8196-mcu",
.of_match_table = of_match_clk_mt8196_mcu,
diff --git a/drivers/clk/mediatek/clk-mt8196-mfg.c b/drivers/clk/mediatek/clk-mt8196-mfg.c
index a317183f1681..a209162f6207 100644
--- a/drivers/clk/mediatek/clk-mt8196-mfg.c
+++ b/drivers/clk/mediatek/clk-mt8196-mfg.c
@@ -61,22 +61,31 @@
.parent_name = "mfg_eb", \
}
-static const struct mtk_pll_data mfg_ao_plls[] = {
- PLL(CLK_MFG_AO_MFGPLL, "mfgpll", MFGPLL_CON0, MFGPLL_CON0, 0, 0,
- PLL_PARENT_EN, BIT(0), MFGPLL_CON1, 24, 0, 0, 0,
- MFGPLL_CON1, 0, 22),
+static const struct mtk_clk_desc mfg_ao_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_MFG_AO_MFGPLL, "mfgpll", MFGPLL_CON0,
+ MFGPLL_CON0, 0, 0, PLL_PARENT_EN, BIT(0),
+ MFGPLL_CON1, 24, 0, 0, 0, MFGPLL_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
-static const struct mtk_pll_data mfgsc0_ao_plls[] = {
- PLL(CLK_MFGSC0_AO_MFGPLL_SC0, "mfgpll-sc0", MFGPLL_SC0_CON0,
- MFGPLL_SC0_CON0, 0, 0, PLL_PARENT_EN, BIT(0), MFGPLL_SC0_CON1, 24,
- 0, 0, 0, MFGPLL_SC0_CON1, 0, 22),
+static const struct mtk_clk_desc mfgsc0_ao_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_MFGSC0_AO_MFGPLL_SC0, "mfgpll-sc0", MFGPLL_SC0_CON0,
+ MFGPLL_SC0_CON0, 0, 0, PLL_PARENT_EN, BIT(0),
+ MFGPLL_SC0_CON1, 24, 0, 0, 0, MFGPLL_SC0_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
-static const struct mtk_pll_data mfgsc1_ao_plls[] = {
- PLL(CLK_MFGSC1_AO_MFGPLL_SC1, "mfgpll-sc1", MFGPLL_SC1_CON0,
- MFGPLL_SC1_CON0, 0, 0, PLL_PARENT_EN, BIT(0), MFGPLL_SC1_CON1, 24,
- 0, 0, 0, MFGPLL_SC1_CON1, 0, 22),
+static const struct mtk_clk_desc mfgsc1_ao_plls = {
+ .plls = (const struct mtk_pll_data[]){
+ PLL(CLK_MFGSC1_AO_MFGPLL_SC1, "mfgpll-sc1", MFGPLL_SC1_CON0,
+ MFGPLL_SC1_CON0, 0, 0, PLL_PARENT_EN, BIT(0),
+ MFGPLL_SC1_CON1, 24, 0, 0, 0, MFGPLL_SC1_CON1, 0, 22),
+ },
+ .num_plls = 1,
};
static const struct of_device_id of_match_clk_mt8196_mfg[] = {
@@ -90,56 +99,9 @@ static const struct of_device_id of_match_clk_mt8196_mfg[] = {
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8196_mfg);
-static int clk_mt8196_mfg_probe(struct platform_device *pdev)
-{
- const struct mtk_pll_data *plls;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- const int num_plls = 1;
- int r;
-
- plls = of_device_get_match_data(&pdev->dev);
- if (!plls)
- return -EINVAL;
-
- clk_data = mtk_alloc_clk_data(num_plls);
- if (!clk_data)
- return -ENOMEM;
-
- r = mtk_clk_register_plls(&pdev->dev, plls, num_plls, clk_data);
- if (r)
- goto free_clk_data;
-
- r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (r)
- goto unregister_plls;
-
- platform_set_drvdata(pdev, clk_data);
-
- return r;
-
-unregister_plls:
- mtk_clk_unregister_plls(plls, num_plls, clk_data);
-free_clk_data:
- mtk_free_clk_data(clk_data);
-
- return r;
-}
-
-static void clk_mt8196_mfg_remove(struct platform_device *pdev)
-{
- const struct mtk_pll_data *plls = of_device_get_match_data(&pdev->dev);
- struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
- struct device_node *node = pdev->dev.of_node;
-
- of_clk_del_provider(node);
- mtk_clk_unregister_plls(plls, 1, clk_data);
- mtk_free_clk_data(clk_data);
-}
-
static struct platform_driver clk_mt8196_mfg_drv = {
- .probe = clk_mt8196_mfg_probe,
- .remove = clk_mt8196_mfg_remove,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8196-mfg",
.of_match_table = of_match_clk_mt8196_mfg,
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* [PATCH v2 35/35] clk: mediatek: mt8516-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
` (33 preceding siblings ...)
2026-10-13 15:17 ` [PATCH v2 34/35] clk: mediatek: mt8196: " Akari Tsuyukusa
@ 2026-10-13 15:17 ` Akari Tsuyukusa
34 siblings, 0 replies; 50+ messages in thread
From: Akari Tsuyukusa @ 2026-10-13 15:17 UTC (permalink / raw)
To: Brian Masney, Jerome Brunet, Matthias Brugger,
AngeloGioacchino Del Regno, Yassine Oudjana, Richard Cochran
Cc: Chen-Yu Tsai, Bartosz Golaszewski, Kees Cook,
Uwe Kleine-König (The Capable Hub), Danilo Krummrich,
Nicolas Frattaroli, Bjorn Helgaas, Takashi Sakamoto,
Haotian Zhang, Miles Chen, Sam Shih, Daniel Golle, Chun-Jie Chen,
Laura Nao, Nícolas F. R. A. Prado,
open list:COMMON CLK FRAMEWORK, open list,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Akari Tsuyukusa
The MT8516 apmixedsys driver used a custom probe to register PLLs but
had no remove callback. With PLL registration and unregistration
handled by the common helpers,
the driver can use mtk_clk_simple_probe() and mtk_clk_simple_remove().
Switch to module_platform_driver() to support module unloading and
ensure that registered clocks are unregistered on removal.
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
---
Changes in v2:
- Improvement of commit messages
---
drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 42 ++++----------------
1 file changed, 8 insertions(+), 34 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8516-apmixedsys.c b/drivers/clk/mediatek/clk-mt8516-apmixedsys.c
index 2a6206cae2f0..2fb09e7acde7 100644
--- a/drivers/clk/mediatek/clk-mt8516-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8516-apmixedsys.c
@@ -71,52 +71,26 @@ static const struct mtk_pll_data plls[] = {
31, 0x01A0, 1, 0x01B4, 0x01A4, 0),
};
-static int clk_mt8516_apmixed_probe(struct platform_device *pdev)
-{
- void __iomem *base;
- struct clk_hw_onecell_data *clk_data;
- struct device_node *node = pdev->dev.of_node;
- struct device *dev = &pdev->dev;
- int ret;
-
- base = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(base))
- return PTR_ERR(base);
-
- clk_data = mtk_devm_alloc_clk_data(dev, CLK_APMIXED_NR_CLK);
- if (!clk_data)
- return -ENOMEM;
-
- ret = mtk_clk_register_plls(dev, plls, ARRAY_SIZE(plls), clk_data);
- if (ret)
- return ret;
-
- ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
- if (ret)
- goto unregister_plls;
-
- return 0;
-
-unregister_plls:
- mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
-
- return ret;
-}
+static const struct mtk_clk_desc apmixed_desc = {
+ .plls = plls,
+ .num_plls = ARRAY_SIZE(plls),
+};
static const struct of_device_id of_match_clk_mt8516_apmixed[] = {
- { .compatible = "mediatek,mt8516-apmixedsys" },
+ { .compatible = "mediatek,mt8516-apmixedsys", .data = &apmixed_desc },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_match_clk_mt8516_apmixed);
static struct platform_driver clk_mt8516_apmixed_drv = {
- .probe = clk_mt8516_apmixed_probe,
+ .probe = mtk_clk_simple_probe,
+ .remove = mtk_clk_simple_remove,
.driver = {
.name = "clk-mt8516-apmixed",
.of_match_table = of_match_clk_mt8516_apmixed,
},
};
-builtin_platform_driver(clk_mt8516_apmixed_drv)
+module_platform_driver(clk_mt8516_apmixed_drv)
MODULE_DESCRIPTION("MediaTek MT8516 apmixedsys clocks driver");
MODULE_LICENSE("GPL");
--
2.56.0
^ permalink raw reply related [flat|nested] 50+ messages in thread
* Re: [PATCH v2 03/35] clk: mediatek: mt7622: Fix memory leak on module removal
2026-10-13 15:17 ` [PATCH v2 03/35] clk: mediatek: mt7622: " Akari Tsuyukusa
@ 2026-10-13 15:34 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 15:34 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] misc: commit message inaccuracy regarding apmixedsys memory leak
--
commit d007de80a8548f3cad6c0b96d9c2662f93cc4b64
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt7622: Fix memory leak on module removal
This commit fixes module removal issues in mt7622-apmixedsys and mt7622-infracfg
by calling platform_set_drvdata() in probe to ensure drvdata is available.
> clk-mt7622-apmixedsys.c and clk-mt7622-infracfg.c do not call
> platform_set_drvdata() during their driver probe callback,
> but their remove callback calls platform_get_drvdata().
> This results in platform_get_drvdata() returning NULL,
> which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
> This leaves clk_data unreleased, causing a memory leak.
[Severity: Medium]
Is this description completely accurate for clk-mt7622-apmixedsys.c?
While this is true for clk-mt7622-infracfg.c, clk-mt7622-apmixedsys.c uses
mtk_devm_alloc_clk_data() to allocate its clk_data, which means the memory
is automatically freed by the devres framework on unbind regardless of
drvdata. It never calls mtk_free_clk_data().
The actual consequence in clk_mt7622_apmixed_remove() is not a memory leak
of the clk_data structure itself, but rather a resource leak of the clocks
in the Common Clock Framework because the unregister functions return early
when passed a NULL clk_data pointer:
mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
Could the commit message be updated to clarify that for apmixedsys, the
issue is a CCF resource leak rather than a memory leak from a missing kfree()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=3
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 02/35] clk: mediatek: mt6795: Fix memory leak on module removal
2026-10-13 15:17 ` [PATCH v2 02/35] clk: mediatek: mt6795: " Akari Tsuyukusa
@ 2026-10-13 15:36 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 15:36 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] clk: mediatek: commit message mischaracterizes bug severity as memory leak instead of kernel panic
--
commit a61ee7f5e1c349f92340b7b9ebe198a23e34b370
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt6795: Fix memory leak on module removal
This commit adds platform_set_drvdata() to the probe functions of three
MediaTek MT6795 clock drivers to properly store the clock data. The commit
message states this missing initialization caused a memory leak during
module removal.
> clk-mt6795-apmixedsys.c, clk-mt6795-infracfg.c and clk-mt6795-pericfg.c
> do not call platform_set_drvdata() during their driver probe callback,
> but their remove callback calls platform_get_drvdata().
> This results in platform_get_drvdata() returning NULL, which leads to
> calling kfree(NULL) in mtk_free_clk_data(NULL).
> This leaves clk_data unreleased, causing a memory leak.
[Severity: Low]
Does the missing platform_set_drvdata() actually cause a kernel panic rather
than a memory leak?
Looking at clk_mt6795_apmixed_remove(), clk_data is dereferenced before
mtk_free_clk_data() is called:
drivers/clk/mediatek/clk-mt6795-apmixedsys.c:clk_mt6795_apmixed_remove() {
...
struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
...
mtk_clk_unregister_ref2usb_tx(clk_data->hws[CLK_APMIXED_REF2USB_TX]);
...
}
If clk_data is NULL, accessing clk_data->hws will cause a NULL pointer
dereference.
Similarly, in clk_mt6795_infracfg_remove(), mtk_clk_unregister_cpumuxes()
is called with the NULL clk_data:
drivers/clk/mediatek/clk-cpumux.c:mtk_clk_unregister_cpumuxes() {
...
for (i = num; i > 0; i--) {
const struct mtk_composite *mux = &clks[i - 1];
if (IS_ERR_OR_NULL(clk_data->hws[mux->id]))
continue;
...
}
This also dereferences the NULL pointer before reaching mtk_free_clk_data().
Could the commit message be updated to reflect that this fixes a kernel panic
during driver unbind?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=2
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 09/35] clk: mediatek: Fix index in composite clock unwind path
2026-10-13 15:17 ` [PATCH v2 09/35] clk: mediatek: Fix index in composite clock unwind path Akari Tsuyukusa
@ 2026-10-13 15:49 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 15:49 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: type confusion and wild frees in unwind path for skipped duplicates
--
commit 0447601409056d10a76a91c61e487c303de15ac7
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: Fix index in composite clock unwind path
This commit fixes an index error in the unwind path of
mtk_clk_register_composites(). It updates the error handling loop
to use the current descriptor's ID instead of always checking the
first descriptor's ID.
Cc: stable@vger.kernel.org
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index 3dfdd3a422f80..0b10a4b14a6e8 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
> @@ -363,7 +363,7 @@ int mtk_clk_register_composites(struct device *dev,
> while (--i >= 0) {
> const struct mtk_composite *mc = &mcs[i];
>
> - if (IS_ERR_OR_NULL(clk_data->hws[mcs->id]))
> + if (IS_ERR_OR_NULL(clk_data->hws[mc->id]))
[Severity: High]
Does this unwind loop safely handle duplicate clock IDs that were skipped
during the forward registration loop?
In mtk_clk_register_composites(), the forward loop skips registering a
duplicate clock ID but leaves its existing valid pointer intact:
if (!IS_ERR_OR_NULL(clk_data->hws[mc->id])) {
pr_warn("Trying to register duplicate clock ID: %d\n",
mc->id);
continue;
}
If a subsequent clock fails to register, the error path is triggered. Since
the skipped duplicate has a valid pointer in the array from a prior
registration, the updated guard evaluates to false. The unwind path will
then incorrectly unregister a clock pointer that this loop did not
allocate.
If that externally-owned duplicate was registered as a different clock type,
mtk_clk_unregister_composite() will perform an invalid cast:
composite = to_clk_composite(hw);
if (composite->mux_hw)
mux = to_clk_mux(composite->mux_hw);
Could this lead to memory corruption when kfree() is subsequently called on
garbage offsets read from the invalid cast?
> continue;
>
> mtk_clk_unregister_composite(clk_data->hws[mc->id]);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=9
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 13/35] clk: mediatek: Add PLL support to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 13/35] clk: mediatek: Add PLL " Akari Tsuyukusa
@ 2026-10-13 15:58 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 15:58 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] clk: mtk: redundant iomap for plls causes memory leak
--
commit 5289a3c612ab2d43573cbb1c18f5582e2661818a
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: Add PLL support to common probe/remove helpers
This commit extends __mtk_clk_simple_probe() and __mtk_clk_simple_remove()
to support PLLs. This reduces boilerplate code in apmixedsys drivers.
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index 004098a839b2c..e06cd40d995a9 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
[ ... ]
> @@ -486,7 +487,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
> }
>
> /* Composite and divider clocks needs us to pass iomem pointer */
> - if (mcd->composite_clks || mcd->divider_clks) {
> + if (mcd->composite_clks || mcd->divider_clks || mcd->plls) {
> if (!mcd->shared_io)
> base = devm_platform_ioremap_resource(pdev, 0);
> else
> @@ -514,7 +515,7 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
> num_clks = mcd->num_clks + mcd->num_composite_clks;
> num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
> num_clks += mcd->num_mux_clks + mcd->num_divider_clks;
> - num_clks += mcd->num_cpumuxes;
> + num_clks += mcd->num_cpumuxes + mcd->num_plls;
>
> clk_data = mtk_alloc_clk_data(num_clks);
> if (!clk_data) {
> @@ -522,11 +523,18 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
> goto free_base;
> }
>
> + if (mcd->plls) {
> + r = mtk_clk_register_plls(&pdev->dev, mcd->plls,
> + mcd->num_plls, clk_data);
[Severity: Medium]
Does adding mcd->plls to the earlier base mapping condition cause a resource
leak?
Since mtk_clk_register_plls() maps its own I/O memory using of_iomap()
internally and isn't passed the base pointer mapped above, the newly
mapped memory remains unused.
If mcd->shared_io is true, of_iomap() maps memory into base but it is never
unmapped on the success path, leading to a virtual I/O memory leak each
time a device successfully probes. If mcd->shared_io is false, it
redundantly calls devm_platform_ioremap_resource() to create an unused
duplicate mapping.
Could mcd->plls be removed from the earlier mapping condition to prevent
this?
> + if (r)
> + goto free_data;
> + }
> +
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=13
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 15/35] clk: mediatek: Add FHCTL support to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 15/35] clk: mediatek: Add FHCTL support to common " Akari Tsuyukusa
@ 2026-10-13 16:09 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:09 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] clk: mediatek: Use-After-Free of FHCTL base on probe deferral / rebind
- [Medium] clk: mediatek: memory leak of FHCTL iomem base on probe failure or no matches
--
commit 8d87854263bcfad5cea06d0fd17b75e7b846a747
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: Add FHCTL support to common probe/remove helpers
Extend __mtk_clk_simple_probe() and __mtk_clk_simple_remove() to support
FHCTL. This reduces boilerplate code in apmixedsys drivers with FHCTL
support.
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index 1172e76516c03..8fa81a8671ad0 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
[ ... ]
> @@ -525,8 +529,18 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
> }
>
> if (mcd->plls) {
> - r = mtk_clk_register_plls(&pdev->dev, mcd->plls,
> +#if IS_ENABLED(CONFIG_COMMON_CLK_MEDIATEK_FHCTL)
> + if (mcd->fhctl_node) {
> + fhctl_parse_dt(mcd->fhctl_node, mcd->pllfhs,
> + mcd->num_pllfhs);
> + r = mtk_clk_register_pllfhs(&pdev->dev, mcd->plls,
> + mcd->num_plls, mcd->pllfhs,
> + mcd->num_pllfhs, clk_data);
[Severity: Medium]
This problem wasn't introduced by this patch, but does calling
fhctl_parse_dt() here expose drivers to a memory leak of the fhctl iomem
base mapped via of_iomap() in fhctl_parse_dt()?
If mtk_clk_register_pllfhs() fails, the code jumps to the free_data label
in __mtk_clk_simple_probe(), bypassing unregister_plls. As a result, the
mapped i/o memory seems to be permanently leaked.
Additionally, if mtk_clk_register_pllfhs() fails to register the very first
pll, it skips its internal cleanup loop entirely, meaning the memory mapped
by fhctl_parse_dt() is never unmapped.
[Severity: High]
This problem wasn't introduced by this patch, but does the common
registration path expose fhctl-enabled drivers to a use-after-free during
probe deferral or device rebinds?
During a successful call, fhctl_parse_dt() mutates the static mcd->pllfhs
array by setting pllfh->state.fh_enable = 1 and storing the mapped i/o
pointer in pllfh->state.base.
If the probe later fails and the device is removed,
mtk_clk_unregister_pllfhs() calls iounmap() on the base but fails to clear
the fh_enable flag or the stale base pointer from the static array.
If the device is subsequently re-bound and fhctl_parse_dt() fails early
(leaving the static array unmodified), won't mtk_clk_register_pllfhs()
still see fh_enable == 1 from the previous probe and blindly dereference
the stale, unmapped state.base pointer?
> + } else
> +#endif
> + r = mtk_clk_register_plls(&pdev->dev, mcd->plls,
> mcd->num_plls, clk_data);
> +
> if (r)
> goto free_data;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=15
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 14/35] clk: mediatek: Add child-device population to probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 14/35] clk: mediatek: Add child-device population to " Akari Tsuyukusa
@ 2026-10-13 16:10 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:10 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] clk: mediatek: NULL deref in __mtk_clk_simple_remove() without id_table fallback
- [High] clk: mediatek: Use-after-free of clk in devm notifier release
--
commit 4b72b775dd71cd9f8aca52f2f386291f6722da4e
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: Add child-device population to probe/remove helpers
MediaTek audio clock drivers call devm_of_platform_populate() after
mtk_clk_simple_probe(). Extend __mtk_clk_simple_probe() to run
of_platform_populate() when the new 'populate_children' flag is set,
reducing boilerplate.
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index e06cd40d995a9..1172e76516c03 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
[ ... ]
> @@ -603,7 +604,16 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
> r = mtk_register_reset_controller_with_dev(&pdev->dev,
> mcd->rst_desc);
> if (r)
> - goto unregister_clks;
> + goto unregister_provider;
> + }
> +
> + if (mcd->populate_children) {
> + r = of_platform_populate(pdev->dev.of_node, NULL, NULL,
> + &pdev->dev);
> + if (r) {
> + of_platform_depopulate(&pdev->dev);
> + goto unregister_provider;
[Severity: High]
Does this new error path cause a use-after-free on the clk?
If __mtk_clk_simple_probe() has previously registered a rate-change
notifier on a struct clk using devm_clk_notifier_register() (via
mcd->clk_notifier_func), the notifier's lifetime is tied to the
pdev->dev devres list.
When taking this goto unregister_provider error path, the clocks are
manually unregistered via the cleanup labels, for example by calling
mtk_clk_unregister_muxes() which calls clk_hw_unregister() and then
clk_unregister().
clk_unregister() frees the struct clk pointer, but does not remove its
associated notifiers from clk_notifier_list.
Later, when the driver core invokes devres_release_all() for the device,
it calls devm_clk_notifier_release(), which invokes
clk_notifier_unregister() with the now-freed struct clk pointer, resulting
in a use-after-free.
This use-after-free also appears to occur during driver unbind in
__mtk_clk_simple_remove().
[ ... ]
> @@ -658,6 +671,9 @@ static void __mtk_clk_simple_remove(struct platform_device *pdev,
> struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
> const struct mtk_clk_desc *mcd = device_get_match_data(&pdev->dev);
>
> + if (mcd->populate_children)
[Severity: High]
Can this dereference a NULL mcd pointer during driver removal?
Many MediaTek clock drivers register as platform drivers using an
id_table without an of_match_table. While __mtk_clk_simple_probe() handles
this by safely falling back to platform_get_device_id() when
device_get_match_data() returns NULL, __mtk_clk_simple_remove() lacks
this fallback.
When the driver is unbound, for instance via sysfs or module unload,
device_get_match_data() will return NULL, causing mcd->populate_children
to crash.
> + of_platform_depopulate(&pdev->dev);
> +
> of_clk_del_provider(node);
> if (mcd->clks)
> mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=14
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 17/35] clk: mediatek: mt2712-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 17/35] clk: mediatek: mt2712-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 16:20 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:20 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] clk: mediatek: missing shared_io flag causes redundant exclusive syscon mapping
--
commit c93284125c00a17383c7e9f49de6dd50d3cdc4e9
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt2712-apmixedsys: Switch to common probe/remove helpers
This patch updates the MT2712 apmixedsys driver to use the common
mtk_clk_simple_probe() and mtk_clk_simple_remove() helpers. It removes the
custom probe and remove callbacks that previously handled PLL registration
and unregistration.
> diff --git a/drivers/clk/mediatek/clk-mt2712-apmixedsys.c b/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
> --- a/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
> +++ b/drivers/clk/mediatek/clk-mt2712-apmixedsys.c
[ ... ]
> +static const struct mtk_clk_desc apmixed_desc = {
> + .plls = plls,
> + .num_plls = ARRAY_SIZE(plls),
> +};
[Severity: Medium]
Does this descriptor need the .shared_io = true flag?
By omitting .shared_io = true here, it looks like mtk_clk_simple_probe()
will automatically call devm_platform_ioremap_resource(). This requests
the memory region exclusively, which seems to conflict with the shared
nature of a syscon hardware region.
Additionally, the resulting base pointer from mtk_clk_simple_probe()
doesn't appear to be passed to mtk_clk_register_plls(), which internally
maps the exact same region again using of_iomap().
Could this lead to an unused, redundant ioremap mapping and an improper
request_mem_region() on the syscon?
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=17
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 16/35] clk: mediatek: mt2701: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 16/35] clk: mediatek: mt2701: Switch " Akari Tsuyukusa
@ 2026-10-13 16:23 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:23 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] clk: mediatek: heap buffer overflow in mtk_clk_simple_probe() due to sparse clock IDs
- [High] clk: mediatek: UAF from __initconst cpu_muxes during deferred probe
--
commit 659dcd3d07d9476de418d05bc84f3a19e38f1127
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt2701: Switch to common probe/remove helpers
The MT2701 topckgen and pericfg drivers register clock types already
supported by the common helpers, so their custom initialization
routines can be replaced with struct mtk_clk_desc.
> diff --git a/drivers/clk/mediatek/clk-mt2701.c b/drivers/clk/mediatek/clk-mt2701.c
> index 710c4f2f9f304..5ea0c4acaf1be 100644
> --- a/drivers/clk/mediatek/clk-mt2701.c
> +++ b/drivers/clk/mediatek/clk-mt2701.c
[ ... ]
> @@ -655,38 +656,19 @@ static const struct mtk_gate top_clks[] = {
> 28),
> };
>
> -static int mtk_topckgen_init(struct platform_device *pdev)
> -{
[ ... ]
> - return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
> -}
> +static const struct mtk_clk_desc topck_desc = {
> + .clks = top_clks,
> + .num_clks = ARRAY_SIZE(top_clks),
[Severity: Critical]
Does this code cause a heap buffer overflow regression during probe?
Looking at __mtk_clk_simple_probe() in drivers/clk/mediatek/clk-mtk.c, it
allocates clk_data based on the sum of all element counts:
__mtk_clk_simple_probe()
num_clks = mcd->num_clks + mcd->num_composite_clks;
num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
...
clk_data = mtk_alloc_clk_data(num_clks);
Since the device tree clock IDs are sparse, the maximum clock ID can be much
larger than the total number of registered clocks.
When mtk_clk_register_gates() assigns the hardware clock to the index
matching its ID:
mtk_clk_register_gates()
if (!IS_ERR_OR_NULL(clk_data->hws[cg->id])) {
won't it write out of bounds of the undersized array?
[ ... ]
> @@ -725,81 +707,21 @@ static const struct mtk_fixed_factor infra_fixed_divs[] = {
> static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
> static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
>
> -static const struct mtk_clk_rst_desc clk_rst_desc[] = {
[ ... ]
> - mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[0]);
> -
> - return 0;
> -}
> +static const struct mtk_clk_desc infracfg_desc = {
> + .clks = infra_clks,
> + .num_clks = ARRAY_SIZE(infra_clks),
> + .factor_clks = infra_fixed_divs,
> + .num_factor_clks = ARRAY_SIZE(infra_fixed_divs),
> + .cpumuxes = cpu_muxes,
[Severity: High]
Does this create a use-after-free regression for cpu_muxes?
The cpu_muxes array is annotated with __initconst. Previously it was used in
an early init callback, but this patch passes it to the standard platform
driver probe function mtk_clk_simple_probe() via the infracfg_desc.cpumuxes
pointer.
Since mtk_clk_simple_probe() can run during deferred probe or upon manual
sysfs bind after the module initialization sections have been freed, will the
probe function access the freed cpu_muxes array?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=16
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 19/35] clk: mediatek: mt6779: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 19/35] clk: mediatek: mt6779: " Akari Tsuyukusa
@ 2026-10-13 16:31 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:31 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: heap buffer overflow during clock registration due to sparse IDs
--
commit 667fb3289a24a54cc5cde32a40e6a991c9fdb902
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt6779: Switch to common probe/remove helpers
The MT6779 apmixedsys driver used a custom probe to register PLLs.
With PLL registration now supported by the common helpers, it can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
> diff --git a/drivers/clk/mediatek/clk-mt6779.c b/drivers/clk/mediatek/clk-mt6779.c
> index 4b9dcb910b03f..a806789ae27c1 100644
> --- a/drivers/clk/mediatek/clk-mt6779.c
> +++ b/drivers/clk/mediatek/clk-mt6779.c
[ ... ]
> @@ -1211,125 +1209,47 @@ static const struct mtk_pll_data plls[] = {
> 0, 0, 32, 8, 0x02D4, 1, 0, 0x14, 1, 0x02D8, 0, 0x02D4),
> };
>
> -static int clk_mt6779_apmixed_probe(struct platform_device *pdev)
> -{
> - struct clk_hw_onecell_data *clk_data;
> - struct device_node *node = pdev->dev.of_node;
> -
> - clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
> - if (!clk_data)
> - return -ENOMEM;
> -
> - mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
> -
> - mtk_clk_register_gates(&pdev->dev, node, apmixed_clks,
> - ARRAY_SIZE(apmixed_clks), clk_data);
> -
> - return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
> -}
> -
> -static int clk_mt6779_top_probe(struct platform_device *pdev)
> -{
> - void __iomem *base;
> - struct clk_hw_onecell_data *clk_data;
> - struct device_node *node = pdev->dev.of_node;
> -
> - base = devm_platform_ioremap_resource(pdev, 0);
> - if (IS_ERR(base))
> - return PTR_ERR(base);
> -
> - clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
> - if (!clk_data)
> - return -ENOMEM;
> -
> - mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
> - clk_data);
> -
> - mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
> -
> - mtk_clk_register_muxes(&pdev->dev, top_muxes,
> - ARRAY_SIZE(top_muxes), node,
> - &mt6779_clk_lock, clk_data);
> -
> - mtk_clk_register_composites(&pdev->dev, top_aud_muxes,
> - ARRAY_SIZE(top_aud_muxes), base,
> - &mt6779_clk_lock, clk_data);
> -
> - mtk_clk_register_composites(&pdev->dev, top_aud_divs,
> - ARRAY_SIZE(top_aud_divs), base,
> - &mt6779_clk_lock, clk_data);
> -
> - return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
> -}
> -
[ ... ]
> +static const struct mtk_clk_desc apmixed_desc = {
> + .clks = apmixed_clks,
> + .num_clks = ARRAY_SIZE(apmixed_clks),
> + .plls = plls,
> + .num_plls = ARRAY_SIZE(plls),
> };
>
> +static const struct mtk_clk_desc topck_desc = {
> + .fixed_clks = top_fixed_clks,
> + .num_fixed_clks = ARRAY_SIZE(top_fixed_clks),
> + .factor_clks = top_divs,
> + .num_factor_clks = ARRAY_SIZE(top_divs),
> + .mux_clks = top_muxes,
> + .num_mux_clks = ARRAY_SIZE(top_muxes),
> + .composite_clks = top_aud_muxes_divs,
> + .num_composite_clks = ARRAY_SIZE(top_aud_muxes_divs),
> + .clk_lock = &mt6779_clk_lock,
> +};
[Severity: High]
Does this struct initialization fail to account for sparse DT binding IDs?
The previous code allocated clk_data using a maximum bounds macro, for
example mtk_alloc_clk_data(CLK_TOP_NR_CLK).
By switching to mtk_clk_simple_probe(), it appears __mtk_clk_simple_probe()
calculates the number of clocks by simply summing the array sizes (e.g.
num_fixed_clks + num_factor_clks + ...), which may total fewer than 100
elements.
However, the clock registration functions like mtk_clk_register_composites()
write directly into clk_data->hws[mc->id] = hw, where mc->id uses the sparse
DT binding IDs (such as CLK_TOP_UNIVPLL_D3_D16, which is 152).
Can this overflow the dynamically allocated clk_data->hws flexible array and
corrupt heap memory during probe?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=19
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 21/35] clk: mediatek: mt6797: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 21/35] clk: mediatek: mt6797: " Akari Tsuyukusa
@ 2026-10-13 16:39 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:39 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: mediatek: mt6797: heap OOB write in apmixedsys probe
--
commit 28b566b97c81bb9b4e1fed4aa54cc098337a524e
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt6797: Switch to common probe/remove helpers
The MT6797 topckgen and infracfg drivers use clock types already
supported by the common helpers. The apmixedsys driver can also use
them now that PLL registration and unregistration are supported.
> diff --git a/drivers/clk/mediatek/clk-mt6797.c b/drivers/clk/mediatek/clk-mt6797.c
> index ebf850ac57f54..1934420375e88 100644
> --- a/drivers/clk/mediatek/clk-mt6797.c
> +++ b/drivers/clk/mediatek/clk-mt6797.c
[ ... ]
> -static int mtk_apmixedsys_init(struct platform_device *pdev)
> -{
> - struct clk_hw_onecell_data *clk_data;
> - struct device_node *node = pdev->dev.of_node;
> -
> - clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
> - if (!clk_data)
> - return -ENOMEM;
> -
> - mtk_clk_register_plls(&pdev->dev, plls, ARRAY_SIZE(plls), clk_data);
> -
> - return of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
> -}
> +static const struct mtk_clk_desc apmixedsys_desc = {
> + .plls = plls,
> + .num_plls = ARRAY_SIZE(plls),
[Severity: High]
Does this cause an out-of-bounds write during probe?
Before this patch, mtk_alloc_clk_data(CLK_APMIXED_NR) was used to allocate
enough elements to cover the maximum clock ID. The maximum clock ID for
these PLLs is CLK_APMIXED_APLL2 (10).
With the new common probe, __mtk_clk_simple_probe() allocates the array
dynamically based strictly on the count of provided elements, which is
ARRAY_SIZE(plls) (10).
When mtk_clk_register_plls() processes CLK_APMIXED_APLL2, it stores the clock
pointer at index 10:
drivers/clk/mediatek/clk-pll.c:mtk_clk_register_plls() {
...
clk_data->hws[pll->id] = hw;
...
}
Since the array is only allocated for 10 elements (indices 0-9), could
writing to index 10 corrupt memory?
> +};
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=21
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 26/35] clk: mediatek: mt8135-apmixedsys: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 26/35] clk: mediatek: mt8135-apmixedsys: " Akari Tsuyukusa
@ 2026-10-13 16:50 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:50 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: mediatek: heap buffer overflow due to under-allocating clk_data->hws
--
commit a8601c1333aeb3d960b60f68a7bfd49fbd80c7c9
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt8135-apmixedsys: Switch to common probe/remove helpers
The MT8135 apmixedsys driver previously needed custom probe/remove
callbacks to register and unregister PLLs. With PLL support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
> diff --git a/drivers/clk/mediatek/clk-mt8135-apmixedsys.c b/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
> index e3b7dc13b458c..fe868417de482 100644
> --- a/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
> +++ b/drivers/clk/mediatek/clk-mt8135-apmixedsys.c
> @@ -47,56 +47,20 @@ static const struct mtk_pll_data plls[] = {
> PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x304, 0x31c, 0x80000000, 0, 21, 0x2b0, 6, 0x0, 0x308, 0),
> };
>
> -static int clk_mt8135_apmixed_probe(struct platform_device *pdev)
> -{
> - struct clk_hw_onecell_data *clk_data;
> - struct device_node *node = pdev->dev.of_node;
> - int ret;
> -
> - clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
[ ... ]
> +static const struct mtk_clk_desc apmixed_desc = {
> + .plls = plls,
> + .num_plls = ARRAY_SIZE(plls),
[Severity: High]
Does this code under-allocate the clk_data->hws[] array, causing an
out-of-bounds heap memory overwrite?
The original probe function explicitly allocated an array of size
CLK_APMIXED_NR_CLK. The new mtk_clk_simple_probe() helper dynamically
calculates the size of the clk_data->hws array by summing the element
counts of the provided clock arrays.
Here, ARRAY_SIZE(plls) evaluates to 10, which means an array of exactly 10
elements is allocated. However, the Mediatek DT bindings for MT8135 APMIXED
clocks use 1-based IDs, reaching up to CLK_APMIXED_VDECPLL = 10.
When mtk_clk_register_plls() writes the hardware pointer using the ID as the
index:
drivers/clk/mediatek/clk-pll.c:mtk_clk_register_plls() {
...
clk_data->hws[pll->id] = hw;
...
}
It writes to clk_data->hws[10] for CLK_APMIXED_VDECPLL, causing an
out-of-bounds memory overwrite.
Additionally, this breaks device tree lookups because of_clk_hw_onecell_get()
strictly checks that the index is less than hw_data->num, so looking up
CLK_APMIXED_VDECPLL will return -EINVAL.
> +};
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=26
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 25/35] clk: mediatek: mt7988-apmixed: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 25/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
@ 2026-10-13 16:52 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 16:52 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] clk: mtk: out-of-bounds array write in mtk_clk_register functions
--
commit 9e2f22353c17eb582f6f6eadd7b30d78eb6c4de2
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt7988-apmixed: Switch to common probe/remove helpers
The MT7988 apmixedsys driver used a custom probe to register PLLs but
had no remove callback. With PLL registration and unregistration
handled by the common helpers, the driver can use mtk_clk_simple_probe()
and mtk_clk_simple_remove().
> diff --git a/drivers/clk/mediatek/clk-mt7988-apmixed.c b/drivers/clk/mediatek/clk-mt7988-apmixed.c
> index 24f4e7b87a312..f7bb00e7d17a1 100644
> --- a/drivers/clk/mediatek/clk-mt7988-apmixed.c
> +++ b/drivers/clk/mediatek/clk-mt7988-apmixed.c
[ ... ]
> -free_apmixed_data:
> - mtk_free_clk_data(clk_data);
> - return r;
> -}
> -
> static struct platform_driver clk_mt7988_apmixed_drv = {
> - .probe = clk_mt7988_apmixed_probe,
> + .probe = mtk_clk_simple_probe,
> + .remove = mtk_clk_simple_remove,
[Severity: High]
While this is not a regression for mt7988-apmixedsys because its IDs are
densely packed (0..11), does migrating to mtk_clk_simple_probe cause an
out-of-bounds array write for other drivers migrated in this series?
Looking at __mtk_clk_simple_probe() in clk-mtk.c, it allocates clk_data based
on the total count of clock elements:
drivers/clk/mediatek/clk-mtk.c:__mtk_clk_simple_probe() {
...
num_clks = mcd->num_clks + mcd->num_composite_clks;
num_clks += mcd->num_fixed_clks + mcd->num_factor_clks;
num_clks += mcd->num_mux_clks + mcd->num_divider_clks;
num_clks += mcd->num_cpumuxes + mcd->num_plls;
clk_data = mtk_alloc_clk_data(num_clks);
...
}
For drivers with sparse clock IDs like mt2701 topckgen, the total element
count (149) is smaller than the maximum ID (CLK_TOP_AXISEL_D4 is 158).
When mtk_clk_register_factors() processes this, will it write out-of-bounds
into adjacent slab memory?
drivers/clk/mediatek/clk-mtk.c:mtk_clk_register_factors() {
...
clk_data->hws[ff->id] = hw;
...
}
Could this cause a kernel panic during boot when loading other Mediatek clock
drivers with sparse IDs (like mt2701 and mt6779) migrated in this series?
> .driver = {
> .name = "clk-mt7988-apmixed",
> .of_match_table = of_match_clk_mt7988_apmixed,
> },
> };
> -builtin_platform_driver(clk_mt7988_apmixed_drv);
> +module_platform_driver(clk_mt7988_apmixed_drv);
>
> MODULE_DESCRIPTION("MediaTek MT7988 apmixedsys clocks driver");
> MODULE_LICENSE("GPL");
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=25
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 28/35] clk: mediatek: mt8173-infracfg: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 28/35] clk: mediatek: mt8173-infracfg: " Akari Tsuyukusa
@ 2026-10-13 17:01 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 17:01 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] clk: mediatek: early timer initialization breaks due to removal of CLK_OF_DECLARE_DRIVER
- [High] clk: mediatek: out-of-bounds array write in mtk_clk_simple_probe due to sparse IDs
--
commit cabfa228cff0aa82afbc9489448b517cc6478e89
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt8173-infracfg: Switch to common probe/remove helpers
The MT8173 infracfg driver previously needed custom probe/remove
callbacks to register and unregister cpumux. With cpumux support now
available in the common helpers, the driver can use
mtk_clk_simple_probe() and mtk_clk_simple_remove().
> diff --git a/drivers/clk/mediatek/clk-mt8173-infracfg.c b/drivers/clk/mediatek/clk-mt8173-infracfg.c
> index 9b8c358977891..fdd994736e833 100644
> --- a/drivers/clk/mediatek/clk-mt8173-infracfg.c
> +++ b/drivers/clk/mediatek/clk-mt8173-infracfg.c
[ ... ]
> @@ -70,95 +68,29 @@ static const struct mtk_clk_rst_desc clk_rst_desc = {
> .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
> };
>
> +static const struct mtk_clk_desc infracfg_desc = {
> + .clks = infra_gates,
> + .num_clks = ARRAY_SIZE(infra_gates),
> + .factor_clks = infra_divs,
> + .num_factor_clks = ARRAY_SIZE(infra_divs),
> + .cpumuxes = cpu_muxes,
> + .num_cpumuxes = ARRAY_SIZE(cpu_muxes),
> + .rst_desc = &clk_rst_desc,
> +};
[Severity: High]
Does this code under-allocate the clock array by using the sum of element
counts rather than the maximum clock ID?
The transition to mtk_clk_simple_probe() calculates num_clks by summing the
array sizes in infracfg_desc (11 gates + 1 factor + 2 cpumuxes = 14 elements).
Consequently, mtk_alloc_clk_data(14) allocates exactly 14 elements.
However, mt8173-infracfg uses sparse IDs. For example, CLK_INFRA_CA72SEL is
defined as 14. When mtk_clk_register_cpumuxes() registers this cpumux, it
attempts to assign the clock pointer to clk_data->hws[14]:
drivers/clk/mediatek/clk-cpumux.c:mtk_clk_register_cpumuxes() {
...
clk_data->hws[mux->id] = hw;
...
}
This performs an out-of-bounds write past the end of the allocation. The
previous custom probe avoided this by explicitly allocating CLK_INFRA_NR_CLK
elements.
> static const struct of_device_id of_match_clk_mt8173_infracfg[] = {
> - { .compatible = "mediatek,mt8173-infracfg" },
> + { .compatible = "mediatek,mt8173-infracfg", .data = &infracfg_desc },
> { /* sentinel */ }
> };
> MODULE_DEVICE_TABLE(of, of_match_clk_mt8173_infracfg);
>
> -static void clk_mt8173_infra_init_early(struct device_node *node)
> -{
> - int i;
> -
> - infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
> - if (!infra_clk_data)
> - return;
> -
> - for (i = 0; i < CLK_INFRA_NR_CLK; i++)
> - infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
> -
> - mtk_clk_register_factors(infra_early_divs,
> - ARRAY_SIZE(infra_early_divs), infra_clk_data);
> -
> - of_clk_add_hw_provider(node, of_clk_hw_onecell_get, infra_clk_data);
> -}
> -CLK_OF_DECLARE_DRIVER(mtk_infrasys, "mediatek,mt8173-infracfg",
> - clk_mt8173_infra_init_early);
[Severity: High]
Does removing CLK_OF_DECLARE_DRIVER break early timer initialization?
The MT8173 device tree defines a system timer matching mediatek,mt6577-timer,
which depends on CLK_INFRA_CLK_13M. This timer is initialized during early boot
via TIMER_OF_DECLARE running synchronously from timer_probe().
By removing CLK_OF_DECLARE_DRIVER from mt8173-infracfg, the infracfg clock
provider is deferred to the standard platform module probe phase. When
timer_probe() executes early in boot, of_clk_get() for CLK_INFRA_CLK_13M
returns -EPROBE_DEFER.
Since timer_probe() completely ignores deferred probing and never retries:
drivers/clocksource/timer-probe.c:timer_probe() {
...
ret = init_func_ret(np);
if (ret) {
if (ret != -EPROBE_DEFER)
pr_err("Failed to initialize '%pOF': %d\n", np, ret);
continue;
}
...
}
This causes the system to permanently lose its mt6577-timer (clocksource,
clockevents, and sched_clock), leading to a boot regression.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=28
^ permalink raw reply [flat|nested] 50+ messages in thread
* Re: [PATCH v2 34/35] clk: mediatek: mt8196: Switch to common probe/remove helpers
2026-10-13 15:17 ` [PATCH v2 34/35] clk: mediatek: mt8196: " Akari Tsuyukusa
@ 2026-10-13 17:24 ` sashiko-bot
0 siblings, 0 replies; 50+ messages in thread
From: sashiko-bot @ 2026-10-13 17:24 UTC (permalink / raw)
To: Akari Tsuyukusa; +Cc: open list:COMMON CLK FRAMEWORK
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] clk: mediatek: redundant ioremap and exclusive region request for PLLs
--
commit 493ba4ac616daf31697a4dcddf3d65ea3f269cb3
Author: Akari Tsuyukusa <akkun11.open@gmail.com>
clk: mediatek: mt8196: Switch to common probe/remove helpers
This commit updates the MT8196 apmixedsys, mcusys, and mfg drivers to use
the common mtk_clk_simple_probe() and mtk_clk_simple_remove() helpers by
representing their PLL configurations with struct mtk_clk_desc.
> diff --git a/drivers/clk/mediatek/clk-mt8196-apmixedsys.c b/drivers/clk/mediatek/clk-mt8196-apmixedsys.c
> index c4ebb0170b82b..a20fa02070a88 100644
> --- a/drivers/clk/mediatek/clk-mt8196-apmixedsys.c
> +++ b/drivers/clk/mediatek/clk-mt8196-apmixedsys.c
[ ... ]
> @@ -192,8 +141,8 @@ static const struct of_device_id of_match_clk_mt8196_apmixed[] = {
> MODULE_DEVICE_TABLE(of, of_match_clk_mt8196_apmixed);
>
> static struct platform_driver clk_mt8196_apmixed_drv = {
> - .probe = clk_mt8196_apmixed_probe,
> - .remove = clk_mt8196_apmixed_remove,
> + .probe = mtk_clk_simple_probe,
[Severity: Medium]
Does switching to mtk_clk_simple_probe() cause an unintended exclusive
memory region request for the shared apmixedsys controller?
By switching to the common helper without setting .shared_io = true in
the mtk_clk_desc structures, __mtk_clk_simple_probe() will map the IO
region exclusively:
drivers/clk/mediatek/clk-mtk.c:__mtk_clk_simple_probe() {
/* Composite and divider clocks needs us to pass iomem pointer */
if (mcd->composite_clks || mcd->divider_clks || mcd->plls) {
if (!mcd->shared_io)
base = devm_platform_ioremap_resource(pdev, 0);
...
}
Because devm_platform_ioremap_resource() calls request_mem_region(),
this exclusive claim could conflict with other drivers expecting to
access this shared syscon node.
Furthermore, the exclusively mapped `base` pointer appears to be completely
unused for PLL registration, as mtk_clk_register_plls() maps the region a
second time via of_iomap():
drivers/clk/mediatek/clk-pll.c:mtk_clk_register_plls() {
...
base = of_iomap(dev->of_node, 0);
...
}
Would it be safer to set .shared_io = true in apmixed_desc and
apmixed2_desc (and similarly for other shared controllers in this patch) to
avoid the redundant mapping and exclusive resource lock?
> + .remove = mtk_clk_simple_remove,
> .driver = {
> .name = "clk-mt8196-apmixed",
> .of_match_table = of_match_clk_mt8196_apmixed,
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261013151734.3177690-1-akkun11.open@gmail.com?part=34
^ permalink raw reply [flat|nested] 50+ messages in thread
end of thread, other threads:[~2026-10-13 17:24 UTC | newest]
Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 15:16 [PATCH v2 00/35] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 01/35] clk: mediatek: mt2712: Fix memory leak on module removal Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 02/35] clk: mediatek: mt6795: " Akari Tsuyukusa
2026-10-13 15:36 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 03/35] clk: mediatek: mt7622: " Akari Tsuyukusa
2026-10-13 15:34 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 04/35] clk: mediatek: mt8135: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 05/35] clk: mediatek: mt8173: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 06/35] clk: mediatek: mt8192: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 07/35] clk: mediatek: mt6735: Add missing MODULE_DEVICE_TABLE() Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 08/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 09/35] clk: mediatek: Fix index in composite clock unwind path Akari Tsuyukusa
2026-10-13 15:49 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 10/35] clk: mediatek: Fix memory leak in mtk_clk_register_gate() Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 11/35] clk: mediatek: return 0 instead of r in __mtk_clk_simple_probe() Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 12/35] clk: mediatek: Add cpumux support to common probe/remove helpers Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 13/35] clk: mediatek: Add PLL " Akari Tsuyukusa
2026-10-13 15:58 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 14/35] clk: mediatek: Add child-device population to " Akari Tsuyukusa
2026-10-13 16:10 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 15/35] clk: mediatek: Add FHCTL support to common " Akari Tsuyukusa
2026-10-13 16:09 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 16/35] clk: mediatek: mt2701: Switch " Akari Tsuyukusa
2026-10-13 16:23 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 17/35] clk: mediatek: mt2712-apmixedsys: " Akari Tsuyukusa
2026-10-13 16:20 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 18/35] clk: mediatek: mt6735-apmixedsys: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 19/35] clk: mediatek: mt6779: " Akari Tsuyukusa
2026-10-13 16:31 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 20/35] clk: mediatek: mt6795: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 21/35] clk: mediatek: mt6797: " Akari Tsuyukusa
2026-10-13 16:39 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 22/35] clk: mediatek: mt7622: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 23/35] clk: mediatek: mt7981-apmixed: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 24/35] clk: mediatek: mt7986-apmixed: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 25/35] clk: mediatek: mt7988-apmixed: " Akari Tsuyukusa
2026-10-13 16:52 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 26/35] clk: mediatek: mt8135-apmixedsys: " Akari Tsuyukusa
2026-10-13 16:50 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 27/35] clk: mediatek: mt8167-apmixedsys: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 28/35] clk: mediatek: mt8173-infracfg: " Akari Tsuyukusa
2026-10-13 17:01 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 29/35] clk: mediatek: mt8183: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 30/35] clk: mediatek: mt8186-apmixedsys: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 31/35] clk: mediatek: mt8188-apmixedsys: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 32/35] clk: mediatek: mt8192: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 33/35] clk: mediatek: mt8195: " Akari Tsuyukusa
2026-10-13 15:17 ` [PATCH v2 34/35] clk: mediatek: mt8196: " Akari Tsuyukusa
2026-10-13 17:24 ` sashiko-bot
2026-10-13 15:17 ` [PATCH v2 35/35] clk: mediatek: mt8516-apmixedsys: " Akari Tsuyukusa
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.