[v2 1/3] clk: mediatek: Add error handle when fail to register clock provider
Chun-Jie Chen
chun-jie.chen at mediatek.com
Sun Jan 9 16:59:00 PST 2022
Need to deference registered clocks when fail to
regisiter clock provider.
Signed-off-by: Chun-Jie Chen <chun-jie.chen at mediatek.com>
---
drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 5 ++++-
drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 5 +++--
drivers/clk/mediatek/clk-mt8195-topckgen.c | 5 ++++-
drivers/clk/mediatek/clk-mt8195-vdo0.c | 5 ++++-
drivers/clk/mediatek/clk-mt8195-vdo1.c | 5 ++++-
drivers/clk/mediatek/clk-mtk.c | 14 +++++++++++++-
drivers/clk/mediatek/clk-mtk.h | 1 +
7 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
index 6156ceeed71e..be0a716e24d2 100644
--- a/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
+++ b/drivers/clk/mediatek/clk-mt8195-apmixedsys.c
@@ -126,10 +126,13 @@ static int clk_mt8195_apmixed_probe(struct platform_device *pdev)
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
if (r)
- goto free_apmixed_data;
+ goto unregister_clk;
return r;
+unregister_clk:
+ mtk_clk_unregister(clk_data);
+
free_apmixed_data:
mtk_free_clk_data(clk_data);
return r;
diff --git a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
index f1c84186346e..bc5fc84e48dd 100644
--- a/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
+++ b/drivers/clk/mediatek/clk-mt8195-apusys_pll.c
@@ -68,11 +68,12 @@ static int clk_mt8195_apusys_pll_probe(struct platform_device *pdev)
mtk_clk_register_plls(node, apusys_plls, ARRAY_SIZE(apusys_plls), clk_data);
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
if (r)
- goto free_apusys_pll_data;
+ goto unregister_clk;
return r;
-free_apusys_pll_data:
+unregister_clk:
+ mtk_clk_unregister(clk_data);
mtk_free_clk_data(clk_data);
return r;
}
diff --git a/drivers/clk/mediatek/clk-mt8195-topckgen.c b/drivers/clk/mediatek/clk-mt8195-topckgen.c
index 3e2aba9c40bb..02a1801dfe86 100644
--- a/drivers/clk/mediatek/clk-mt8195-topckgen.c
+++ b/drivers/clk/mediatek/clk-mt8195-topckgen.c
@@ -1254,10 +1254,13 @@ static int clk_mt8195_topck_probe(struct platform_device *pdev)
r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
if (r)
- goto free_top_data;
+ goto unregister_clk;
return r;
+unregister_clk:
+ mtk_clk_unregister(top_clk_data);
+
free_top_data:
mtk_free_clk_data(top_clk_data);
return r;
diff --git a/drivers/clk/mediatek/clk-mt8195-vdo0.c b/drivers/clk/mediatek/clk-mt8195-vdo0.c
index f7ff7618c714..b7ceb6c7a33f 100644
--- a/drivers/clk/mediatek/clk-mt8195-vdo0.c
+++ b/drivers/clk/mediatek/clk-mt8195-vdo0.c
@@ -105,10 +105,13 @@ static int clk_mt8195_vdo0_probe(struct platform_device *pdev)
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
if (r)
- goto free_vdo0_data;
+ goto unregister_clk;
return r;
+unregister_clk:
+ mtk_clk_unregister(clk_data);
+
free_vdo0_data:
mtk_free_clk_data(clk_data);
return r;
diff --git a/drivers/clk/mediatek/clk-mt8195-vdo1.c b/drivers/clk/mediatek/clk-mt8195-vdo1.c
index 03df8eae8838..cca90c2632a1 100644
--- a/drivers/clk/mediatek/clk-mt8195-vdo1.c
+++ b/drivers/clk/mediatek/clk-mt8195-vdo1.c
@@ -122,10 +122,13 @@ static int clk_mt8195_vdo1_probe(struct platform_device *pdev)
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
if (r)
- goto free_vdo1_data;
+ goto unregister_clk;
return r;
+unregister_clk:
+ mtk_clk_unregister(clk_data);
+
free_vdo1_data:
mtk_free_clk_data(clk_data);
return r;
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 8d5791b3f460..ee4de1094458 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -303,6 +303,15 @@ void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
}
}
+void mtk_clk_unregister(struct clk_onecell_data *clk_data)
+{
+ int i;
+
+ for (i = 0; i < clk_data->clk_num; i++)
+ clk_unregister(clk_data->clks[i]);
+}
+EXPORT_SYMBOL_GPL(mtk_clk_unregister);
+
int mtk_clk_simple_probe(struct platform_device *pdev)
{
const struct mtk_clk_desc *mcd;
@@ -324,10 +333,13 @@ int mtk_clk_simple_probe(struct platform_device *pdev)
r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
if (r)
- goto free_data;
+ goto unregister_clk;
return r;
+unregister_clk:
+ mtk_clk_unregister(clk_data);
+
free_data:
mtk_free_clk_data(clk_data);
return r;
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 0ff289d93452..4c0958f66f51 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -200,6 +200,7 @@ struct mtk_clk_divider {
void mtk_clk_register_dividers(const struct mtk_clk_divider *mcds,
int num, void __iomem *base, spinlock_t *lock,
struct clk_onecell_data *clk_data);
+void mtk_clk_unregister(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);
--
2.18.0
More information about the Linux-mediatek
mailing list