From: Trent Piepho Subject: [PATCH] gianfar: Fix error in mdio reset timeout Date: Mon, 22 Sep 2008 10:03:56 -0700 Message-ID: <1222103036-27770-1-git-send-email-tpiepho@freescale.com> Cc: Trent Piepho To: netdev@vger.kernel.org Return-path: Received: from az33egw01.freescale.net ([192.88.158.102]:58593 "EHLO az33egw01.freescale.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751227AbYIVRFK (ORCPT ); Mon, 22 Sep 2008 13:05:10 -0400 Received: from az33smr01.freescale.net (az33smr01.freescale.net [10.64.34.199]) by az33egw01.freescale.net (8.12.11/az33egw01) with ESMTP id m8MH55id003215 for ; Mon, 22 Sep 2008 10:05:06 -0700 (MST) Sender: netdev-owner@vger.kernel.org List-ID: 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 --- drivers/net/gianfar_mii.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/gianfar_mii.c b/drivers/net/gianfar_mii.c index ebcfb27..906aba2 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; -- 1.5.4.1