* [PATCH v1] clocksource/timer-atmel-pit:- Fix resource leaks in error paths.
@ 2017-05-05 12:51 Arvind Yadav
2017-05-18 9:26 ` Alexandre Belloni
0 siblings, 1 reply; 4+ messages in thread
From: Arvind Yadav @ 2017-05-05 12:51 UTC (permalink / raw)
To: nicolas.ferre, tglx, daniel.lezcano; +Cc: linux-kernel
Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
drivers/clocksource/timer-atmel-pit.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index c0b5df3..28b0cd3 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -180,26 +180,29 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
data->base = of_iomap(node, 0);
if (!data->base) {
pr_err("Could not map PIT address\n");
- return -ENXIO;
+ ret = -ENXIO;
+ goto error_free;
}
data->mck = of_clk_get(node, 0);
if (IS_ERR(data->mck)) {
pr_err("Unable to get mck clk\n");
- return PTR_ERR(data->mck);
+ ret = PTR_ERR(data->mck);
+ goto error_iounmap;
}
ret = clk_prepare_enable(data->mck);
if (ret) {
pr_err("Unable to enable mck\n");
- return ret;
+ goto error_clk_put;
}
/* Get the interrupts property */
data->irq = irq_of_parse_and_map(node, 0);
if (!data->irq) {
pr_err("Unable to get IRQ from DT\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto error_clk_disable;
}
/*
@@ -223,11 +226,11 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
data->clksrc.rating = 175;
data->clksrc.read = read_pit_clk;
data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
-
+
ret = clocksource_register_hz(&data->clksrc, pit_rate);
if (ret) {
pr_err("Failed to register clocksource");
- return ret;
+ goto error_clk_disable;
}
/* Set up irq handler */
@@ -236,7 +239,7 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
"at91_tick", data);
if (ret) {
pr_err("Unable to setup IRQ\n");
- return ret;
+ goto error_unregister_clk;
}
/* Set up and register clockevents */
@@ -254,6 +257,19 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
clockevents_register_device(&data->clkevt);
return 0;
+
+error_unregister_clk:
+ clocksource_unregister(&data->clksrc);
+error_clk_disable:
+ clk_disable_unprepare(data->mck);
+error_clk_put:
+ clk_put(data->mck);
+error_iounmap:
+ iounmap(data->base);
+error_free:
+ kfree(data);
+
+ return ret;
}
CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
at91sam926x_pit_dt_init);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v1] clocksource/timer-atmel-pit:- Fix resource leaks in error paths.
2017-05-05 12:51 [PATCH v1] clocksource/timer-atmel-pit:- Fix resource leaks in error paths Arvind Yadav
@ 2017-05-18 9:26 ` Alexandre Belloni
2017-05-18 10:33 ` Arvind Yadav
0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Belloni @ 2017-05-18 9:26 UTC (permalink / raw)
To: Arvind Yadav; +Cc: nicolas.ferre, tglx, daniel.lezcano, linux-kernel
Hi,
This needs a proper commit message. Also, can you tell us on which SoC
you tested your changes?
On 05/05/2017 at 18:21:48 +0530, Arvind Yadav wrote:
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> ---
> drivers/clocksource/timer-atmel-pit.c | 30 +++++++++++++++++++++++-------
> 1 file changed, 23 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
> index c0b5df3..28b0cd3 100644
> --- a/drivers/clocksource/timer-atmel-pit.c
> +++ b/drivers/clocksource/timer-atmel-pit.c
> @@ -180,26 +180,29 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> data->base = of_iomap(node, 0);
> if (!data->base) {
> pr_err("Could not map PIT address\n");
> - return -ENXIO;
> + ret = -ENXIO;
> + goto error_free;
> }
>
> data->mck = of_clk_get(node, 0);
> if (IS_ERR(data->mck)) {
> pr_err("Unable to get mck clk\n");
> - return PTR_ERR(data->mck);
> + ret = PTR_ERR(data->mck);
> + goto error_iounmap;
> }
>
> ret = clk_prepare_enable(data->mck);
> if (ret) {
> pr_err("Unable to enable mck\n");
> - return ret;
> + goto error_clk_put;
> }
>
> /* Get the interrupts property */
> data->irq = irq_of_parse_and_map(node, 0);
> if (!data->irq) {
> pr_err("Unable to get IRQ from DT\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto error_clk_disable;
> }
>
> /*
> @@ -223,11 +226,11 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> data->clksrc.rating = 175;
> data->clksrc.read = read_pit_clk;
> data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
> -
> +
> ret = clocksource_register_hz(&data->clksrc, pit_rate);
> if (ret) {
> pr_err("Failed to register clocksource");
> - return ret;
> + goto error_clk_disable;
> }
>
> /* Set up irq handler */
> @@ -236,7 +239,7 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> "at91_tick", data);
> if (ret) {
> pr_err("Unable to setup IRQ\n");
> - return ret;
> + goto error_unregister_clk;
> }
>
> /* Set up and register clockevents */
> @@ -254,6 +257,19 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> clockevents_register_device(&data->clkevt);
>
> return 0;
> +
> +error_unregister_clk:
> + clocksource_unregister(&data->clksrc);
> +error_clk_disable:
> + clk_disable_unprepare(data->mck);
> +error_clk_put:
> + clk_put(data->mck);
> +error_iounmap:
> + iounmap(data->base);
> +error_free:
> + kfree(data);
> +
> + return ret;
> }
> CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
> at91sam926x_pit_dt_init);
> --
> 1.9.1
>
>
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] clocksource/timer-atmel-pit:- Fix resource leaks in error paths.
2017-05-18 9:26 ` Alexandre Belloni
@ 2017-05-18 10:33 ` Arvind Yadav
2017-05-18 11:38 ` Alexandre Belloni
0 siblings, 1 reply; 4+ messages in thread
From: Arvind Yadav @ 2017-05-18 10:33 UTC (permalink / raw)
To: Alexandre Belloni; +Cc: nicolas.ferre, tglx, daniel.lezcano, linux-kernel
Hi,
Yes i have tested on board SBC6045 with Atmel SoC.
Commit message " Handle return error in at91sam926x_pit_dt_init.
at91sam926x_pit_dt_init can fail here. We must have released memory
and clock "
is this fine?
Regards
-Arvind
On Thursday 18 May 2017 02:56 PM, Alexandre Belloni wrote:
> Hi,
>
> This needs a proper commit message. Also, can you tell us on which SoC
> you tested your changes?
>
> On 05/05/2017 at 18:21:48 +0530, Arvind Yadav wrote:
>> Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
>> ---
>> drivers/clocksource/timer-atmel-pit.c | 30 +++++++++++++++++++++++-------
>> 1 file changed, 23 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
>> index c0b5df3..28b0cd3 100644
>> --- a/drivers/clocksource/timer-atmel-pit.c
>> +++ b/drivers/clocksource/timer-atmel-pit.c
>> @@ -180,26 +180,29 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
>> data->base = of_iomap(node, 0);
>> if (!data->base) {
>> pr_err("Could not map PIT address\n");
>> - return -ENXIO;
>> + ret = -ENXIO;
>> + goto error_free;
>> }
>>
>> data->mck = of_clk_get(node, 0);
>> if (IS_ERR(data->mck)) {
>> pr_err("Unable to get mck clk\n");
>> - return PTR_ERR(data->mck);
>> + ret = PTR_ERR(data->mck);
>> + goto error_iounmap;
>> }
>>
>> ret = clk_prepare_enable(data->mck);
>> if (ret) {
>> pr_err("Unable to enable mck\n");
>> - return ret;
>> + goto error_clk_put;
>> }
>>
>> /* Get the interrupts property */
>> data->irq = irq_of_parse_and_map(node, 0);
>> if (!data->irq) {
>> pr_err("Unable to get IRQ from DT\n");
>> - return -EINVAL;
>> + ret = -EINVAL;
>> + goto error_clk_disable;
>> }
>>
>> /*
>> @@ -223,11 +226,11 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
>> data->clksrc.rating = 175;
>> data->clksrc.read = read_pit_clk;
>> data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
>> -
>> +
>> ret = clocksource_register_hz(&data->clksrc, pit_rate);
>> if (ret) {
>> pr_err("Failed to register clocksource");
>> - return ret;
>> + goto error_clk_disable;
>> }
>>
>> /* Set up irq handler */
>> @@ -236,7 +239,7 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
>> "at91_tick", data);
>> if (ret) {
>> pr_err("Unable to setup IRQ\n");
>> - return ret;
>> + goto error_unregister_clk;
>> }
>>
>> /* Set up and register clockevents */
>> @@ -254,6 +257,19 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
>> clockevents_register_device(&data->clkevt);
>>
>> return 0;
>> +
>> +error_unregister_clk:
>> + clocksource_unregister(&data->clksrc);
>> +error_clk_disable:
>> + clk_disable_unprepare(data->mck);
>> +error_clk_put:
>> + clk_put(data->mck);
>> +error_iounmap:
>> + iounmap(data->base);
>> +error_free:
>> + kfree(data);
>> +
>> + return ret;
>> }
>> CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
>> at91sam926x_pit_dt_init);
>> --
>> 1.9.1
>>
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1] clocksource/timer-atmel-pit:- Fix resource leaks in error paths.
2017-05-18 10:33 ` Arvind Yadav
@ 2017-05-18 11:38 ` Alexandre Belloni
0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2017-05-18 11:38 UTC (permalink / raw)
To: Arvind Yadav; +Cc: nicolas.ferre, tglx, daniel.lezcano, linux-kernel
On 18/05/2017 at 16:03:48 +0530, Arvind Yadav wrote:
> Hi,
> Yes i have tested on board SBC6045 with Atmel SoC.
>
Ok, thanks.
> Commit message " Handle return error in at91sam926x_pit_dt_init.
> at91sam926x_pit_dt_init can fail here. We must have released memory
> and clock "
>
> is this fine?
>
Sure.
My point is that currently, if any of it fails, your board will not boot
anyway ;).
> Regards
> -Arvind
>
> On Thursday 18 May 2017 02:56 PM, Alexandre Belloni wrote:
> > Hi,
> >
> > This needs a proper commit message. Also, can you tell us on which SoC
> > you tested your changes?
> >
> > On 05/05/2017 at 18:21:48 +0530, Arvind Yadav wrote:
> > > Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
> > > ---
> > > drivers/clocksource/timer-atmel-pit.c | 30 +++++++++++++++++++++++-------
> > > 1 file changed, 23 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
> > > index c0b5df3..28b0cd3 100644
> > > --- a/drivers/clocksource/timer-atmel-pit.c
> > > +++ b/drivers/clocksource/timer-atmel-pit.c
> > > @@ -180,26 +180,29 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> > > data->base = of_iomap(node, 0);
> > > if (!data->base) {
> > > pr_err("Could not map PIT address\n");
> > > - return -ENXIO;
> > > + ret = -ENXIO;
> > > + goto error_free;
> > > }
> > > data->mck = of_clk_get(node, 0);
> > > if (IS_ERR(data->mck)) {
> > > pr_err("Unable to get mck clk\n");
> > > - return PTR_ERR(data->mck);
> > > + ret = PTR_ERR(data->mck);
> > > + goto error_iounmap;
> > > }
> > > ret = clk_prepare_enable(data->mck);
> > > if (ret) {
> > > pr_err("Unable to enable mck\n");
> > > - return ret;
> > > + goto error_clk_put;
> > > }
> > > /* Get the interrupts property */
> > > data->irq = irq_of_parse_and_map(node, 0);
> > > if (!data->irq) {
> > > pr_err("Unable to get IRQ from DT\n");
> > > - return -EINVAL;
> > > + ret = -EINVAL;
> > > + goto error_clk_disable;
> > > }
> > > /*
> > > @@ -223,11 +226,11 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> > > data->clksrc.rating = 175;
> > > data->clksrc.read = read_pit_clk;
> > > data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
> > > -
> > > +
> > > ret = clocksource_register_hz(&data->clksrc, pit_rate);
> > > if (ret) {
> > > pr_err("Failed to register clocksource");
> > > - return ret;
> > > + goto error_clk_disable;
> > > }
> > > /* Set up irq handler */
> > > @@ -236,7 +239,7 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> > > "at91_tick", data);
> > > if (ret) {
> > > pr_err("Unable to setup IRQ\n");
> > > - return ret;
> > > + goto error_unregister_clk;
> > > }
> > > /* Set up and register clockevents */
> > > @@ -254,6 +257,19 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
> > > clockevents_register_device(&data->clkevt);
> > > return 0;
> > > +
> > > +error_unregister_clk:
> > > + clocksource_unregister(&data->clksrc);
> > > +error_clk_disable:
> > > + clk_disable_unprepare(data->mck);
> > > +error_clk_put:
> > > + clk_put(data->mck);
> > > +error_iounmap:
> > > + iounmap(data->base);
> > > +error_free:
> > > + kfree(data);
> > > +
> > > + return ret;
> > > }
> > > CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
> > > at91sam926x_pit_dt_init);
> > > --
> > > 1.9.1
> > >
> > >
>
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-05-18 11:38 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-05 12:51 [PATCH v1] clocksource/timer-atmel-pit:- Fix resource leaks in error paths Arvind Yadav
2017-05-18 9:26 ` Alexandre Belloni
2017-05-18 10:33 ` Arvind Yadav
2017-05-18 11:38 ` Alexandre Belloni
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.