blob: 3f7cac8ceafaa6bbf1c24c60c42548e408d28381 [file] [log] [blame]
From 9b0b90a585e25b8688c1c492070bf101e894a3c5 Mon Sep 17 00:00:00 2001
From: Colin Ian King <>
Date: Thu, 19 Dec 2019 21:32:46 +0000
Subject: [PATCH] clocksource/drivers/bcm2835_timer: Fix memory leak of timer
commit 2052d032c06761330bca4944bb7858b00960e868 upstream.
Currently when setup_irq fails the error exit path will leak the
recently allocated timer structure. Originally the code would
throw a panic but a later commit changed the behaviour to return
via the err_iounmap path and hence we now have a memory leak. Fix
this by adding a err_timer_free error path that kfree's timer.
Addresses-Coverity: ("Resource Leak")
Fixes: 524a7f08983d ("clocksource/drivers/bcm2835_timer: Convert init function to return error")
Signed-off-by: Colin Ian King <>
Signed-off-by: Daniel Lezcano <>
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/clocksource/bcm2835_timer.c b/drivers/clocksource/bcm2835_timer.c
index 2b196cbfadb6..b235f446ee50 100644
--- a/drivers/clocksource/bcm2835_timer.c
+++ b/drivers/clocksource/bcm2835_timer.c
@@ -121,7 +121,7 @@ static int __init bcm2835_timer_init(struct device_node *node)
ret = setup_irq(irq, &timer->act);
if (ret) {
pr_err("Can't set up timer IRQ\n");
- goto err_iounmap;
+ goto err_timer_free;
clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff);
@@ -130,6 +130,9 @@ static int __init bcm2835_timer_init(struct device_node *node)
return 0;
+ kfree(timer);
return ret;