From baac03d9bb7b8aa3c33a2dbf5f459ea6ce8abaf4 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 22 Sep 2008 10:03:56 -0700 Subject: gianfar: Fix error in mdio reset timeout The loop with the timeout used "while (... && timeout--)", which means than when the timeout occurs, "timeout" will be -1 after the loop has exited. The code that checks if the looped exited because of a timeout used "if (timeout <= 0)". Seems ok, except timeout is unsigned, and (unsigned)-1 isn't less than zero! Using "--timeout" in the loop fixes this problem, as now "timeout" will be 0 when the loop times out. This also fixes a bug in the existing code, where it will erroneously think a timeout occurred if the condition the loop was waiting for is satisfied on the final iteration before a timeout. Signed-off-by: Trent Piepho Acked-by: Andy Fleming Signed-off-by: Jeff Garzik --- drivers/net/gianfar_mii.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/net/gianfar_mii.c') diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c index ebcfb27a904..906aba2757e 100644 --- a/drivers/net/gianfar_mii.c +++ b/drivers/net/gianfar_mii.c @@ -136,12 +136,12 @@ static int gfar_mdio_reset(struct mii_bus *bus) /* Wait until the bus is free */ while ((gfar_read(®s->miimind) & MIIMIND_BUSY) && - timeout--) + --timeout) cpu_relax(); mutex_unlock(&bus->mdio_lock); - if(timeout <= 0) { + if(timeout == 0) { printk(KERN_ERR "%s: The MII Bus is stuck!\n", bus->name); return -EBUSY; -- cgit v1.2.3 From ac7198bb124e7007cfd48990d382678341886dba Mon Sep 17 00:00:00 2001 From: Andy Fleming Date: Mon, 22 Sep 2008 14:10:25 -0700 Subject: gianfar: free/iounmap memory after an error in mii bus initialization Recent changes to MII bus initialization code added exit points which didn't free or iounmap the bus before returning. Addresses http://bugzilla.kernel.org/show_bug.cgi?id=11372. Signed-off-by: Andy Fleming Reported-by: Daniel Marjamki Cc: Jeff Garzik Signed-off-by: Andrew Morton Signed-off-by: Jeff Garzik --- drivers/net/gianfar_mii.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'drivers/net/gianfar_mii.c') diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c index 906aba2757e..678f48c6911 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); -- cgit v1.2.3 From 18ee49ddb0d242ed1d0e273038d5e4f6de7379d3 Mon Sep 17 00:00:00 2001 From: Lennert Buytenhek Date: Wed, 1 Oct 2008 15:41:33 +0000 Subject: phylib: rename mii_bus::dev to mii_bus::parent In preparation of giving mii_bus objects a device tree presence of their own, rename struct mii_bus's ->dev argument to ->parent, since having a 'struct device *dev' that points to our parent device conflicts with introducing a 'struct device dev' representing our own device. Signed-off-by: Lennert Buytenhek Signed-off-by: David S. Miller Acked-by: Andy Fleming --- drivers/net/gianfar_mii.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net/gianfar_mii.c') diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c index 678f48c6911..38895b0e376 100644 --- a/drivers/net/gianfar_mii.c +++ b/drivers/net/gianfar_mii.c @@ -196,7 +196,7 @@ static int gfar_mdio_probe(struct device *dev) new_bus->irq = pdata->irq; - new_bus->dev = dev; + new_bus->parent = dev; dev_set_drvdata(dev, new_bus); /* -- cgit v1.2.3 From 298cf9beb9679522de995e249eccbd82f7c51999 Mon Sep 17 00:00:00 2001 From: Lennert Buytenhek Date: Wed, 8 Oct 2008 16:29:57 -0700 Subject: phylib: move to dynamic allocation of struct mii_bus This patch introduces mdiobus_alloc() and mdiobus_free(), and makes all mdio bus drivers use these functions to allocate their struct mii_bus'es dynamically. Signed-off-by: Lennert Buytenhek Signed-off-by: David S. Miller Acked-by: Andy Fleming --- drivers/net/gianfar_mii.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers/net/gianfar_mii.c') diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c index 38895b0e376..bf73eea9801 100644 --- a/drivers/net/gianfar_mii.c +++ b/drivers/net/gianfar_mii.c @@ -164,8 +164,7 @@ static int gfar_mdio_probe(struct device *dev) if (NULL == dev) return -EINVAL; - new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); - + new_bus = mdiobus_alloc(); if (NULL == new_bus) return -ENOMEM; @@ -242,7 +241,7 @@ static int gfar_mdio_probe(struct device *dev) bus_register_fail: iounmap(regs); reg_map_fail: - kfree(new_bus); + mdiobus_free(new_bus); return err; } @@ -258,7 +257,7 @@ static int gfar_mdio_remove(struct device *dev) iounmap((void __iomem *)bus->priv); bus->priv = NULL; - kfree(bus); + mdiobus_free(bus); return 0; } -- cgit v1.2.3