Re: [PATCH 11/32] clk: mediatek: Add auto-population of sub-devices support in simple probe
From: Chen-Yu Tsai
Date: Mon Aug 03 2026 - 22:44:09 EST
On Mon, Aug 3, 2026 at 10:18 PM Akari Tsuyukusa <akkun11.open@xxxxxxxxx> wrote:
>
> 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@xxxxxxxxx>
> ---
> drivers/clk/mediatek/clk-mtk.c | 7 +++++++
> drivers/clk/mediatek/clk-mtk.h | 1 +
> 2 files changed, 8 insertions(+)
>
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index c3369a04cdec..71d70b5a9990 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>
> @@ -609,6 +610,12 @@ static int __mtk_clk_simple_probe(struct platform_device *pdev,
> if (mcd->need_runtime_pm)
> pm_runtime_put(&pdev->dev);
>
> + if (mcd->populate_children) {
> + r = devm_of_platform_populate(&pdev->dev);
> + if (r)
> + goto unregister_clks;
You cannot use devm_* here, as they get unrolled _after_ the probe function
returns an error or after the remove function returns. A child could be
referencing a clock that got tore down in the error path below.
All devm_* functions need to happen before anything that requires manual
tear down. You can't mix the two together.
ChenYu
> + }
> +
> return r;
>
> unregister_clks:
> 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.55.0
>