Re: [PATCH 11/32] clk: mediatek: Add auto-population of sub-devices support in simple probe
Chen-Yu Tsai <[email protected]> Tue, 4 Aug 2026 10:43:08 +0800
| Newsgroups | org.kernel.vger.stable,org.infradead.lists.linux-arm-kernel,org.infradead.lists.linux-mediatek,org.kernel.vger.linux-clk,org.kernel.vger.linux-kernel,org.kernel.vger.netdev |
|---|---|
| Message-ID | <CAGXv+5FHSNH5SLiCiXyHDieO2rUDypAQBi5-nbTFKFzb+3ZWRA@mail.gmail.com> |
On Mon, Aug 3, 2026 at 10:18=E2=80=AFPM Akari Tsuyukusa <akkun11.open@gmail= .com> 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 <[email protected]> > --- > 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-mt= k.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_de= vice *pdev, > if (mcd->need_runtime_pm) > pm_runtime_put(&pdev->dev); > > + if (mcd->populate_children) { > + r =3D 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-mt= k.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 >