mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare()
@ 2026-06-26 14:37 Felix Gu
  2026-06-26 16:17 ` Frank Li
  2026-06-29  7:21 ` Peng Fan (OSS)
  0 siblings, 2 replies; 5+ messages in thread
From: Felix Gu @ 2026-06-26 14:37 UTC (permalink / raw)
  To: Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Marco Felsch, Peng Fan, Shawn Guo
  Cc: imx, linux-arm-kernel, linux-kernel, Felix Gu

When clk_prepare_enable() fails, the error path does not release the
clock reference obtained by of_clk_get_by_name(). Add clk_put() to
the error path before iounmap().

Fixes: 390c01073f5d ("soc: imx8m: Cleanup with adding imx8m_soc_[un]prepare")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/soc/imx/soc-imx8m.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
index fc080e56f50d..de19972435f9 100644
--- a/drivers/soc/imx/soc-imx8m.c
+++ b/drivers/soc/imx/soc-imx8m.c
@@ -150,10 +150,12 @@ static int imx8m_soc_prepare(struct platform_device *pdev, const char *ocotp_com
 
 	ret = clk_prepare_enable(drvdata->clk);
 	if (ret)
-		goto err_clk;
+		goto put_clk;
 
 	return 0;
 
+put_clk:
+	clk_put(drvdata->clk);
 err_clk:
 	iounmap(drvdata->ocotp_base);
 	return ret;

---
base-commit: 30ffa8de54e5cc80d93fd211ca134d1764a7011f
change-id: 20260626-soc-imx8m-938e89104044

Best regards,
--  
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare()
  2026-06-26 14:37 [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare() Felix Gu
@ 2026-06-26 16:17 ` Frank Li
  2026-06-28  8:25   ` Felix Gu
  2026-06-29  7:21 ` Peng Fan (OSS)
  1 sibling, 1 reply; 5+ messages in thread
From: Frank Li @ 2026-06-26 16:17 UTC (permalink / raw)
  To: Felix Gu
  Cc: Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Marco Felsch, Peng Fan, Shawn Guo, imx, linux-arm-kernel,
	linux-kernel

On Fri, Jun 26, 2026 at 10:37:35PM +0800, Felix Gu wrote:
> When clk_prepare_enable() fails, the error path does not release the
> clock reference obtained by of_clk_get_by_name(). Add clk_put() to
> the error path before iounmap().
>
> Fixes: 390c01073f5d ("soc: imx8m: Cleanup with adding imx8m_soc_[un]prepare")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---

Thanks for your fix

>  drivers/soc/imx/soc-imx8m.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
> index fc080e56f50d..de19972435f9 100644
> --- a/drivers/soc/imx/soc-imx8m.c
> +++ b/drivers/soc/imx/soc-imx8m.c
> @@ -150,10 +150,12 @@ static int imx8m_soc_prepare(struct platform_device *pdev, const char *ocotp_com
>
>  	ret = clk_prepare_enable(drvdata->clk);
>  	if (ret)
> -		goto err_clk;
> +		goto put_clk;

imx8m_soc_prepare() call be from probe(), can your use
devm_clk_get_enabled() to combine clk get and enable together.

And use new patch change ioremap() to devm_ioremap().

Frank
>
>  	return 0;
>
> +put_clk:
> +	clk_put(drvdata->clk);
>  err_clk:
>  	iounmap(drvdata->ocotp_base);
>  	return ret;
>
> ---
> base-commit: 30ffa8de54e5cc80d93fd211ca134d1764a7011f
> change-id: 20260626-soc-imx8m-938e89104044
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare()
  2026-06-26 16:17 ` Frank Li
@ 2026-06-28  8:25   ` Felix Gu
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Gu @ 2026-06-28  8:25 UTC (permalink / raw)
  To: Frank Li
  Cc: Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Marco Felsch, Peng Fan, Shawn Guo, imx, linux-arm-kernel,
	linux-kernel

Hi Frank,
On Sat, Jun 27, 2026 at 12:17 AM Frank Li <Frank.li@oss.nxp.com> wrote:
> > ---
>
> Thanks for your fix
>
>
> imx8m_soc_prepare() call be from probe(), can your use
> devm_clk_get_enabled() to combine clk get and enable together.
>
> And use new patch change ioremap() to devm_ioremap().
>
Those resources are only used in the probe time, it may not necessary
to use devm here.

Best regards,
Felix
> Frank
> >
> >       return 0;
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare()
  2026-06-26 14:37 [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare() Felix Gu
  2026-06-26 16:17 ` Frank Li
@ 2026-06-29  7:21 ` Peng Fan (OSS)
  2026-06-30 13:58   ` Felix Gu
  1 sibling, 1 reply; 5+ messages in thread
From: Peng Fan (OSS) @ 2026-06-29  7:21 UTC (permalink / raw)
  To: Felix Gu, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, Marco Felsch, Shawn Guo
  Cc: imx, linux-arm-kernel, linux-kernel

> Subject: [PATCH] soc: imx8m: fix clock reference leak in
> imx8m_soc_prepare()
> 
> When clk_prepare_enable() fails, the error path does not release the
> clock reference obtained by of_clk_get_by_name(). Add clk_put() to
> the error path before iounmap().
> 
> Fixes: 390c01073f5d ("soc: imx8m: Cleanup with adding
> imx8m_soc_[un]prepare")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
>  drivers/soc/imx/soc-imx8m.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-
> imx8m.c index fc080e56f50d..de19972435f9 100644
> --- a/drivers/soc/imx/soc-imx8m.c
> +++ b/drivers/soc/imx/soc-imx8m.c
> @@ -150,10 +150,12 @@ static int imx8m_soc_prepare(struct
> platform_device *pdev, const char *ocotp_com
> 
>  	ret = clk_prepare_enable(drvdata->clk);
>  	if (ret)
> -		goto err_clk;
> +		goto put_clk;
> 
>  	return 0;
> 
> +put_clk:
> +	clk_put(drvdata->clk);
>  err_clk:

It should be safe to directly put "clk_put" here, no
need extra label.

Regards
Peng.

>  	iounmap(drvdata->ocotp_base);
>  	return ret;
> 
> ---
> base-commit: 30ffa8de54e5cc80d93fd211ca134d1764a7011f
> change-id: 20260626-soc-imx8m-938e89104044
> 
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare()
  2026-06-29  7:21 ` Peng Fan (OSS)
@ 2026-06-30 13:58   ` Felix Gu
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Gu @ 2026-06-30 13:58 UTC (permalink / raw)
  To: Peng Fan (OSS)
  Cc: Frank Li, Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
	Marco Felsch, Shawn Guo, imx, linux-arm-kernel, linux-kernel

Hi Peng,

On Mon, Jun 29, 2026 at 3:21 PM Peng Fan (OSS) <peng.fan@oss.nxp.com> wrote:
> > platform_device *pdev, const char *ocotp_com
> >
> >       ret = clk_prepare_enable(drvdata->clk);
> >       if (ret)
> > -             goto err_clk;
> > +             goto put_clk;
> >
> >       return 0;
> >
> > +put_clk:
> > +     clk_put(drvdata->clk);
> >  err_clk:
>
> It should be safe to directly put "clk_put" here, no
> need extra label.
Passing an error_ptr to clk_put() could invoke WARN_ON_ONCE.

Best regards
Felix
>
> Regards
> Peng.
>
> >       iounmap(drvdata->ocotp_base);
> >       return ret;
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-30 13:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-26 14:37 [PATCH] soc: imx8m: fix clock reference leak in imx8m_soc_prepare() Felix Gu
2026-06-26 16:17 ` Frank Li
2026-06-28  8:25   ` Felix Gu
2026-06-29  7:21 ` Peng Fan (OSS)
2026-06-30 13:58   ` Felix Gu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome