Skip to content

Commit 2ba8e2a

Browse files
ISCAS-Vulabdlezcano
authored andcommitted
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: 1f2acc5 ("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
1 parent 640594a commit 2ba8e2a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

drivers/clocksource/timer-ralink.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,28 @@ static int __init ralink_systick_init(struct device_node *np)
130130
systick.dev.irq = irq_of_parse_and_map(np, 0);
131131
if (!systick.dev.irq) {
132132
pr_err("%pOFn: request_irq failed", np);
133-
return -EINVAL;
133+
ret = -EINVAL;
134+
goto err_iounmap;
134135
}
135136

136137
ret = clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name,
137138
SYSTICK_FREQ, 301, 16,
138139
clocksource_mmio_readl_up);
139140
if (ret)
140-
return ret;
141+
goto err_free_irq;
141142

142143
clockevents_register_device(&systick.dev);
143144

144145
pr_info("%pOFn: running - mult: %d, shift: %d\n",
145146
np, systick.dev.mult, systick.dev.shift);
146147

147148
return 0;
149+
150+
err_free_irq:
151+
irq_dispose_mapping(systick.dev.irq);
152+
err_iounmap:
153+
iounmap(systick.membase);
154+
return ret;
148155
}
149156

150157
TIMER_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init);

0 commit comments

Comments
 (0)