Skip to contentSkip to conversation

gianfar: Fix error in mdio reset timeout

PATCH Applied Trent Piepho 2 participants 2 messages Sep 22, 2008 – Sep 25, 2008

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

PATCH 1/1 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.

---
 drivers/net/gianfar_mii.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/gianfar_mii.c +2 -2
index ebcfb27..906aba2 100644
@@ -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;
Signature · 1 line
1.5.4.1
Applied
#1 lore raw
Quoted 26 lines · Trent Piepho

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.

---
 drivers/net/gianfar_mii.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/gianfar_mii.c +0 -0
index ebcfb27..906aba2 100644
@@ -136,12 +136,12 @@ static int gfar_mdio_reset(struct mii_bus *bus)
 
 	/* Wait until the bus is free */

drivers/net/gianfar_mii.c static int gfar_mdio_reset(struct mii_bus *bus) · line 145

Quoted 10 lines
drivers/net/gianfar_mii.c +2 -2
 	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",

applied