Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clocksource/drivers/bcm2835_timer: Fix memory leak of timer

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 <colin.king@canonical.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20191219213246.34437-1-colin.king@canonical.com

authored by

Colin Ian King and committed by
Daniel Lezcano
2052d032 f5ac896b

+4 -1
+4 -1
drivers/clocksource/bcm2835_timer.c
··· 121 121 ret = setup_irq(irq, &timer->act); 122 122 if (ret) { 123 123 pr_err("Can't set up timer IRQ\n"); 124 - goto err_iounmap; 124 + goto err_timer_free; 125 125 } 126 126 127 127 clockevents_config_and_register(&timer->evt, freq, 0xf, 0xffffffff); ··· 129 129 pr_info("bcm2835: system timer (irq = %d)\n", irq); 130 130 131 131 return 0; 132 + 133 + err_timer_free: 134 + kfree(timer); 132 135 133 136 err_iounmap: 134 137 iounmap(base);