netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gianfar: Fix error in mdio reset timeout
@ 2008-06-04 18:20 Trent Piepho
  0 siblings, 0 replies; 4+ messages in thread
From: Trent Piepho @ 2008-06-04 18:20 UTC (permalink / raw)
  To: netdev; +Cc: Trent Piepho

The loop getting timed-out used "while (...  && timeout--)", which means
than when the timeout occurs, timeout will be -1 after the loop has exited.
Except timeout is unsigned, so it won't be negative!  The code that checks
if the looped exited because of a timeout used "if (timeout <= 0)", which
doesn't work, as (unsigned)-1 isn't <= 0.

Using "--timeout" in the loop fixes this problem.

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 was satisfied
on the final iteration before a timeout.

Signed-off-by: Trent Piepho <tpiepho@freescale.com>
---
 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(&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;
-- 
1.5.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] gianfar: Fix error in mdio reset timeout
@ 2008-06-10 23:36 Trent Piepho
  0 siblings, 0 replies; 4+ messages in thread
From: Trent Piepho @ 2008-06-10 23:36 UTC (permalink / raw)
  To: netdev; +Cc: Trent Piepho

The loop getting timed-out used "while (...  && timeout--)", which means
than when the timeout occurs, timeout will be -1 after the loop has exited.
Except timeout is unsigned, so it won't be negative!  The code that checks
if the looped exited because of a timeout used "if (timeout <= 0)", which
doesn't work, as (unsigned)-1 isn't <= 0.

Using "--timeout" in the loop fixes this problem.

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 was satisfied
on the final iteration before a timeout.

Signed-off-by: Trent Piepho <tpiepho@freescale.com>
---
 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(&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;
-- 
1.5.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] gianfar: Fix error in mdio reset timeout
@ 2008-09-22 17:03 Trent Piepho
  2008-09-25  0:50 ` Jeff Garzik
  0 siblings, 1 reply; 4+ messages in thread
From: Trent Piepho @ 2008-09-22 17:03 UTC (permalink / raw)
  To: netdev; +Cc: 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.

Signed-off-by: Trent Piepho <tpiepho@freescale.com>
Acked-by: Andy Fleming <afleming@freescale.com>
---
 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(&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;
-- 
1.5.4.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] gianfar: Fix error in mdio reset timeout
  2008-09-22 17:03 [PATCH] gianfar: Fix error in mdio reset timeout Trent Piepho
@ 2008-09-25  0:50 ` Jeff Garzik
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Garzik @ 2008-09-25  0:50 UTC (permalink / raw)
  To: Trent Piepho; +Cc: netdev

Trent Piepho wrote:
> 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>
> ---
>  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(&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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-25  0:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-22 17:03 [PATCH] gianfar: Fix error in mdio reset timeout Trent Piepho
2008-09-25  0:50 ` Jeff Garzik
  -- strict thread matches above, loose matches on Subject: below --
2008-06-10 23:36 Trent Piepho
2008-06-04 18:20 Trent Piepho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).