Skip to content

Commit

Permalink
clk: mediatek: Fix memory leak on clock init fail
Browse files Browse the repository at this point in the history
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 <jamesjj.liao@mediatek.com>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
  • Loading branch information
James Liao authored and Stephen Boyd committed Jan 29, 2016
1 parent 5fd9c05 commit 4974259
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/clk/mediatek/clk-mtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4974259

Please sign in to comment.