clk: mediatek: Add API for clock resource recycle
authorChun-Jie Chen <chun-jie.chen@mediatek.com>
Tue, 14 Sep 2021 02:16:13 +0000 (10:16 +0800)
committerStephen Boyd <sboyd@kernel.org>
Tue, 14 Sep 2021 22:05:37 +0000 (15:05 -0700)
In order to avoid resource leak when fail clock registration appears,
so adds the common interface to handle it.

Signed-off-by: Chun-Jie Chen <chun-jie.chen@mediatek.com>
Reviewed-by: Chen-Yu Tsai <wenst@chromium.org>
Link: https://lore.kernel.org/r/20210914021633.26377-5-chun-jie.chen@mediatek.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/mediatek/clk-mtk.c
drivers/clk/mediatek/clk-mtk.h

index 4b6096c44d74f3a33962653e3e3d8ab465d85a82..c3d385c0cfcbffc3f8a8c82ad8d9eb0d9ee04463 100644 (file)
@@ -43,6 +43,15 @@ err_out:
        return NULL;
 }
 
+void mtk_free_clk_data(struct clk_onecell_data *clk_data)
+{
+       if (!clk_data)
+               return;
+
+       kfree(clk_data->clks);
+       kfree(clk_data);
+}
+
 void mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks,
                int num, struct clk_onecell_data *clk_data)
 {
index 7de41c3b320679761895afcadb06cbd7d01bd107..0ff289d93452c3c780bef01dafa976f4b6669fc6 100644 (file)
@@ -202,6 +202,7 @@ void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
                                struct clk_onecell_data *clk_data);
 
 struct clk_onecell_data *mtk_alloc_clk_data(unsigned int clk_num);
+void mtk_free_clk_data(struct clk_onecell_data *clk_data);
 
 #define HAVE_RST_BAR   BIT(0)
 #define PLL_AO         BIT(1)