2019-06-17 11:32:56

by Colin King

[permalink] [raw]
Subject: [PATCH][next] clocksource: davinci-timer: fix memory leak of clockevent on error return

From: Colin Ian King <[email protected]>

Currently when the call to request_irq falls there is a memory leak of
clockevent on the error return path. Fix this by kfree'ing clockevent.

Addresses-Coverity: ("Resource leak")
Fixes: fe3b8194f274 ("clocksource: davinci-timer: add support for clockevents")
Signed-off-by: Colin Ian King <[email protected]>
---
drivers/clocksource/timer-davinci.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
index a9ca02390b66..8512f12e250a 100644
--- a/drivers/clocksource/timer-davinci.c
+++ b/drivers/clocksource/timer-davinci.c
@@ -300,6 +300,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;
}

--
2.20.1


2019-06-24 08:48:12

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH][next] clocksource: davinci-timer: fix memory leak of clockevent on error return

pon., 17 cze 2019 o 13:31 Colin King <[email protected]> napisał(a):
>
> From: Colin Ian King <[email protected]>
>
> Currently when the call to request_irq falls there is a memory leak of
> clockevent on the error return path. Fix this by kfree'ing clockevent.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: fe3b8194f274 ("clocksource: davinci-timer: add support for clockevents")
> Signed-off-by: Colin Ian King <[email protected]>
> ---
> drivers/clocksource/timer-davinci.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
> index a9ca02390b66..8512f12e250a 100644
> --- a/drivers/clocksource/timer-davinci.c
> +++ b/drivers/clocksource/timer-davinci.c
> @@ -300,6 +300,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;
> }
>
> --
> 2.20.1
>

Hi Colin,

I omitted the error checking in this driver on purpose - it doesn't
make sense as the system won't boot without a timer.

Bart

2019-06-24 09:06:28

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH][next] clocksource: davinci-timer: fix memory leak of clockevent on error return

On Mon, Jun 24, 2019 at 10:28:10AM +0200, Bartosz Golaszewski wrote:
> pon., 17 cze 2019 o 13:31 Colin King <[email protected]> napisał(a):
> >
> > From: Colin Ian King <[email protected]>
> >
> > Currently when the call to request_irq falls there is a memory leak of
> > clockevent on the error return path. Fix this by kfree'ing clockevent.
> >
> > Addresses-Coverity: ("Resource leak")
> > Fixes: fe3b8194f274 ("clocksource: davinci-timer: add support for clockevents")
> > Signed-off-by: Colin Ian King <[email protected]>
> > ---
> > drivers/clocksource/timer-davinci.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
> > index a9ca02390b66..8512f12e250a 100644
> > --- a/drivers/clocksource/timer-davinci.c
> > +++ b/drivers/clocksource/timer-davinci.c
> > @@ -300,6 +300,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;
> > }
> >
> > --
> > 2.20.1
> >
>
> Hi Colin,
>
> I omitted the error checking in this driver on purpose - it doesn't
> make sense as the system won't boot without a timer.

One way to silence these static checker warnings is to use
"GFP_KERNEL | __GFP_NOFAIL".

regards,
dan carpenter

2019-06-24 09:08:18

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH][next] clocksource: davinci-timer: fix memory leak of clockevent on error return

pon., 24 cze 2019 o 11:04 Dan Carpenter <[email protected]> napisał(a):
>
> On Mon, Jun 24, 2019 at 10:28:10AM +0200, Bartosz Golaszewski wrote:
> > pon., 17 cze 2019 o 13:31 Colin King <[email protected]> napisał(a):
> > >
> > > From: Colin Ian King <[email protected]>
> > >
> > > Currently when the call to request_irq falls there is a memory leak of
> > > clockevent on the error return path. Fix this by kfree'ing clockevent.
> > >
> > > Addresses-Coverity: ("Resource leak")
> > > Fixes: fe3b8194f274 ("clocksource: davinci-timer: add support for clockevents")
> > > Signed-off-by: Colin Ian King <[email protected]>
> > > ---
> > > drivers/clocksource/timer-davinci.c | 1 +
> > > 1 file changed, 1 insertion(+)
> > >
> > > diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
> > > index a9ca02390b66..8512f12e250a 100644
> > > --- a/drivers/clocksource/timer-davinci.c
> > > +++ b/drivers/clocksource/timer-davinci.c
> > > @@ -300,6 +300,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;
> > > }
> > >
> > > --
> > > 2.20.1
> > >
> >
> > Hi Colin,
> >
> > I omitted the error checking in this driver on purpose - it doesn't
> > make sense as the system won't boot without a timer.
>
> One way to silence these static checker warnings is to use
> "GFP_KERNEL | __GFP_NOFAIL".
>
> regards,
> dan carpenter
>

Noted, I'll be sending a new version of this driver to Daniel anyway,
so I'll include it.

Thanks,
Bart

2019-06-24 09:10:33

by Colin King

[permalink] [raw]
Subject: Re: [PATCH][next] clocksource: davinci-timer: fix memory leak of clockevent on error return

On 24/06/2019 10:03, Dan Carpenter wrote:
> On Mon, Jun 24, 2019 at 10:28:10AM +0200, Bartosz Golaszewski wrote:
>> pon., 17 cze 2019 o 13:31 Colin King <[email protected]> napisał(a):
>>>
>>> From: Colin Ian King <[email protected]>
>>>
>>> Currently when the call to request_irq falls there is a memory leak of
>>> clockevent on the error return path. Fix this by kfree'ing clockevent.
>>>
>>> Addresses-Coverity: ("Resource leak")
>>> Fixes: fe3b8194f274 ("clocksource: davinci-timer: add support for clockevents")
>>> Signed-off-by: Colin Ian King <[email protected]>
>>> ---
>>> drivers/clocksource/timer-davinci.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/clocksource/timer-davinci.c b/drivers/clocksource/timer-davinci.c
>>> index a9ca02390b66..8512f12e250a 100644
>>> --- a/drivers/clocksource/timer-davinci.c
>>> +++ b/drivers/clocksource/timer-davinci.c
>>> @@ -300,6 +300,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;
>>> }
>>>
>>> --
>>> 2.20.1
>>>
>>
>> Hi Colin,
>>
>> I omitted the error checking in this driver on purpose - it doesn't
>> make sense as the system won't boot without a timer.
>
> One way to silence these static checker warnings is to use
> "GFP_KERNEL | __GFP_NOFAIL".

/me notes that down to for future reference, thanks again Dan for your
wise input.

>
> regards,
> dan carpenter
>