mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] clocksource: ralink: Fix resource leaks in init error path
@ 2025-10-30  9:07 Haotian Zhang
  2025-11-05 13:39 ` Daniel Lezcano
  2025-11-26 14:40 ` [tip: timers/clocksource] clocksource/drivers/ralink: " tip-bot2 for Haotian Zhang
  0 siblings, 2 replies; 3+ messages in thread
From: Haotian Zhang @ 2025-10-30  9:07 UTC (permalink / raw)
  To: daniel.lezcano, tglx; +Cc: linux-kernel, Haotian Zhang

The ralink_systick_init() function does not release all acquired resources
on its error paths. If irq_of_parse_and_map() or a subsequent call fails,
the previously created I/O memory mapping and IRQ mapping are leaked.

Add goto-based error handling labels to ensure that all allocated
resources are correctly freed.

Fixes: 1f2acc5a8a0a ("MIPS: ralink: Add support for systick timer found on newer ralink SoC")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/clocksource/timer-ralink.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/timer-ralink.c b/drivers/clocksource/timer-ralink.c
index 6ecdb4228f76..68434d9ed910 100644
--- a/drivers/clocksource/timer-ralink.c
+++ b/drivers/clocksource/timer-ralink.c
@@ -130,14 +130,15 @@ static int __init ralink_systick_init(struct device_node *np)
 	systick.dev.irq = irq_of_parse_and_map(np, 0);
 	if (!systick.dev.irq) {
 		pr_err("%pOFn: request_irq failed", np);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_iounmap;
 	}
 
 	ret = clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
 				    SYSTICK_FREQ, 301, 16,
 				    clocksource_mmio_readl_up);
 	if (ret)
-		return ret;
+		goto err_free_irq;
 
 	clockevents_register_device(&systick.dev);
 
@@ -145,6 +146,12 @@ static int __init ralink_systick_init(struct device_node *np)
 			np, systick.dev.mult, systick.dev.shift);
 
 	return 0;
+
+err_free_irq:
+	irq_dispose_mapping(systick.dev.irq);
+err_iounmap:
+	iounmap(systick.membase);
+	return ret;
 }
 
 TIMER_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init);
-- 
2.50.1.windows.1


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

* Re: [PATCH] clocksource: ralink: Fix resource leaks in init error path
  2025-10-30  9:07 [PATCH] clocksource: ralink: Fix resource leaks in init error path Haotian Zhang
@ 2025-11-05 13:39 ` Daniel Lezcano
  2025-11-26 14:40 ` [tip: timers/clocksource] clocksource/drivers/ralink: " tip-bot2 for Haotian Zhang
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2025-11-05 13:39 UTC (permalink / raw)
  To: Haotian Zhang, tglx; +Cc: linux-kernel

On 10/30/25 10:07, Haotian Zhang wrote:
> The ralink_systick_init() function does not release all acquired resources
> on its error paths. If irq_of_parse_and_map() or a subsequent call fails,
> the previously created I/O memory mapping and IRQ mapping are leaked.
> 
> Add goto-based error handling labels to ensure that all allocated
> resources are correctly freed.
> 
> Fixes: 1f2acc5a8a0a ("MIPS: ralink: Add support for systick timer found on newer ralink SoC")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
> ---

Applied, thanks

-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

* [tip: timers/clocksource] clocksource/drivers/ralink: Fix resource leaks in init error path
  2025-10-30  9:07 [PATCH] clocksource: ralink: Fix resource leaks in init error path Haotian Zhang
  2025-11-05 13:39 ` Daniel Lezcano
@ 2025-11-26 14:40 ` tip-bot2 for Haotian Zhang
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Haotian Zhang @ 2025-11-26 14:40 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Haotian Zhang, Daniel Lezcano, x86, linux-kernel

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     2ba8e2aae1324704565a7d4d66f199d056c9e3c6
Gitweb:        https://git.kernel.org/tip/2ba8e2aae1324704565a7d4d66f199d056c9e3c6
Author:        Haotian Zhang <vulab@iscas.ac.cn>
AuthorDate:    Thu, 30 Oct 2025 17:07:10 +08:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Wed, 26 Nov 2025 11:24:34 +01:00

clocksource/drivers/ralink: Fix resource leaks in init error path

The ralink_systick_init() function does not release all acquired resources
on its error paths. If irq_of_parse_and_map() or a subsequent call fails,
the previously created I/O memory mapping and IRQ mapping are leaked.

Add goto-based error handling labels to ensure that all allocated
resources are correctly freed.

Fixes: 1f2acc5a8a0a ("MIPS: ralink: Add support for systick timer found on newer ralink SoC")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20251030090710.1603-1-vulab@iscas.ac.cn
---
 drivers/clocksource/timer-ralink.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/clocksource/timer-ralink.c b/drivers/clocksource/timer-ralink.c
index 6ecdb42..68434d9 100644
--- a/drivers/clocksource/timer-ralink.c
+++ b/drivers/clocksource/timer-ralink.c
@@ -130,14 +130,15 @@ static int __init ralink_systick_init(struct device_node *np)
 	systick.dev.irq = irq_of_parse_and_map(np, 0);
 	if (!systick.dev.irq) {
 		pr_err("%pOFn: request_irq failed", np);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto err_iounmap;
 	}
 
 	ret = clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
 				    SYSTICK_FREQ, 301, 16,
 				    clocksource_mmio_readl_up);
 	if (ret)
-		return ret;
+		goto err_free_irq;
 
 	clockevents_register_device(&systick.dev);
 
@@ -145,6 +146,12 @@ static int __init ralink_systick_init(struct device_node *np)
 			np, systick.dev.mult, systick.dev.shift);
 
 	return 0;
+
+err_free_irq:
+	irq_dispose_mapping(systick.dev.irq);
+err_iounmap:
+	iounmap(systick.membase);
+	return ret;
 }
 
 TIMER_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init);

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

end of thread, other threads:[~2025-11-26 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-30  9:07 [PATCH] clocksource: ralink: Fix resource leaks in init error path Haotian Zhang
2025-11-05 13:39 ` Daniel Lezcano
2025-11-26 14:40 ` [tip: timers/clocksource] clocksource/drivers/ralink: " tip-bot2 for Haotian Zhang

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®