[PATCH 3/8] clocksource/drivers/timer-goldfish: Fix resource leaks in init
Kuan-Wei Chiu
visitorckw at gmail.com
Thu Nov 5 08:16:57 PST 2026
goldfish_timer_init() ignores the return value of
clocksource_register_hz() and fails to release allocated resources when
initialization fails.
Check the return value of clocksource_register_hz() and clean up
allocated resources on error.
Fixes: c92e7ef16400 ("clocksource/drivers: Add a goldfish-timer clocksource")
Signed-off-by: Kuan-Wei Chiu <visitorckw at gmail.com>
---
drivers/clocksource/timer-goldfish.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/clocksource/timer-goldfish.c b/drivers/clocksource/timer-goldfish.c
index b1dc8b388470..8c312c3a64a6 100644
--- a/drivers/clocksource/timer-goldfish.c
+++ b/drivers/clocksource/timer-goldfish.c
@@ -131,7 +131,7 @@ int __init goldfish_timer_init(int irq, void __iomem *base)
ret = request_resource(&iomem_resource, &timerdrv->res);
if (ret) {
pr_err("Cannot allocate '%s' resource\n", timerdrv->res.name);
- return ret;
+ goto err_free;
}
timerdrv->cs = (struct clocksource){
@@ -143,17 +143,29 @@ int __init goldfish_timer_init(int irq, void __iomem *base)
.max_idle_ns = LONG_MAX,
};
- clocksource_register_hz(&timerdrv->cs, NSEC_PER_SEC);
+ ret = clocksource_register_hz(&timerdrv->cs, NSEC_PER_SEC);
+ if (ret) {
+ pr_err("Couldn't register goldfish-timer clocksource\n");
+ goto err_release_res;
+ }
ret = request_irq(irq, goldfish_timer_irq, IRQF_TIMER,
"goldfish_timer", timerdrv);
if (ret) {
pr_err("Couldn't register goldfish-timer interrupt\n");
- return ret;
+ goto err_unregister_cs;
}
clockevents_config_and_register(&timerdrv->ced, NSEC_PER_SEC,
1, 0xffffffff);
return 0;
+
+err_unregister_cs:
+ clocksource_unregister(&timerdrv->cs);
+err_release_res:
+ release_resource(&timerdrv->res);
+err_free:
+ kfree(timerdrv);
+ return ret;
}
--
2.56.0.398.g882cbad275-goog
More information about the linux-riscv
mailing list