All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: mmp: pxa168: fix potential memory leaks in pxa168_clk_init()
@ 2022-04-07  9:01 xkernel.wang
  0 siblings, 0 replies; only message in thread
From: xkernel.wang @ 2022-04-07  9:01 UTC (permalink / raw)
  To: mturquette, sboyd; +Cc: linux-clk, linux-kernel, Xiaoke Wang

From: Xiaoke Wang <xkernel.wang@foxmail.com>

In pxa168_clk_init(), except for the first error path, the other error
paths directly return without releasing the allocated resources, which
can lead to memory leaks.

This patch unifies the error handling code and each error will jump to
the corresponding tag to release the resources.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
 drivers/clk/mmp/clk-of-pxa168.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/mmp/clk-of-pxa168.c b/drivers/clk/mmp/clk-of-pxa168.c
index f110c02..05b96cf 100644
--- a/drivers/clk/mmp/clk-of-pxa168.c
+++ b/drivers/clk/mmp/clk-of-pxa168.c
@@ -258,19 +258,19 @@ static void __init pxa168_clk_init(struct device_node *np)
 	pxa_unit->mpmu_base = of_iomap(np, 0);
 	if (!pxa_unit->mpmu_base) {
 		pr_err("failed to map mpmu registers\n");
-		return;
+		goto free_memory;
 	}
 
 	pxa_unit->apmu_base = of_iomap(np, 1);
 	if (!pxa_unit->apmu_base) {
 		pr_err("failed to map apmu registers\n");
-		return;
+		goto unmap_mpmu_region;
 	}
 
 	pxa_unit->apbc_base = of_iomap(np, 2);
 	if (!pxa_unit->apbc_base) {
 		pr_err("failed to map apbc registers\n");
-		return;
+		goto unmap_apmu_region;
 	}
 
 	mmp_clk_init(np, &pxa_unit->unit, PXA168_NR_CLKS);
@@ -282,6 +282,15 @@ static void __init pxa168_clk_init(struct device_node *np)
 	pxa168_axi_periph_clk_init(pxa_unit);
 
 	pxa168_clk_reset_init(np, pxa_unit);
+
+	return;
+
+unmap_apmu_region:
+	iounmap(pxa_unit->apmu_base);
+unmap_mpmu_region:
+	iounmap(pxa_unit->mpmu_base);
+free_memory:
+	kfree(pxa_unit);
 }
 
 CLK_OF_DECLARE(pxa168_clk, "marvell,pxa168-clock", pxa168_clk_init);
-- 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-07  9:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07  9:01 [PATCH] clk: mmp: pxa168: fix potential memory leaks in pxa168_clk_init() xkernel.wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.