Skip to content

Commit

Permalink
clocksource/drivers/timer-imx-gpt: Fix potential memory leak
Browse files Browse the repository at this point in the history
[ Upstream commit 8051a99 ]

Fix coverity Issue CID 250382:  Resource leak (RESOURCE_LEAK).
Add kfree when error return.

Signed-off-by: Jacky Bai <ping.bai@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20231009083922.1942971-1-ping.bai@nxp.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
JackyBai authored and gregkh committed Nov 28, 2023
1 parent 9f4c391 commit ff8370a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions drivers/clocksource/timer-imx-gpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,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)
return -ENXIO;
if (!imxtm->base) {
ret = -ENXIO;
goto err_kfree;
}

imxtm->irq = irq_of_parse_and_map(np, 0);
if (imxtm->irq <= 0)
return -EINVAL;
if (imxtm->irq <= 0) {
ret = -EINVAL;
goto err_kfree;
}

imxtm->clk_ipg = of_clk_get_by_name(np, "ipg");

Expand All @@ -472,11 +476,15 @@ static int __init mxc_timer_init_dt(struct device_node *np, enum imx_gpt_type t

ret = _mxc_timer_init(imxtm);
if (ret)
return ret;
goto err_kfree;

initialized = 1;

return 0;

err_kfree:
kfree(imxtm);
return ret;
}

static int __init imx1_timer_init_dt(struct device_node *np)
Expand Down

0 comments on commit ff8370a

Please sign in to comment.