Patchwork gianfar: Free/iounmap memory after an error in mii bus initialization

login
register
mail settings
Submitter Andy Fleming
Date Sept. 18, 2008, 9:37 p.m.
Message ID <1221773874-3273-1-git-send-email-afleming@freescale.com>
Download mbox | patch
Permalink /patch/554/
State Accepted
Delegated to: Jeff Garzik
Headers show

Comments

Andy Fleming - Sept. 18, 2008, 9:37 p.m.
Recent changes to MII bus initialization code added exit points which
didn't free or iounmap the bus before returning.

This was reported as bug #11372

Signed-off-by: Andy Fleming <afleming@freescale.com>
Andrew Morton - Sept. 20, 2008, 12:24 a.m.
On Thu, 18 Sep 2008 16:37:54 -0500
Andy Fleming <afleming@freescale.com> wrote:

> Recent changes to MII bus initialization code added exit points which
> didn't free or iounmap the bus before returning.
> 
> This was reported as bug #11372
> 
> Signed-off-by: Andy Fleming <afleming@freescale.com>

administrivia:

- Adding a

	Reported-by: Daniel Marjamki <danielm77@spray.se>

  would be nice.

- When referencing a bugzilla report in the changelog I like to use
  the full URL.  Because there are people who periodically troll the
  mainline commits closing off bugzilla reports.  Using the full
  URL minimises the chance that they will miss something.

Patch

diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c
index ebcfb27..4804ec1 100644
--- a/drivers/net/gianfar_mii.c
+++ b/drivers/net/gianfar_mii.c
@@ -211,19 +211,21 @@  static int gfar_mdio_probe(struct device *dev)
 	gfar_write(&enet_regs->tbipa, 0);
 	for (i = PHY_MAX_ADDR; i > 0; i--) {
 		u32 phy_id;
-		int r;
 
-		r = get_phy_id(new_bus, i, &phy_id);
-		if (r)
-			return r;
+		err = get_phy_id(new_bus, i, &phy_id);
+		if (err)
+			goto bus_register_fail;
 
 		if (phy_id == 0xffffffff)
 			break;
 	}
 
 	/* The bus is full.  We don't support using 31 PHYs, sorry */
-	if (i == 0)
-		return -EBUSY;
+	if (i == 0) {
+		err = -EBUSY;
+
+		goto bus_register_fail;
+	}
 
 	gfar_write(&enet_regs->tbipa, i);