The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Brian Masney <bmasney@redhat.com>
To: Myeonghun Pak <mhun512@gmail.com>
Cc: Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ijae Kim <ae878000@gmail.com>
Subject: Re: [PATCH] clk: palmas: unprepare clock on provider registration failure
Date: Tue, 23 Jun 2026 09:59:22 -0400	[thread overview]
Message-ID: <ajqROjYdv28Yrqo5@redhat.com> (raw)
In-Reply-To: <20260623090738.13773-1-mhun512@gmail.com>

Hi Myeonghun,

Thanks for the patch!

On Tue, Jun 23, 2026 at 06:07:34PM +0900, Myeonghun Pak wrote:
> palmas_clks_init_configure() prepares the clock when an external control
> pin is configured.  If the subsequent of_clk_add_hw_provider() call fails,
> palmas_clks_probe() returns the error without dropping that prepare
> reference.
> 
> Unprepare the clock on that error path when external control is active, so
> the probe failure path balances the successful clk_prepare().
> 
> This issue was identified during our ongoing static-analysis research while
> reviewing kernel code.
> 
> Fixes: 942d1d674931 ("clk: Add driver for Palmas clk32kg and clk32kgaudio clocks")
> Co-developed-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
> 
> ---
>  drivers/clk/clk-palmas.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-palmas.c b/drivers/clk/clk-palmas.c
> index 39049f62db..ab9df2eedb 100644
> --- a/drivers/clk/clk-palmas.c
> +++ b/drivers/clk/clk-palmas.c
> @@ -265,8 +265,11 @@ static int palmas_clks_probe(struct platform_device *pdev)
>  	}
>  
>  	ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, &cinfo->hw);
> -	if (ret < 0)
> +	if (ret < 0) {
>  		dev_err(&pdev->dev, "Fail to add clock driver, %d\n", ret);
> +		if (cinfo->ext_control_pin)
> +			clk_unprepare(cinfo->hw.clk);
> +	}

The driver currently only calls clk_unprepare() on an error path in
palmas_clks_init_configure(). It leaks when the driver is removed.

I think the cleanest approach to fixing this is to convert over to use
devm_of_clk_add_hw_provider().

Brian


      reply	other threads:[~2026-06-23 13:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23  9:07 [PATCH] clk: palmas: unprepare clock on provider registration failure Myeonghun Pak
2026-06-23 13:59 ` Brian Masney [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ajqROjYdv28Yrqo5@redhat.com \
    --to=bmasney@redhat.com \
    --cc=ae878000@gmail.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhun512@gmail.com \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox