Skip to contentSkip to conversation

gpio/omap: fix possible memory leak in omap2_gpio_dev_init()

PATCH New Wei Yongjun 3 participants 4 messages Sep 3, 2012 – Sep 7, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpio/omap: fix possible memory leak in omap2_gpio_dev_init()

From: Wei Yongjun <[email protected]>

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/)

---
 arch/arm/mach-omap2/gpio.c | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-omap2/gpio.c +2 -0
index 9ad7d48..fe626e90 100644
@@ -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;
 	}
#1 lore raw

PATCH v2 1/1 gpio/omap: fix possible memory leak in omap2_gpio_dev_init()

Quoted 10 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

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/)

Tony, can you pick this one up for fixes?

Thanks,

Kevin

maintainer
#2 lore raw

PATCH v2 1/1 gpio/omap: fix possible memory leak in omap2_gpio_dev_init()

Quoted 8 lines · Kevin Hilman
Quoted 6 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

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.

Quoted 8 lines
Quoted 4 lines

spatch with a semantic match is used to found this problem.
(http://coccinelle.lip6.fr/)

Tony, can you pick this one up for fixes?

Sure, is fixes-noncritical OK for this one?

Tony

#3 lore raw

PATCH v2 1/1 gpio/omap: fix possible memory leak in omap2_gpio_dev_init()

Quoted 12 lines · Tony Lindgren
Quoted 11 lines · Kevin Hilman
Quoted 9 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

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/)

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Tony, can you pick this one up for fixes?

Sure, is fixes-noncritical OK for this one?

Yes.

Kevin