mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] clocksource: clps711x: Fix resource leaks in error paths
@ 2025-07-31  6:23 Zhen Ni
  2025-08-01 14:00 ` Markus Elfring
  2025-08-04 12:36 ` [PATCH v2] " Zhen Ni
  0 siblings, 2 replies; 8+ messages in thread
From: Zhen Ni @ 2025-07-31  6:23 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel, Zhen Ni

The current implementation of clps711x_timer_init() has multiple error
paths that directly return without releasing the base I/O memory mapped
via of_iomap(). This leads to resource leaks when:
1. irq_of_parse_and_map() fails
2. of_clk_get() returns an error
3. _clps711x_clkevt_init() fails for CLOCKEVENT alias
4. An unrecognized timer alias is provided

Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
 drivers/clocksource/clps711x-timer.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/clocksource/clps711x-timer.c b/drivers/clocksource/clps711x-timer.c
index e95fdc49c226..f803d694c7a4 100644
--- a/drivers/clocksource/clps711x-timer.c
+++ b/drivers/clocksource/clps711x-timer.c
@@ -78,24 +78,34 @@ static int __init clps711x_timer_init(struct device_node *np)
 	unsigned int irq = irq_of_parse_and_map(np, 0);
 	struct clk *clock = of_clk_get(np, 0);
 	void __iomem *base = of_iomap(np, 0);
+	int ret = 0;
 
 	if (!base)
 		return -ENOMEM;
-	if (!irq)
-		return -EINVAL;
-	if (IS_ERR(clock))
-		return PTR_ERR(clock);
+	if (!irq) {
+		ret = -EINVAL;
+		goto out;
+	}
+	if (IS_ERR(clock)) {
+		ret = PTR_ERR(clock);
+		goto out;
+	}
 
 	switch (of_alias_get_id(np, "timer")) {
 	case CLPS711X_CLKSRC_CLOCKSOURCE:
 		clps711x_clksrc_init(clock, base);
 		break;
 	case CLPS711X_CLKSRC_CLOCKEVENT:
-		return _clps711x_clkevt_init(clock, base, irq);
+		ret =  _clps711x_clkevt_init(clock, base, irq);
+		break;
 	default:
-		return -EINVAL;
+		ret = -EINVAL;
+		break;
 	}
 
-	return 0;
+out:
+	if (base)
+		iounmap(base);
+	return ret;
 }
 TIMER_OF_DECLARE(clps711x, "cirrus,ep7209-timer", clps711x_timer_init);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-19  6:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-31  6:23 [PATCH] clocksource: clps711x: Fix resource leaks in error paths Zhen Ni
2025-08-01 14:00 ` Markus Elfring
2025-08-04 12:36 ` [PATCH v2] " Zhen Ni
2025-08-04 12:52   ` Markus Elfring
     [not found]   ` <20250805035637.169422-1-zhen.ni@easystack.cn>
2025-08-13 12:14     ` [PATCH v3] " Daniel Lezcano
2025-08-14 12:33   ` Zhen Ni
2025-09-17 16:05     ` Daniel Lezcano
2025-09-19  3:54     ` [PATCH v4] " Zhen Ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®