]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
gianfar: Fix error in mdio reset timeout
authorTrent Piepho <tpiepho@freescale.com>
Mon, 22 Sep 2008 17:03:56 +0000 (10:03 -0700)
committerJeff Garzik <jgarzik@redhat.com>
Thu, 25 Sep 2008 00:48:56 +0000 (20:48 -0400)
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 <tpiepho@freescale.com>
Acked-by: Andy Fleming <afleming@freescale.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
drivers/net/gianfar_mii.c

index ebcfb27a904eae72e7ca5ae5ee869acf5969496e..906aba2757e79b114fcc597ba1985305596d712c 100644 (file)
@@ -136,12 +136,12 @@ static int gfar_mdio_reset(struct mii_bus *bus)
 
        /* Wait until the bus is free */
        while ((gfar_read(&regs->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;