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 <yongjun_wei@trendmicro.com.cn> Acked-by: Kevin Hilman <khilman@ti.com> Signed-off-by: Tony Lindgren <tony@atomide.com>
This commit is contained in:
parent
55d512e245
commit
5e40b1c1cc
1 changed files with 2 additions and 0 deletions
|
@ -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);
|
pdata->regs = kzalloc(sizeof(struct omap_gpio_reg_offs), GFP_KERNEL);
|
||||||
if (!pdata->regs) {
|
if (!pdata->regs) {
|
||||||
pr_err("gpio%d: Memory allocation failed\n", id);
|
pr_err("gpio%d: Memory allocation failed\n", id);
|
||||||
|
kfree(pdata);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +122,7 @@ static int __init omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused)
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
WARN(1, "Invalid gpio bank_type\n");
|
WARN(1, "Invalid gpio bank_type\n");
|
||||||
|
kfree(pdata->regs);
|
||||||
kfree(pdata);
|
kfree(pdata);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue