[PATCH] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()

Haoxiang Li posted 1 patch 3 weeks, 3 days ago
drivers/clk/st/clkgen-pll.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()
Posted by Haoxiang Li 3 weeks, 3 days ago
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
Re: [PATCH] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()
Posted by Markus Elfring 3 weeks, 3 days ago
> 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
Re: [PATCH] clk: st: clkgen-pll: Fix a memory leak in clkgen_odf_register()
Posted by Brian Masney 3 weeks, 3 days ago
On Thu, Jan 15, 2026 at 12:55:24PM +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>

This patch looks good, however this patch belongs in a series with
your other work to clkgen-pll. I'm going to leave some comments on your
other patch that you posted to this driver.

Brian