2021-08-20 11:18:31

by Chun-Jie Chen

[permalink] [raw]
Subject: [v2 05/24] clk: mediatek: Fix resource leak in mtk_clk_simple_probe

Release clock data when clock driver probe fail to fix
possible resource leak.

Signed-off-by: Chun-Jie Chen <[email protected]>
---
drivers/clk/mediatek/clk-mtk.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index c3d385c0cfcb..74890759e98c 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -314,7 +314,15 @@ int mtk_clk_simple_probe(struct platform_device *pdev)

r = mtk_clk_register_gates(node, mcd->clks, mcd->num_clks, clk_data);
if (r)
- return r;
+ goto free_data;

- return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+ r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+ if (r)
+ goto free_data;
+
+ return r;
+
+free_data:
+ mtk_free_clk_data(clk_data);
+ return r;
}
--
2.18.0


2021-08-23 06:46:52

by Chen-Yu Tsai

[permalink] [raw]
Subject: Re: [v2 05/24] clk: mediatek: Fix resource leak in mtk_clk_simple_probe

On Fri, Aug 20, 2021 at 7:19 PM Chun-Jie Chen
<[email protected]> wrote:
>
> Release clock data when clock driver probe fail to fix
> possible resource leak.
>
> Signed-off-by: Chun-Jie Chen <[email protected]>

Reviewed-by: Chen-Yu Tsai <[email protected]>

> ---
> drivers/clk/mediatek/clk-mtk.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
> index c3d385c0cfcb..74890759e98c 100644
> --- a/drivers/clk/mediatek/clk-mtk.c
> +++ b/drivers/clk/mediatek/clk-mtk.c
> @@ -314,7 +314,15 @@ int mtk_clk_simple_probe(struct platform_device *pdev)
>
> r = mtk_clk_register_gates(node, mcd->clks, mcd->num_clks, clk_data);

Note for future reference: there is no unregister counterpart for
mtk_clk_register_*.


> if (r)
> - return r;
> + goto free_data;
>
> - return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
> + r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
> + if (r)
> + goto free_data;
> +
> + return r;
> +
> +free_data:
> + mtk_free_clk_data(clk_data);
> + return r;
> }
> --
> 2.18.0
> _______________________________________________
> Linux-mediatek mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-mediatek