]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
gpio/omap: fix possible memory leak in omap2_gpio_dev_init()
authorWei Yongjun <yongjun_wei@trendmicro.com.cn>
Mon, 3 Sep 2012 12:42:27 +0000 (20:42 +0800)
committerTony Lindgren <tony@atomide.com>
Mon, 10 Sep 2012 18:48:30 +0000 (11:48 -0700)
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 <yongjun_wei@trendmicro.com.cn>
Acked-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
arch/arm/mach-omap2/gpio.c

index 9ad7d489b0deb8d2166b0288450fdba087dc450b..fe626e903deaa3683ff8cef9b328484ef8dbfb5a 100644 (file)
@@ -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;
        }