]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
clk: ti: Fix memleak in ti_fapll_synth_setup
authorZhang Qilong <zhangqilong3@huawei.com>
Fri, 13 Nov 2020 13:16:23 +0000 (21:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Dec 2020 12:42:41 +0000 (13:42 +0100)
[ Upstream commit 8c6239f6e95f583bb763d0228e02d4dd0fb3d492 ]

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>
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>
drivers/clk/ti/fapll.c

index 66a0d0ed8b55064ac7a888a1d2e6441d3021ceb1..02ff499e36536f1d4b764f9c1ea55485c833ea85 100644 (file)
@@ -497,6 +497,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)
@@ -519,13 +520,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)