Skip to contentSkip to conversation

clk: mediatek: add unregister logic to mtk_clk_simple_probe error path

PATCH In review Miles Chen 2 participants 3 messages Jan 17, 2022 – Jan 25, 2022

Subsystems (2)
lore
Share & tools
lore

Miles Chen

author
#0 lore raw

PATCH 1/1 clk: mediatek: add unregister logic to mtk_clk_simple_probe error path

Stephen pointed out that there is no unregister logic in mtk_clk_simple_probe() error path [1].
Fix it by adding unregister logic to mtk_clk_simple_probe().

[1] https://lore.kernel.org/linux-mediatek/[email protected]/

Fixes c58cd0e40ffa ("clk: mediatek: Add mtk_clk_simple_probe() to simplify clock providers")
Cc Stephen Boyd <[email protected]>
---
 drivers/clk/mediatek/clk-mtk.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/clk/mediatek/clk-mtk.c +21 -3
index 8d5791b3f460..edf21975cb4d 100644
@@ -161,6 +161,22 @@ int mtk_clk_register_gates(struct device_node *node,
 }
 EXPORT_SYMBOL_GPL(mtk_clk_register_gates);
 
+static void mtk_clk_unregister_gates(const struct mtk_gate *clks,
+		int num, struct clk_onecell_data *clk_data)
+{
+	int i;
+	const struct mtk_gate *gate;
+	struct clk *clk;
+
+	for (i = 0; i < num; i++) {
+		gate = &clks[i];
+		clk = clk_data->clks[gate->id];
+
+		if (!IS_ERR_OR_NULL(clk))
+			clk_unregister(clk);
+	}
+}
+
 struct clk *mtk_clk_register_composite(const struct mtk_composite *mc,
 		void __iomem *base, spinlock_t *lock)
 {
@@ -320,15 +336,17 @@ int mtk_clk_simple_probe(struct platform_device *pdev)
 
 	r = mtk_clk_register_gates(node, mcd->clks, mcd->num_clks, clk_data);
 	if (r)
-		goto free_data;
+		goto err_free_data;
 
 	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
 	if (r)
-		goto free_data;
+		goto err_unregister_gates;
 
 	return r;
 
-free_data:
+err_unregister_gates:
+	mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
+err_free_data:
 	mtk_free_clk_data(clk_data);
 	return r;
 }
Signature · 1 line
2.18.0
author
#1 lore raw

Hi Stephen,

Quoted 3 lines

Stephen pointed out that there is no unregister logic in mtk_clk_simple_probe() error path [1].
Fix it by adding unregister logic to mtk_clk_simple_probe().

Chen-Yu's work [1] already addresses this problem. So please ignore this patch.

[1] https://lore.kernel.org/lkml/[email protected]/

maintainer
#2 lore raw

Quoting Miles Chen (2022-01-23 21:20:38)

Quoted 8 lines

Hi Stephen,

Quoted 3 lines

Stephen pointed out that there is no unregister logic in mtk_clk_simple_probe() error path [1].
Fix it by adding unregister logic to mtk_clk_simple_probe().

Chen-Yu's work [1] already addresses this problem. So please ignore this patch.

Alright. Thanks.

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek