* [PATCH 1/7] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()
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 ` 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
` (5 subsequent siblings)
6 siblings, 2 replies; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li, stable
If clk_register_composite() fails, call kfree() to release
div and gate.
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 | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
index c258ff87a171..a7d605b52cf3 100644
--- a/drivers/clk/st/clkgen-pll.c
+++ b/drivers/clk/st/clkgen-pll.c
@@ -742,8 +742,11 @@ static struct clk * __init clkgen_odf_register(const char *parent_name,
&div->hw, &clk_divider_ops,
&gate->hw, &clk_gate_ops,
flags);
- if (IS_ERR(clk))
+ if (IS_ERR(clk)) {
+ kfree(div);
+ kfree(gate);
return clk;
+ }
pr_debug("%s: parent %s rate %lu\n",
__clk_get_name(clk),
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH 1/7] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()
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
1 sibling, 0 replies; 20+ messages in thread
From: Brian Masney @ 2026-01-16 15:29 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mturquette, sboyd, linux-clk, linux-kernel, stable
On Fri, Jan 16, 2026 at 07:38:41PM +0800, Haoxiang Li wrote:
> If clk_register_composite() fails, call kfree() to release
> div and gate.
>
> 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>
Reviewed-by: Brian Masney <bmasney@redhat.com>
Note for next time: I sent out a Reviewed-by tag on this patch on the
previous version. Please include those tags on the future versions.
The only time it's appropriate to not include the tag is if you make
changes to the patch beyond a trivial change.
Also you may want to consider using b4 for your workflow since it really
simplifies your workflow. There's some documentation available at:
https://b4.docs.kernel.org/en/latest/
Basically, here's a quick workflow of what I do:
# Start with a clean branch (say today's linux-next)
# Create a new b4-managed branch
b4 prep -n my-branch-name
# Apply your patches
b4 prep --edit-cover
b4 prep --auto-to-cc
b4 prep --check
b4 send --dry-run
# Send out your patch series for real
b4 send
Later if you need to send out a new version, just use the same b4
managed branch. It'll track the patch version number for you (the
PATCH v2 in the subject).
You can use 'b4 trailers'
(https://b4.docs.kernel.org/en/latest/contributor/trailers.html) to pick
up tags from the list.
There's also a b4 web submission endpoint you can use instead of sending
it through a SMTP server:
https://b4.docs.kernel.org/en/latest/contributor/send.html
Brian
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH 1/7] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()
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
1 sibling, 0 replies; 20+ messages in thread
From: Markus Elfring @ 2026-01-17 10:15 UTC (permalink / raw)
To: Haoxiang Li, linux-clk, Brian Masney, Michael Turquette,
Stephen Boyd
Cc: stable, LKML
> If clk_register_composite() fails, call kfree() to release
> div and gate.
You may put such information also into a single text line.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n659
How do you think about to avoid a bit of duplicate source code here?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.19-rc5#n526
Regards,
Markus
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 2/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
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 11:38 ` 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
` (4 subsequent siblings)
6 siblings, 2 replies; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li
In clkgen_c32_pll_setup(), `clk` is used for two distint variables' name.
This patch rename the preceding `clk` to `pll_clk`.
The rename is in preparation for cleaning up some memory leaks.
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
drivers/clk/st/clkgen-pll.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
index a7d605b52cf3..0390f6834a0d 100644
--- a/drivers/clk/st/clkgen-pll.c
+++ b/drivers/clk/st/clkgen-pll.c
@@ -755,11 +755,10 @@ static struct clk * __init clkgen_odf_register(const char *parent_name,
return clk;
}
-
static void __init clkgen_c32_pll_setup(struct device_node *np,
struct clkgen_pll_data_clks *datac)
{
- struct clk *clk;
+ struct clk *pll_clk;
const char *parent_name, *pll_name;
void __iomem *pll_base;
int num_odfs, odf;
@@ -777,12 +776,12 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
of_clk_detect_critical(np, 0, &pll_flags);
- clk = clkgen_pll_register(parent_name, datac->data, pll_base, pll_flags,
+ pll_clk = clkgen_pll_register(parent_name, datac->data, pll_base, pll_flags,
np->name, datac->data->lock);
- if (IS_ERR(clk))
return;
+ if (IS_ERR(pll_clk))
- pll_name = __clk_get_name(clk);
+ pll_name = __clk_get_name(pll_clk);
num_odfs = datac->data->num_odfs;
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH 2/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
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
1 sibling, 0 replies; 20+ messages in thread
From: Brian Masney @ 2026-01-16 15:32 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mturquette, sboyd, linux-clk, linux-kernel
On Fri, Jan 16, 2026 at 07:38:42PM +0800, Haoxiang Li wrote:
> In clkgen_c32_pll_setup(), `clk` is used for two distint variables' name.
> This patch rename the preceding `clk` to `pll_clk`.
> The rename is in preparation for cleaning up some memory leaks.
>
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH 2/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
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
1 sibling, 0 replies; 20+ messages in thread
From: Markus Elfring @ 2026-01-17 10:40 UTC (permalink / raw)
To: Haoxiang Li, linux-clk, Brian Masney, Michael Turquette,
Stephen Boyd; +Cc: LKML
> In clkgen_c32_pll_setup(), `clk` is used for two distint variables' name.
distinct variable names?
> This patch rename …
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94
Regards,
Markus
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 3/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
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 11:38 ` [PATCH 2/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup() Haoxiang Li
@ 2026-01-16 11:38 ` 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
` (3 subsequent siblings)
6 siblings, 2 replies; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li
In clkgen_c32_pll_setup(), `clk` is used for two distint variables' name.
This patch rename the later `clk` to `odf_clk`.
The rename is in preparation for cleaning up some memory leaks.
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
drivers/clk/st/clkgen-pll.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
index 0390f6834a0d..4ff9b35fe399 100644
--- a/drivers/clk/st/clkgen-pll.c
+++ b/drivers/clk/st/clkgen-pll.c
@@ -797,7 +797,7 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
goto err;
for (odf = 0; odf < num_odfs; odf++) {
- struct clk *clk;
+ struct clk *odf_clk;
const char *clk_name;
unsigned long odf_flags = 0;
@@ -813,13 +813,13 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
of_clk_detect_critical(np, odf, &odf_flags);
}
- clk = clkgen_odf_register(pll_name, pll_base, datac->data,
+ odf_clk = clkgen_odf_register(pll_name, pll_base, datac->data,
odf_flags, odf, &clkgena_c32_odf_lock,
clk_name);
- if (IS_ERR(clk))
goto err;
+ if (IS_ERR(odf_clk))
- clk_data->clks[odf] = clk;
+ clk_data->clks[odf] = odf_clk;
}
of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH 3/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
2026-01-16 11:38 ` [PATCH 3/7] " Haoxiang Li
@ 2026-01-16 15:37 ` Brian Masney
2026-01-17 10:47 ` Markus Elfring
1 sibling, 0 replies; 20+ messages in thread
From: Brian Masney @ 2026-01-16 15:37 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mturquette, sboyd, linux-clk, linux-kernel
Hi Haoxiang,
On Fri, Jan 16, 2026 at 07:38:43PM +0800, Haoxiang Li wrote:
> In clkgen_c32_pll_setup(), `clk` is used for two distint variables' name.
> This patch rename the later `clk` to `odf_clk`.
> The rename is in preparation for cleaning up some memory leaks.
>
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
> ---
> drivers/clk/st/clkgen-pll.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
> index 0390f6834a0d..4ff9b35fe399 100644
> --- a/drivers/clk/st/clkgen-pll.c
> +++ b/drivers/clk/st/clkgen-pll.c
> @@ -797,7 +797,7 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
> goto err;
>
> for (odf = 0; odf < num_odfs; odf++) {
> - struct clk *clk;
> + struct clk *odf_clk;
> const char *clk_name;
> unsigned long odf_flags = 0;
>
> @@ -813,13 +813,13 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
> of_clk_detect_critical(np, odf, &odf_flags);
> }
>
> - clk = clkgen_odf_register(pll_name, pll_base, datac->data,
> + odf_clk = clkgen_odf_register(pll_name, pll_base, datac->data,
> odf_flags, odf, &clkgena_c32_odf_lock,
> clk_name);
> - if (IS_ERR(clk))
> goto err;
> + if (IS_ERR(odf_clk))
This if shouldn't have been moved below the goto.
Also for the subject:
> Subject: [PATCH 2/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
I would use the specific variable name like this:
clk: st: clkgen-pll: Rename clk variable in clkgen_c32_pll_setup()
Brian
>
> - clk_data->clks[odf] = clk;
> + clk_data->clks[odf] = odf_clk;
> }
>
> of_clk_add_provider(np, of_clk_src_onecell_get, clk_data);
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH 3/7] clk: st: clkgen-pll: Rename some variables in clkgen_c32_pll_setup()
2026-01-16 11:38 ` [PATCH 3/7] " Haoxiang Li
2026-01-16 15:37 ` Brian Masney
@ 2026-01-17 10:47 ` Markus Elfring
1 sibling, 0 replies; 20+ messages in thread
From: Markus Elfring @ 2026-01-17 10:47 UTC (permalink / raw)
To: Haoxiang Li, linux-clk, Brian Masney, Michael Turquette,
Stephen Boyd; +Cc: LKML
> In clkgen_c32_pll_setup(), `clk` is used for two distint variables' name.
distinct variable names?
> This patch rename …
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94
Regards,
Markus
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 4/7] clk: st: clkgen-pll: Add iounmap() in clkgen_c32_pll_setup()
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
` (2 preceding siblings ...)
2026-01-16 11:38 ` [PATCH 3/7] " Haoxiang Li
@ 2026-01-16 11:38 ` 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
` (2 subsequent siblings)
6 siblings, 2 replies; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li, stable
Add a iounmap() to release the memory allocated by
clkgen_get_register_base() in error path.
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 | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
index 4ff9b35fe399..0239835b4015 100644
--- a/drivers/clk/st/clkgen-pll.c
+++ b/drivers/clk/st/clkgen-pll.c
@@ -778,8 +778,8 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
pll_clk = clkgen_pll_register(parent_name, datac->data, pll_base, pll_flags,
np->name, datac->data->lock);
- return;
if (IS_ERR(pll_clk))
+ goto err_unmap;
pll_name = __clk_get_name(pll_clk);
@@ -829,7 +829,11 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
kfree(pll_name);
kfree(clk_data->clks);
kfree(clk_data);
+err_unmap:
+ if (pll_base)
+ iounmap(pll_base);
}
+
static void __init clkgen_c32_pll0_setup(struct device_node *np)
{
clkgen_c32_pll_setup(np,
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH 4/7] clk: st: clkgen-pll: Add iounmap() in clkgen_c32_pll_setup()
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
1 sibling, 0 replies; 20+ messages in thread
From: Brian Masney @ 2026-01-16 15:40 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mturquette, sboyd, linux-clk, linux-kernel, stable
On Fri, Jan 16, 2026 at 07:38:44PM +0800, Haoxiang Li wrote:
> Add a iounmap() to release the memory allocated by
> clkgen_get_register_base() in error path.
>
> 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>
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH 4/7] clk: st: clkgen-pll: Add iounmap() in clkgen_c32_pll_setup()
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
1 sibling, 0 replies; 20+ messages in thread
From: Markus Elfring @ 2026-01-17 12:57 UTC (permalink / raw)
To: Haoxiang Li, linux-clk, Brian Masney, Michael Turquette,
Stephen Boyd
Cc: stable, LKML, kernel-janitors
> Add a iounmap() to release the memory allocated by
an call?
> clkgen_get_register_base() in error path.
Was such an improvable implementation detail detected by any known source code
analysis approaches?
…
> +++ b/drivers/clk/st/clkgen-pll.c
…
> @@ -829,7 +829,11 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
> kfree(pll_name);
> kfree(clk_data->clks);
> kfree(clk_data);
> +err_unmap:
> + if (pll_base)
> + iounmap(pll_base);
* I find this pointer check redundant because of a previous variable check.
https://elixir.bootlin.com/linux/v6.19-rc5/source/drivers/clk/st/clkgen-pll.c#L771-L773
* I suggest to refine the goto chain a bit more.
> }
> +
> static void __init clkgen_c32_pll0_setup(struct device_node *np)
…
Regards,
Markus
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 5/7] clk: st: clkgen-pll: Add clk_unregister for pll_clk in clkgen_c32_pll_setup()
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
` (3 preceding siblings ...)
2026-01-16 11:38 ` [PATCH 4/7] clk: st: clkgen-pll: Add iounmap() " Haoxiang Li
@ 2026-01-16 11:38 ` 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 11:38 ` [PATCH 7/7] clk: st: clkgen-pll: Add clk_unregister for odf_clk " Haoxiang Li
6 siblings, 1 reply; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li, stable
In clkgen_c32_pll_setup(), clkgen_pll_register() allocated a
clkgen_pll memory and registered a clk. Add clk_unregister()
and kfree() to release the memory if error occurs.
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 | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
index 0239835b4015..f748e1fce735 100644
--- a/drivers/clk/st/clkgen-pll.c
+++ b/drivers/clk/st/clkgen-pll.c
@@ -764,7 +764,7 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
int num_odfs, odf;
struct clk_onecell_data *clk_data;
unsigned long pll_flags = 0;
-
+ struct clkgen_pll *pll;
parent_name = of_clk_get_parent_name(np, 0);
if (!parent_name)
@@ -787,7 +787,7 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
clk_data = kzalloc(sizeof(*clk_data), GFP_KERNEL);
if (!clk_data)
- return;
+ goto err_pll_unregister;
clk_data->clk_num = num_odfs;
clk_data->clks = kcalloc(clk_data->clk_num, sizeof(struct clk *),
@@ -829,6 +829,10 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
kfree(pll_name);
kfree(clk_data->clks);
kfree(clk_data);
+err_pll_unregister:
+ pll = to_clkgen_pll(__clk_get_hw(pll_clk));
+ clk_unregister(pll_clk);
+ kfree(pll);
err_unmap:
if (pll_base)
iounmap(pll_base);
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* [PATCH 6/7] clk: st: clkgen-pll: Remove redundant kfree() in clkgen_c32_pll_setup()
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
` (4 preceding siblings ...)
2026-01-16 11:38 ` [PATCH 5/7] clk: st: clkgen-pll: Add clk_unregister for pll_clk " Haoxiang Li
@ 2026-01-16 11:38 ` 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
6 siblings, 1 reply; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li
In clkgen_c32_pll_setup(), pll_name is actually pll_clk -> core->name.
This variable will be released in clk_unregister() -> __clk_release()
if some error occurs. Thus kfree(pll_name) will cause a double free.
Remove this redundant kfree().
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
drivers/clk/st/clkgen-pll.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/clk/st/clkgen-pll.c b/drivers/clk/st/clkgen-pll.c
index f748e1fce735..89f0454fa72e 100644
--- a/drivers/clk/st/clkgen-pll.c
+++ b/drivers/clk/st/clkgen-pll.c
@@ -826,7 +826,6 @@ static void __init clkgen_c32_pll_setup(struct device_node *np,
return;
err:
- kfree(pll_name);
kfree(clk_data->clks);
kfree(clk_data);
err_pll_unregister:
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH 6/7] clk: st: clkgen-pll: Remove redundant kfree() in clkgen_c32_pll_setup()
2026-01-16 11:38 ` [PATCH 6/7] clk: st: clkgen-pll: Remove redundant kfree() " Haoxiang Li
@ 2026-01-16 15:45 ` Brian Masney
0 siblings, 0 replies; 20+ messages in thread
From: Brian Masney @ 2026-01-16 15:45 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mturquette, sboyd, linux-clk, linux-kernel
On Fri, Jan 16, 2026 at 07:38:46PM +0800, Haoxiang Li wrote:
> In clkgen_c32_pll_setup(), pll_name is actually pll_clk -> core->name.
> This variable will be released in clk_unregister() -> __clk_release()
> if some error occurs. Thus kfree(pll_name) will cause a double free.
> Remove this redundant kfree().
>
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
A fixes tag is definitely appropriate here.
Fixes: b9b8e614b580 ("clk: st: Support for PLLs inside ClockGenA(s)")
Reviewed-by: Brian Masney <bmasney@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH 7/7] clk: st: clkgen-pll: Add clk_unregister for odf_clk in clkgen_c32_pll_setup()
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
` (5 preceding siblings ...)
2026-01-16 11:38 ` [PATCH 6/7] clk: st: clkgen-pll: Remove redundant kfree() " Haoxiang Li
@ 2026-01-16 11:38 ` Haoxiang Li
2026-01-16 15:53 ` Brian Masney
2026-01-17 13:43 ` Markus Elfring
6 siblings, 2 replies; 20+ messages in thread
From: Haoxiang Li @ 2026-01-16 11:38 UTC (permalink / raw)
To: mturquette, sboyd, bmasney; +Cc: linux-clk, linux-kernel, Haoxiang Li, stable
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) {
+ gate = to_clk_gate(__clk_get_hw(clk_data->clks[odf]));
+ div = to_clk_divider(__clk_get_hw(clk_data->clks[odf]));
+ clk_unregister_composite(clk_data->clks[odf]);
+ kfree(div);
+ kfree(gate);
+ }
err:
kfree(clk_data->clks);
kfree(clk_data);
--
2.25.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH 7/7] clk: st: clkgen-pll: Add clk_unregister for odf_clk in clkgen_c32_pll_setup()
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
2026-01-17 13:43 ` Markus Elfring
1 sibling, 0 replies; 20+ messages in thread
From: Brian Masney @ 2026-01-16 15:53 UTC (permalink / raw)
To: Haoxiang Li; +Cc: mturquette, sboyd, linux-clk, linux-kernel, stable
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
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH 7/7] clk: st: clkgen-pll: Add clk_unregister for odf_clk in clkgen_c32_pll_setup()
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
@ 2026-01-17 13:43 ` Markus Elfring
1 sibling, 0 replies; 20+ messages in thread
From: Markus Elfring @ 2026-01-17 13:43 UTC (permalink / raw)
To: Haoxiang Li, linux-clk, Brian Masney, Michael Turquette,
Stephen Boyd
Cc: stable, LKML
> 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
You may occasionally put more than 58 characters into text lines
of such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n659
> error occurs. Initialize odf to zero for safe.
data processing?
Regards,
Markus
^ permalink raw reply [flat|nested] 20+ messages in thread