Patchwork 82xx: kmalloc failure ignored in ep8248e_mdio_probe()

login
register
mail settings
Submitter roel kluin
Date Sept. 9, 2009, 2:49 p.m.
Message ID <4AA7C095.7090009@gmail.com>
Download mbox | patch
Permalink /patch/33179/
State Accepted, archived
Delegated to: Kumar Gala
Headers show

Comments

roel kluin - Sept. 9, 2009, 2:49 p.m.
Prevent NULL dereference if kmalloc() fails. Also clean up if
of_mdiobus_register() returns an error.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Found with sed: http://kernelnewbies.org/roelkluin

Please review.
Scott Wood - Sept. 9, 2009, 6:46 p.m.
On Wed, Sep 09, 2009 at 04:49:57PM +0200, Roel Kluin wrote:
> Prevent NULL dereference if kmalloc() fails. Also clean up if
> of_mdiobus_register() returns an error.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>

Acked-by: Scott Wood <scottwood@freescale.com>

-Scott
Kumar Gala - Sept. 24, 2009, 6:19 p.m.
On Sep 9, 2009, at 7:49 AM, Roel Kluin wrote:

> Prevent NULL dereference if kmalloc() fails. Also clean up if
> of_mdiobus_register() returns an error.
>
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> Found with sed: http://kernelnewbies.org/roelkluin
>
> Please review.

applied to merge

- k

Patch

diff --git a/arch/powerpc/platforms/82xx/ep8248e.c b/arch/powerpc/platforms/82xx/ep8248e.c
index 51fcae4..f9aee18 100644
--- a/arch/powerpc/platforms/82xx/ep8248e.c
+++ b/arch/powerpc/platforms/82xx/ep8248e.c
@@ -132,12 +132,25 @@  static int __devinit ep8248e_mdio_probe(struct of_device *ofdev,
 		return -ENOMEM;
 
 	bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
+	if (bus->irq == NULL) {
+		ret = -ENOMEM;
+		goto err_free_bus;
+	}
 
 	bus->name = "ep8248e-mdio-bitbang";
 	bus->parent = &ofdev->dev;
 	snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
 
-	return of_mdiobus_register(bus, ofdev->node);
+	ret = of_mdiobus_register(bus, ofdev->node);
+	if (ret)
+		goto err_free_irq;
+
+	return 0;
+err_free_irq:
+	kfree(bus->irq);
+err_free_bus:
+	free_mdio_bitbang(bus);
+	return ret;
 }
 
 static int ep8248e_mdio_remove(struct of_device *ofdev)