Skip to content

Commit ac3b57a

Browse files
Zhang Qilongtsbogend
authored andcommitted
MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu
If the clk_register fails, we should free h before function returns to prevent memleak. Fixes: 4744022 ("MIPS: Alchemy: clock framework integration of onchip clocks") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 61a2f1a commit ac3b57a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

arch/mips/alchemy/common/clock.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name,
152152
{
153153
struct clk_init_data id;
154154
struct clk_hw *h;
155+
struct clk *clk;
155156

156157
h = kzalloc(sizeof(*h), GFP_KERNEL);
157158
if (!h)
@@ -164,7 +165,13 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name,
164165
id.ops = &alchemy_clkops_cpu;
165166
h->init = &id;
166167

167-
return clk_register(NULL, h);
168+
clk = clk_register(NULL, h);
169+
if (IS_ERR(clk)) {
170+
pr_err("failed to register clock\n");
171+
kfree(h);
172+
}
173+
174+
return clk;
168175
}
169176

170177
/* AUXPLLs ************************************************************/

0 commit comments

Comments
 (0)