From: Wei Yongjun Date: Mon, 3 Sep 2012 12:42:27 +0000 (+0800) Subject: gpio/omap: fix possible memory leak in omap2_gpio_dev_init() X-Git-Tag: upstream/snapshot3+hdmi~6583^2~4^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e40b1c1cc5ae9b949f96d40356afd2a31477365;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git gpio/omap: fix possible memory leak in omap2_gpio_dev_init() pdata and pdata->regs have been allocated in this function and should be freed before leaving it, and in the other error handling cases too. spatch with a semantic match is used to found this problem. (http://coccinelle.lip6.fr/) Signed-off-by: Wei Yongjun Acked-by: Kevin Hilman Signed-off-by: Tony Lindgren --- diff --git a/arch/arm/mach-omap2/gpio.c b/arch/arm/mach-omap2/gpio.c index 9ad7d48..fe626e90 100644 --- a/arch/arm/mach-omap2/gpio.c +++ b/arch/arm/mach-omap2/gpio.c @@ -60,6 +60,7 @@ static int __init omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused) pdata->regs = kzalloc(sizeof(struct omap_gpio_reg_offs), GFP_KERNEL); if (!pdata->regs) { pr_err("gpio%d: Memory allocation failed\n", id); + kfree(pdata); return -ENOMEM; } @@ -121,6 +122,7 @@ static int __init omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused) break; default: WARN(1, "Invalid gpio bank_type\n"); + kfree(pdata->regs); kfree(pdata); return -EINVAL; }