linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: ti: Fix memleak in ti_fapll_synth_setup
@ 2020-11-13 13:16 Zhang Qilong
  2020-11-16  9:00 ` Tony Lindgren
  2020-12-17  9:46 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Qilong @ 2020-11-13 13:16 UTC (permalink / raw)
  To: t-kristo, mturquette, sboyd; +Cc: linux-omap, linux-clk

If clk_register fails, we should goto free branch
before function returns to prevent memleak.

Fixes: 163152cbbe321 ("clk: ti: Add support for FAPLL on dm816x")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/clk/ti/fapll.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/ti/fapll.c b/drivers/clk/ti/fapll.c
index 95e36ba64acc..8024c6d2b9e9 100644
--- a/drivers/clk/ti/fapll.c
+++ b/drivers/clk/ti/fapll.c
@@ -498,6 +498,7 @@ static struct clk * __init ti_fapll_synth_setup(struct fapll_data *fd,
 {
 	struct clk_init_data *init;
 	struct fapll_synth *synth;
+	struct clk *clk = ERR_PTR(-ENOMEM);
 
 	init = kzalloc(sizeof(*init), GFP_KERNEL);
 	if (!init)
@@ -520,13 +521,19 @@ static struct clk * __init ti_fapll_synth_setup(struct fapll_data *fd,
 	synth->hw.init = init;
 	synth->clk_pll = pll_clk;
 
-	return clk_register(NULL, &synth->hw);
+	clk = clk_register(NULL, &synth->hw);
+	if (IS_ERR(clk)) {
+		pr_err("failed to register clock\n");
+		goto free;
+	}
+
+	return clk;
 
 free:
 	kfree(synth);
 	kfree(init);
 
-	return ERR_PTR(-ENOMEM);
+	return clk;
 }
 
 static void __init ti_fapll_setup(struct device_node *node)
-- 
2.25.4


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

* Re: [PATCH] clk: ti: Fix memleak in ti_fapll_synth_setup
  2020-11-13 13:16 [PATCH] clk: ti: Fix memleak in ti_fapll_synth_setup Zhang Qilong
@ 2020-11-16  9:00 ` Tony Lindgren
  2020-12-17  9:46 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Tony Lindgren @ 2020-11-16  9:00 UTC (permalink / raw)
  To: Zhang Qilong; +Cc: t-kristo, mturquette, sboyd, linux-omap, linux-clk

* Zhang Qilong <zhangqilong3@huawei.com> [201113 13:13]:
> If clk_register fails, we should goto free branch
> before function returns to prevent memleak.
> 
> Fixes: 163152cbbe321 ("clk: ti: Add support for FAPLL on dm816x")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [PATCH] clk: ti: Fix memleak in ti_fapll_synth_setup
  2020-11-13 13:16 [PATCH] clk: ti: Fix memleak in ti_fapll_synth_setup Zhang Qilong
  2020-11-16  9:00 ` Tony Lindgren
@ 2020-12-17  9:46 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-12-17  9:46 UTC (permalink / raw)
  To: Zhang Qilong, mturquette, t-kristo; +Cc: linux-omap, linux-clk

Quoting Zhang Qilong (2020-11-13 05:16:23)
> If clk_register fails, we should goto free branch
> before function returns to prevent memleak.
> 
> Fixes: 163152cbbe321 ("clk: ti: Add support for FAPLL on dm816x")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---

Applied to clk-next

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

end of thread, other threads:[~2020-12-17  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 13:16 [PATCH] clk: ti: Fix memleak in ti_fapll_synth_setup Zhang Qilong
2020-11-16  9:00 ` Tony Lindgren
2020-12-17  9:46 ` Stephen Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).