Skip to contentSkip to conversation

clocksource/drivers/davinci: Fix memory leak in davinci_timer_register

PATCH Superseded Navid Emamdoost 3 participants 3 messages Oct 21, 2019 – Oct 22, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clocksource/drivers/davinci: Fix memory leak in davinci_timer_register

In the impelementation of davinci_timer_register() the allocated memory for clockevent should be released if request_irq() fails.

Fixes 721154f972aa ("clocksource/drivers/davinci: Add support for clockevents")
---
 drivers/clocksource/timer-davinci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-davinci.c +1 -0
index 62745c962049..910d4d2f0d64 100644
@@ -299,6 +299,7 @@ int __init davinci_timer_register(struct clk *clk,
 			 "clockevent/tim12", clockevent);
 	if (rv) {
 		pr_err("Unable to request the clockevent interrupt");
+		kfree(clockevent);
 		return rv;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines

In the impelementation of davinci_timer_register() the allocated memory for clockevent should be released if request_irq() fails.

* Please avoid the copying of typos from previous change descriptions.

* Under which circumstances will an “imperative mood” matter for you here?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=7d194c2100ad2a6dded545887d02754948ca5241#n151

drivers/clocksource/timer-davinci.c int __init davinci_timer_register(struct clk *clk, · line 304

Quoted 8 lines

+++ b/drivers/clocksource/timer-davinci.c

drivers/clocksource/timer-davinci.c +1 -0
@@ -299,6 +299,7 @@ int __init davinci_timer_register(struct clk *clk,
 			 "clockevent/tim12", clockevent);
 	if (rv) {
 		pr_err("Unable to request the clockevent interrupt");
+		kfree(clockevent);
 		return rv;
 	}

* Should a complete source code analysis point out that a similar fix will be needed also in the if branch after a failed call of the function “clocksource_register_hz”?

* Can any more exception handling become relevant because of previous resource allocations in this function implementation?

Regards,
Markus

#2 lore raw
In reply to Navid Emamdoost

pon., 21 paź 2019 o 22:26 Navid Emamdoost <[email protected]> napisał(a):

Quoted 23 lines

In the impelementation of davinci_timer_register() the allocated memory for clockevent should be released if request_irq() fails.

Fixes 721154f972aa ("clocksource/drivers/davinci: Add support for clockevents")
---
 drivers/clocksource/timer-davinci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-davinci.c +1 -1
index 62745c962049..910d4d2f0d64 100644
@@ -299,6 +299,7 @@ int __init davinci_timer_register(struct clk *clk,
                         "clockevent/tim12", clockevent);
        if (rv) {
                pr_err("Unable to request the clockevent interrupt");
+               kfree(clockevent);
                return rv;
        }
 
--
Quoted 2 lines

2.17.1

Any failure in this driver means the system is fried. I explicitly didn't bother freeing any resources. Nack.

Bart