Skip to content

[PATCH] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks - #73

Draft
akku1139 wants to merge 32 commits into
mainlinefrom
patch/mediatek-clk-simple-probe
Draft

[PATCH] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks#73
akku1139 wants to merge 32 commits into
mainlinefrom
patch/mediatek-clk-simple-probe

Conversation

@akku1139

@akku1139 akku1139 commented Aug 1, 2026

Copy link
Copy Markdown
Member

#57

  • git grep -LFE --name-only '.remove = (mtk_clk_simple_remove|mtk_clk_pdev_remove)' clk-mt*.c
  • git grep -EFL module_platform_driver
  • git grep -F builtin_platform_driver
  • git grep -F arch_initcall
  • git grep -EFL MODULE_DEVICE_TABLE

@akku1139
akku1139 force-pushed the patch/mediatek-clk-simple-probe branch from 3d1c917 to 6c8a05c Compare August 1, 2026 07:34
@akku1139 akku1139 changed the title clk: mediatek: simple_prove()/simple_remove() refactor [PATCH] clk: mediatek: simple_prove()/simple_remove() refactor Aug 1, 2026
@akku1139

akku1139 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author
  • Fixes: 124294f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")
  • Fixes: 4c02c9a ("clk: mediatek: mt8173: Break down clock drivers and allow module build")
  • Fixes: 54b7026 ("clk: mediatek: mt8135-apmixedsys: Convert to platform_driver and module")
  • Fixes: c50e2ea ("clk: mediatek: mt7622-apmixedsys: Add .remove() callback for module build")
  • Fixes: 0d36328 ("clk: mediatek: Add MediaTek Helio X10 MT6795 clock drivers")
  • Fixes: c6368ce ("clk: mediatek: mt2712-apmixedsys: Add .remove() callback for module build")
  • Fixes: 838b863 ("clk: mediatek: mt7622: Move infracfg to clk-mt7622-infracfg.c")

@akku1139
akku1139 force-pushed the patch/mediatek-clk-simple-probe branch 6 times, most recently from f92b254 to e730177 Compare August 1, 2026 12:32
@akku1139

akku1139 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author
  • clk-mt7629-eth.c: very hack
  • clk-mt7629.c: clk_prepare_enable()
  • clk-mt8183-audio.c, clk-mt8192-aud.c, clk-mt7622-aud.c: devm_of_platform_populate()

@akku1139
akku1139 force-pushed the patch/mediatek-clk-simple-probe branch 2 times, most recently from c3d6c46 to 78a130b Compare August 1, 2026 15:02
@akku1139

akku1139 commented Aug 1, 2026

Copy link
Copy Markdown
Member Author
  • infra early init

@akku1139
akku1139 force-pushed the patch/mediatek-clk-simple-probe branch 3 times, most recently from 49689e1 to 64ec78b Compare August 2, 2026 08:21
@akku1139

akku1139 commented Aug 2, 2026

