]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu
authorZhang Qilong <zhangqilong3@huawei.com>
Fri, 13 Nov 2020 13:18:56 +0000 (21:18 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Nov 2020 11:48:11 +0000 (12:48 +0100)
[ Upstream commit ac3b57adf87ad9bac7e33ca26bbbb13fae1ed62b ]

If the clk_register fails, we should free h before
function returns to prevent memleak.

Fixes: 474402291a0ad ("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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/mips/alchemy/common/clock.c

index bd34f4093cd9f7d565be85dd3950849ebaa264a0..7b0dec333c96425cf4e27ba38b94809d650b17e5 100644 (file)
@@ -151,6 +151,7 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name,
 {
        struct clk_init_data id;
        struct clk_hw *h;
+       struct clk *clk;
 
        h = kzalloc(sizeof(*h), GFP_KERNEL);
        if (!h)
@@ -163,7 +164,13 @@ static struct clk __init *alchemy_clk_setup_cpu(const char *parent_name,
        id.ops = &alchemy_clkops_cpu;
        h->init = &id;
 
-       return clk_register(NULL, h);
+       clk = clk_register(NULL, h);
+       if (IS_ERR(clk)) {
+               pr_err("failed to register clock\n");
+               kfree(h);
+       }
+
+       return clk;
 }
 
 /* AUXPLLs ************************************************************/