RE: [PATCH V2 2/2] clocksource: imx-gpt: add necessary kfree to avoid resource leak

From: Anson Huang
Date: Mon Nov 05 2018 - 20:38:56 EST


Hi, Daniel

Best Regards!
Anson Huang

> -----Original Message-----
> From: Daniel Lezcano [mailto:daniel.lezcano@xxxxxxxxxx]
> Sent: 2018å11æ5æ 21:35
> To: Anson Huang <anson.huang@xxxxxxx>; tglx@xxxxxxxxxxxxx;
> linux-kernel@xxxxxxxxxxxxxxx
> Cc: dl-linux-imx <linux-imx@xxxxxxx>
> Subject: Re: [PATCH V2 2/2] clocksource: imx-gpt: add necessary kfree to avoid
> resource leak
>
> Hi Anson,
>
> On 05/11/2018 02:10, Anson Huang wrote:
> > kfree should be called to free resource in error path before return.
> >
> > Signed-off-by: Anson Huang <Anson.Huang@xxxxxxx>
> > ---
> > drivers/clocksource/timer-imx-gpt.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/clocksource/timer-imx-gpt.c
> > b/drivers/clocksource/timer-imx-gpt.c
> > index a3d6ccb..0f78b30 100644
> > --- a/drivers/clocksource/timer-imx-gpt.c
> > +++ b/drivers/clocksource/timer-imx-gpt.c
> > @@ -477,12 +477,16 @@ static int __init mxc_timer_init_dt(struct
> device_node *np, enum imx_gpt_type t
> > return -ENOMEM;
> >
> > imxtm->base = of_iomap(np, 0);
> > - if (!imxtm->base)
> > + if (!imxtm->base) {
> > + kfree(imxtm);
> > return -ENXIO;
> > + }
> >
> > imxtm->irq = irq_of_parse_and_map(np, 0);
> > - if (imxtm->irq <= 0)
> > + if (imxtm->irq <= 0) {
> > + kfree(imxtm);
> > return -EINVAL;
> > + }
> >
> > imxtm->clk_ipg = of_clk_get_by_name(np, "ipg");
>
> Please convert to timer-of API.

This patch mainly to fix the potential resource leak issue, for converting
to timer-of API, should I add another patch for it? Since it is a different
subject.

Thanks.

Anson

>
> Thanks
>
> -- Daniel
>
>
> --
>
> <https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww
> .linaro.org%2F&amp;data=02%7C01%7Canson.huang%40nxp.com%7Cb389e6
> 71eafb4400148208d643237383%7C686ea1d3bc2b4c6fa92cd99c5c301635%
> 7C0%7C0%7C636770216874548293&amp;sdata=toynTer%2Bq7DLRizwW7JKY
> qCrA8WQHeDmJRwLjXUu6XY%3D&amp;reserved=0> Linaro.org â Open source
> software for ARM SoCs
>
> Follow Linaro:
> <https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww
> .facebook.com%2Fpages%2FLinaro&amp;data=02%7C01%7Canson.huang%40
> nxp.com%7Cb389e671eafb4400148208d643237383%7C686ea1d3bc2b4c6fa
> 92cd99c5c301635%7C0%7C0%7C636770216874548293&amp;sdata=JJOClhL
> pER5JMuXHs65fJD%2FPC18%2FJBCyiRw3d41ei48%3D&amp;reserved=0>
> Facebook |
> <https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Ftwitt
> er.com%2F%23!%2Flinaroorg&amp;data=02%7C01%7Canson.huang%40nxp.c
> om%7Cb389e671eafb4400148208d643237383%7C686ea1d3bc2b4c6fa92cd
> 99c5c301635%7C0%7C0%7C636770216874548293&amp;sdata=W1QXRwgXt
> e3wbbjETuDinUniIDeA8THW%2Bsz6SSPWl30%3D&amp;reserved=0> Twitter |
> <https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww
> .linaro.org%2Flinaro-blog%2F&amp;data=02%7C01%7Canson.huang%40nxp.c
> om%7Cb389e671eafb4400148208d643237383%7C686ea1d3bc2b4c6fa92cd
> 99c5c301635%7C0%7C0%7C636770216874548293&amp;sdata=9JdVMOpdiI
> HdxVrFbiDgblAunod9RYkzwYRaHcsgzUo%3D&amp;reserved=0> Blog