Copy link
Copy Markdown
Member Author
  • mt2701
  • mt2712 (ok, apmixed only)
  • mt6735 (ok, apmixed+MODULE_DEVICE_TABLE)
  • mt6765 (SKIP)
  • mt6779 (ok, main only)
  • mt6795 (ok, drop apmixedsys)
  • mt6797
  • mt7622 (ok, squashed)
  • mt7629 (don't edit for now, TODO: note)
  • mt7981 (ok, apmixed only)
  • mt7986 (ok, apmixed only)
  • mt7988 (ok, apmixed only)
  • mt8135 (ok, apmixed only)
  • mt8167 (ok, apmixed only)
  • mt8173 (ok, drop infracfg, TODO: write in cover letter)
  • mt8183 (ok, squashed)
  • mt8186 (ok, apmixed only)
  • mt8188 (ok, apmixed only, drop topckgen, TODO: note in cover letter)
  • mt8192 (ok, squashed)
  • mt8195 (ok, drop topckgen from conversion)
  • mt8196 (ok, drop vlpckgen)
  • mt8365 (don't touch, TODO: note about apmixed)
  • mt8516 (ok, apmixed only)

@akku1139
akku1139 force-pushed the patch/mediatek-clk-simple-probe branch 10 times, most recently from 822d3da to b3c7497 Compare August 2, 2026 10:58
akku1139 added 27 commits August 3, 2026 22:59
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: 124294f ("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>
Add MODULE_DEVICE_TABLE() to the MT6735 clock drivers (imgsys, mfgcfg,
vdecsys, vencsys) to export the Device Tree matching tables.
This is required so that the clock drivers can be automatically loaded
when built as modules.

Fixes: 0bd9b12 ("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>
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: 4b47194 ("clk: mediatek: add drivers for MT7988 SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
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>
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>
…robe

MediaTek audio clock drivers call devm_of_platform_populate() after
mtk_clk_simple_probe(). Extend __mtk_clk_simple_probe() to run
devm_of_platform_populate() when the new 'populate_children' flag is
set, reducing boilerplate.

Note that explicit of_platform_depopulate() calls in remove functions
are unnecessary because devm_of_platform_populate() is managed by
devres and cleans up automatically.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
Extend __mtk_clk_simple_probe() and __mtk_clk_simple_remove() to
support pll freqhoppings.
This reduces boilerplate code in apmixedsys drivers with pllfh support.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT2701 clock drivers can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Drop the CLK_OF_DECLARE_DRIVER early init for infracfg; the kernel's
deferred probe mechanism ensures dependent drivers like cpufreq are
initialized correctly.

Since all MT2701 clock drivers can now be built as modules,
change Kconfig settings to "tristate".

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT2712 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT6735 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT6779 main clock driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Additionally, merge the separate infracfg and other drivers into
a single platform driver, and add support for the apmixed and
topckgen clock controllers using the consolidated of_match_table.
Finally, replace the custom arch_initcall() initialization loop with
the module_platform_driver() macro.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT6795 infracfg and pericfg drivers can use the MediaTek clock
framework common initialization sequence. Reduce boilerplate code by
creating struct mtk_clk_desc and using the mtk_clk_simple_probe/remove
helpers.

Note that the apmixedsys driver is excluded from this conversion because
it requires ref2usb_tx clock handling, which is not currently supported
by the common simple probe helper.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT6797 clock drivers can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Drop the CLK_OF_DECLARE_DRIVER early init for infracfg; the kernel's
deferred probe mechanism ensures dependent drivers like cpufreq are
initialized correctly.

Since all MT6797 clock drivers can now be built as modules,
change Kconfig setting to "tristate".

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT7622 clock drivers can use the MediaTek clock framework common
initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT7981 apmixed driver can use the MediaTek clock framework common
initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.
This change also makes it possible to build the driver as a module.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT7986 apmixed driver can use the MediaTek clock framework common
initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.
Also, add a remove callback to properly support module unloading.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT7988 apmixed driver can use the MediaTek clock framework common
initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8135 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8167 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.
Also, add a remove callback to properly support module unloading.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8173 infracfg driver can use the MediaTek clock framework common
initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

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>
The MT8183 clock drivers can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.
For the apmixedsys driver, add a remove callback to properly support
module unloading.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8186 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8188 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8192 clock drivers can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8195 apusys_pll and apmixedsys drivers can use the MediaTek clock
framework common initialization sequence. Reduce boilerplate code by
creating struct mtk_clk_desc and using the mtk_clk_simple_probe/remove
helpers.

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.

Since all MT8195 clock drivers can now be built as modules,
change Kconfig setting to "tristate".

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8196 apmixedsys, mcusys and mfg clock drivers can use the
MediaTek clock framework common initialization sequence.
Reduce boilerplate code by creating struct mtk_clk_desc and using the
mtk_clk_simple_probe/remove helpers.

Note that the vlpckgen driver is excluded from this conversion because
its probe callback needs to initialize the APLL tuner registers, which
is not currently supported by the common simple probe helper.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
The MT8516 apmixedsys driver can use the MediaTek clock framework
common initialization sequence. Reduce boilerplate code by creating
struct mtk_clk_desc and using the mtk_clk_simple_probe/remove helpers.
Also, add a remove callback to properly support module unloading.

Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
@akku1139
akku1139 force-pushed the patch/mediatek-clk-simple-probe branch from 536b623 to 266c8aa Compare August 3, 2026 14:01
@akku1139

akku1139 commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@akku1139 akku1139 changed the title [PATCH] clk: mediatek: simple_prove()/simple_remove() refactor [PATCH] clk: mediatek: Migrate to common probe/remove helpers and fix memory leaks Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant