From: James Liao Date: Fri, 8 Jan 2016 08:15:33 +0000 (+0800) Subject: clk: mediatek: Fix memory leak on clock init fail X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4974259e18f1fd519d4329babbfefa24852375bb;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git clk: mediatek: Fix memory leak on clock init fail mtk_clk_register_composite() may leak memory due to some error handling path don't free all allocated memory. This patch free all pointers that may allocate memory before error return. And it's safe because kfree() can handle NULL pointers. Signed-off-by: James Liao Reviewed-by: Daniel Kurtz Signed-off-by: Stephen Boyd --- diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c index cf08db6c130c..352830369e0e 100644 --- a/drivers/clk/mediatek/clk-mtk.c +++ b/drivers/clk/mediatek/clk-mtk.c @@ -209,12 +209,14 @@ struct clk * __init mtk_clk_register_composite(const struct mtk_composite *mc, mc->flags); if (IS_ERR(clk)) { - kfree(gate); - kfree(mux); + ret = PTR_ERR(clk); + goto err_out; } return clk; err_out: + kfree(div); + kfree(gate); kfree(mux); return ERR_PTR(ret);