Skip to content

Commit

Permalink
clk: ti: Fix memleak in ti_fapll_synth_setup
Browse files Browse the repository at this point in the history
[ Upstream commit 8c6239f ]

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

Fixes: 163152c ("clk: ti: Add support for FAPLL on dm816x")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Link: https://lore.kernel.org/r/20201113131623.2098222-1-zhangqilong3@huawei.com
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Zhang Qilong authored and gregkh committed Dec 30, 2020
1 parent 572eba1 commit d4515a2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions drivers/clk/ti/fapll.c
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d4515a2

Please sign in to comment.