usbnet: test off by one
Subsystems (4)
PATCH 1/1 usbnet: test off by one
With `while (i++ < MII_TIMEOUT)' i reaches MII_TIMEOUT + 1 after the loop This is probably unlikely a problem in practice.
--- drivers/net/usb/rtl8150.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/usb/rtl8150.c +2 -2
@@ -270,7 +270,7 @@ static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)get_registers (dev,PHYCNT ,1 , data); }while ((data[0 ] &PHY_GO ) && (i++ <MII_TIMEOUT )); -if (i <MII_TIMEOUT ) { +if (i <=MII_TIMEOUT ) {get_registers (dev,PHYDAT ,2 , data); *reg = data[0 ] | (data[1 ] <<8 );return 0 ;
@@ -295,7 +295,7 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)get_registers (dev,PHYCNT ,1 , data); }while ((data[0 ] &PHY_GO ) && (i++ <MII_TIMEOUT )); -if (i <MII_TIMEOUT ) +if (i <=MII_TIMEOUT )return 0 ;else return 1 ;
Petko Manolov
maintainerHey Roel,
MII_TIMEOUT is a number i made up myself, reasonably small so the driver won't sit there forever, but higher than 2. While testing the gadget i discovered that reading MII registers sometimes require more than one attempt.
Technically you're right. In practice it doesn't matter much. Hitting the boundary condition mean things are already out of hand.
Petko
Quoted 23 lines · Roel Kluin
With `while (i++ <
MII_TIMEOUT)' i reachesMII_TIMEOUT+ 1 after the loop This is probably unlikely a problem in practice.Signed-off-by Roel Kluin <[email protected]>---
drivers/net/usb/rtl8150.c| 4 ++--1 files changed, 2 insertions(+), 2 deletions(-)drivers/net/usb/rtl8150.c +1
-1@@ -270,7 +270,7 @@ static int read_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 * reg)get_registers (dev,PHYCNT ,1 , data); }while ((data[0 ] &PHY_GO ) && (i++ <MII_TIMEOUT )); -if (i <MII_TIMEOUT ) { +if (i <=MII_TIMEOUT ) {get_registers (dev,PHYDAT ,2 , data); *reg = data[0 ] | (data[1 ] <<8 );return 0 ;
drivers/net/usb/rtl8150.c static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg) · line 301
Quoted 8 lines
drivers/net/usb/rtl8150.c +1
-1@@ -295,7 +295,7 @@ static int write_mii_word(rtl8150_t * dev, u8 phy, __u8 indx, u16 reg)get_registers (dev,PHYCNT ,1 , data); }while ((data[0 ] &PHY_GO ) && (i++ <MII_TIMEOUT )); -if (i <MII_TIMEOUT ) +if (i <=MII_TIMEOUT )return 0 ;else return 1 ;
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Roel Kluin <[email protected]>
Date: Sun, 27 Dec 2009 22:22:08 +0100
Quoted 4 lines
With `while (i++ <
MII_TIMEOUT)' i reachesMII_TIMEOUT+ 1 after the loop This is probably unlikely a problem in practice.Signed-off-by Roel Kluin <[email protected]>
Applied.