Patchwork net: off by one, try #2

login
register
mail settings
Submitter roel kluin
Date Feb. 11, 2009, 10:01 a.m.
Message ID <4992A214.2040300@gmail.com>
Download mbox | patch
Permalink /patch/22908/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

roel kluin - Feb. 11, 2009, 10:01 a.m.
Better?

-------------------->8----------------8<-----------------------
With while (x++ < n) { ... } x can reach n+1.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
 drivers/net/3c505.c        |    4 ++--
 drivers/net/irda/mcs7780.c |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jarek Poplawski - Feb. 11, 2009, 1:33 p.m.
On 11-02-2009 11:01, Roel Kluin wrote:
> Better?

Yes, but it looks like here is even more...

> 
> -------------------->8----------------8<-----------------------
> With while (x++ < n) { ... } x can reach n+1.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
>  drivers/net/3c505.c        |    4 ++--
>  drivers/net/irda/mcs7780.c |    2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
> index 6124605..fb74846 100644
> --- a/drivers/net/3c505.c
> +++ b/drivers/net/3c505.c
> @@ -500,9 +500,9 @@ static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
>  		pcb->data.raw[i++] = inb_command(dev->base_addr);
>  		if (i > MAX_PCB_DATA)
>  			INVALID_PCB_MSG(i);

i is also misused here and array can be overriden, so additional
break/return is needed.

Thanks,
Jarek P.

> -	} while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
> +	} while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j <= 20000);
>  	spin_unlock_irqrestore(&adapter->lock, flags);
> -	if (j >= 20000) {
> +	if (j > 20000) {
>  		TIMEOUT_MSG(__LINE__);
>  		return false;
>  	}
> diff --git a/drivers/net/irda/mcs7780.c b/drivers/net/irda/mcs7780.c
> index 7eafdca..b4f4f19 100644
> --- a/drivers/net/irda/mcs7780.c
> +++ b/drivers/net/irda/mcs7780.c
> @@ -585,7 +585,7 @@ static int mcs_speed_change(struct mcs_cb *mcs)
>  		mcs_get_reg(mcs, MCS_RESV_REG, &rval);
>  	} while(cnt++ < 100 && (rval & MCS_IRINTX));
>  
> -	if(cnt >= 100) {
> +	if(cnt > 100) {
>  		IRDA_ERROR("unable to change speed\n");
>  		ret = -EIO;
>  		goto error;
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index 6124605..fb74846 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -500,9 +500,9 @@  static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
 		pcb->data.raw[i++] = inb_command(dev->base_addr);
 		if (i > MAX_PCB_DATA)
 			INVALID_PCB_MSG(i);
-	} while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
+	} while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j <= 20000);
 	spin_unlock_irqrestore(&adapter->lock, flags);
-	if (j >= 20000) {
+	if (j > 20000) {
 		TIMEOUT_MSG(__LINE__);
 		return false;
 	}
diff --git a/drivers/net/irda/mcs7780.c b/drivers/net/irda/mcs7780.c
index 7eafdca..b4f4f19 100644
--- a/drivers/net/irda/mcs7780.c
+++ b/drivers/net/irda/mcs7780.c
@@ -585,7 +585,7 @@  static int mcs_speed_change(struct mcs_cb *mcs)
 		mcs_get_reg(mcs, MCS_RESV_REG, &rval);
 	} while(cnt++ < 100 && (rval & MCS_IRINTX));
 
-	if(cnt >= 100) {
+	if(cnt > 100) {
 		IRDA_ERROR("unable to change speed\n");
 		ret = -EIO;
 		goto error;