lkml.org 
[lkml]   [2018]   [Nov]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH V2 2/2] clocksource: imx-gpt: add necessary kfree to avoid resource leak
    From
    Date

    Hi Anson,

    On 06/11/2018 02:38, Anson Huang wrote:
    > Hi, Daniel
    >
    > Best Regards!
    > Anson Huang
    >
    >> -----Original Message-----
    >> From: Daniel Lezcano [mailto:daniel.lezcano@linaro.org]
    >> Sent: 2018年11月5日 21:35
    >> To: Anson Huang <anson.huang@nxp.com>; tglx@linutronix.de;
    >> linux-kernel@vger.kernel.org
    >> Cc: dl-linux-imx <linux-imx@nxp.com>
    >> 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@nxp.com>
    >>> ---
    >>> 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.

    Actually I was unclear. The patch is duplicating the kfree in the error
    path, usually a rollback routine should be provided.

    So instead of creating this rollback path, you can directly use the
    timer-of which contains the error check and rollback.



    --
    <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

    Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
    <http://twitter.com/#!/linaroorg> Twitter |
    <http://www.linaro.org/linaro-blog/> Blog

    \
     
     \ /
      Last update: 2018-11-06 10:06    [W:3.867 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site