Skip to contentSkip to conversation

clk: mediatek: Fix memory leaks on probe

PATCH Applied José Expósito 2 participants 2 messages Jan 15, 2022 – Jan 25, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clk: mediatek: Fix memory leaks on probe

----- Forwarded message from José Expósito <[email protected]> -----

Date: Wed, 15 Dec 2021 08:29:15 +0100
From: José Expósito <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected], José Expósito <[email protected]>, Chen-Yu Tsai <[email protected]>
Subject: [PATCH v2] clk: mediatek: Fix memory leaks on probe
X-Mailer: git-send-email 2.25.1

Handle the error branches to free memory where required.

Addresses-Coverity-ID: 1491825 ("Resource leak")

---

v2: Add Reviewed-by tag

Sorry, I forgot to add [email protected]

---
 drivers/clk/mediatek/clk-mt8192.c | 36 +++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)
drivers/clk/mediatek/clk-mt8192.c +30 -6
index cbc7c6dbe0f4..79ddb3cc0b98 100644
@@ -1236,9 +1236,17 @@ static int clk_mt8192_infra_probe(struct platform_device *pdev)
 
 	r = mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks), clk_data);
 	if (r)
-		return r;
+		goto free_clk_data;
+
+	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+	if (r)
+		goto free_clk_data;
+
+	return r;
 
-	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+free_clk_data:
+	mtk_free_clk_data(clk_data);
+	return r;
 }
 
 static int clk_mt8192_peri_probe(struct platform_device *pdev)
@@ -1253,9 +1261,17 @@ static int clk_mt8192_peri_probe(struct platform_device *pdev)
 
 	r = mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks), clk_data);
 	if (r)
-		return r;
+		goto free_clk_data;
+
+	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+	if (r)
+		goto free_clk_data;
 
-	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
+	return r;
+
+free_clk_data:
+	mtk_free_clk_data(clk_data);
+	return r;
 }
 
 static int clk_mt8192_apmixed_probe(struct platform_device *pdev)
@@ -1271,9 +1287,17 @@ static int clk_mt8192_apmixed_probe(struct platform_device *pdev)
 	mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
 	r = mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks), clk_data);
 	if (r)
-		return r;
+		goto free_clk_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_clk_data;
+
+	return r;
+
+free_clk_data:
+	mtk_free_clk_data(clk_data);
+	return r;
 }
 
 static const struct of_device_id of_match_clk_mt8192[] = {
Signature · 4 lines
2.25.1


----- End forwarded message -----
maintainer Applied
#1 lore raw

Quoting José Expósito (2022-01-15 10:30:59)

Quoted 1 line

----- Forwarded message from José Expósito <[email protected]> -----

Applied to clk-next