All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Masney <bmasney@redhat.com>
To: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Cc: mturquette@baylibre.com, sboyd@kernel.org,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 7/7] clk: st: clkgen-pll: Add clk_unregister for odf_clk in clkgen_c32_pll_setup()
Date: Fri, 16 Jan 2026 10:53:16 -0500	[thread overview]
Message-ID: <aWpe7MWiJlduga23@redhat.com> (raw)
In-Reply-To: <20260116113847.1827694-8-lihaoxiang@isrc.iscas.ac.cn>

Hi Haoxiang,

On Fri, Jan 16, 2026 at 07:38:47PM +0800, Haoxiang Li wrote:
> In clkgen_c32_pll_setup(), clkgen_odf_register() allocated
> clk_gate and clk_divider memory and registered a clk. Add
> clk_unregister() and kfree() to release the memory if
> error occurs. Initialize odf to zero for safe.
> 
> Fixes: b9b8e614b580 ("clk: st: Support for PLLs inside ClockGenA(s)")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
>  drivers/clk/st/clkgen-pll.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
> index 89f0454fa72e..3fc0af4b77c6 100644
> --- a/drivers/clk/st/clkgen-pll.c
> +++ b/drivers/clk/st/clkgen-pll.c
> @@ -761,10 +761,12 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
>  	struct clk *pll_clk;
>  	const char *parent_name, *pll_name;
>  	void __iomem *pll_base;
> -	int num_odfs, odf;
> +	int num_odfs, odf = 0;
>  	struct clk_onecell_data *clk_data;
>  	unsigned long pll_flags = 0;
>  	struct clkgen_pll *pll;
> +	struct clk_gate *gate;
> +	struct clk_divider *div;
>  
>  	parent_name = of_clk_get_parent_name(np, 0);
>  	if (!parent_name)
> @@ -808,7 +810,7 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
>  			if (of_property_read_string_index(np,
>  							  "clock-output-names",
>  							  odf, &clk_name))
> -				return;
> +				goto err_odf_unregister;
>  
>  			of_clk_detect_critical(np, odf, &odf_flags);
>  		}
> @@ -816,8 +818,8 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
>  		odf_clk = clkgen_odf_register(pll_name, pll_base, datac->data,
>  				odf_flags, odf, &clkgena_c32_odf_lock,
>  				clk_name);
> -			goto err;
>  		if (IS_ERR(odf_clk))
> +			goto err_odf_unregister;
>  
>  		clk_data->clks[odf] = odf_clk;
>  	}
> @@ -825,6 +827,14 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
>  	of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
>  	return;
>  
> +err_odf_unregister:
> +	while (--odf >= 0) {

I think the prefix -- is not appropriate here. If clkgen_odf_register()
fails for the first odf (ie odf=0), then when we jump to
err_odf_unregister, odf will still be set to 0, --odf will set it to -1,
the while loop will not run, and won't free anything.

What do you think about using the postfix operator instead?

	while (odf-- >= 0)

Brian


  reply	other threads:[~2026-01-16 15:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 11:38 [PATCH 0/7] clk: st: clkgen-pll: Add cleanup in clkgen_c32_pll_setup() and clkgen_odf_register() Haoxiang Li
2026-01-16 11:38 ` [PATCH 1/7] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register() Haoxiang Li
2026-01-16 15:29   ` Brian Masney
2026-01-17 10:15   ` Markus Elfring
2026-01-16 11:38 ` [PATCH 2/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup() Haoxiang Li
2026-01-16 15:32   ` Brian Masney
2026-01-17 10:40   ` Markus Elfring
2026-01-16 11:38 ` [PATCH 3/7] " Haoxiang Li
2026-01-16 15:37   ` Brian Masney
2026-01-17 10:47   ` Markus Elfring
2026-01-16 11:38 ` [PATCH 4/7] clk: st: clkgen-pll: Add iounmap() " Haoxiang Li
2026-01-16 15:40   ` Brian Masney
2026-01-17 12:57   ` Markus Elfring
2026-01-16 11:38 ` [PATCH 5/7] clk: st: clkgen-pll: Add clk_unregister for pll_clk " Haoxiang Li
2026-01-16 15:43   ` Brian Masney
2026-01-16 11:38 ` [PATCH 6/7] clk: st: clkgen-pll: Remove redundant kfree() " Haoxiang Li
2026-01-16 15:45   ` Brian Masney
2026-01-16 11:38 ` [PATCH 7/7] clk: st: clkgen-pll: Add clk_unregister for odf_clk " Haoxiang Li
2026-01-16 15:53   ` Brian Masney [this message]
2026-01-17 13:43   ` Markus Elfring

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=aWpe7MWiJlduga23@redhat.com \
    --to=bmasney@redhat.com \
    --cc=lihaoxiang@isrc.iscas.ac.cn \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=sboyd@kernel.org \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.