[PATCH v2 5/6] clk: mediatek: mt8173: fix memory leak on module removal

Akari Tsuyukusa akkun11.open at gmail.com
Tue Jul 28 10:02:59 PDT 2026


Hi Brian,

On Tue, Jul 28, 2026 at 10:53:00AM -0400, Brian Masney wrote:
> On Tue, Jul 07, 2026 at 04:48:34PM +0900, Akari Tsuyukusa wrote:
> > 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 at vger.kernel.org
> > Signed-off-by: Akari Tsuyukusa <akkun11.open at gmail.com>
> > ---
> >  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..8b69009e1965 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, clk_data);
> > +
> 
> This patch doesn't compile.
> 
>     drivers/clk/mediatek/clk-mt8173-infracfg.c: In function ‘clk_mt8173_infracfg_probe’:
>     drivers/clk/mediatek/clk-mt8173-infracfg.c:131:36: error: ‘clk_data’ undeclared (first use in this function); did you mean ‘clk_gate’?

Sorry for sending you a broken patch.
I accidentally built only with ARCH=arm and missed the build failure.

While fixing this, I noticed that clk-mt8173-infracfg.c can be converted
to use mtk_clk_simple_probe()/remove() instead of adding driver-specific
drvdata handling.

The helper currently lacks cpumux support, but I have a reviewed patch
for it:
https://lore.kernel.org/lkml/20260304181024.738391-2-akkun11.open@gmail.com/
(Reviewed-by: Chen-Yu Tsai <wenst at chromium.org>)

Also, adding PLL support to the helper should allow more MediaTek clock
drivers to use the common probe/remove path:
https://github.com/TeamYogaBlade2/linux/commit/d991a61887ab76fd83708dffe8e48192e01023d5

Would it be preferable to extend mtk_clk_simple_probe()/remove() with
cpumux and PLL support and reorganize this series around it?
or should I keep this series focused on the current simple fixes?

Best Regards,
Akari



More information about the Linux-mediatek mailing list