Patchwork net: off by one, try #2

login
register
mail settings
Submitter roel kluin
Date Feb. 11, 2009, 2:22 p.m.
Message ID <4992DF3C.7070802@gmail.com>
Download mbox | patch
Permalink /patch/22923/
State Changes Requested
Delegated to: David Miller
Headers show

Comments

roel kluin - Feb. 11, 2009, 2:22 p.m.
>> With while (x++ < n) { ... } x can reach n+1.
> 
> Yes, but it looks like here is even more...
> i is also misused here and array can be overriden, so additional
> break/return is needed.

Thanks, is this how it should be?
-------------------->8----------------8<-----------------------

With while (x++ < n) { ... } x can reach n+1. As Jarek Poplawski pointed out, array
pcb->data.raw was not correctly used.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
--
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, 5:14 p.m.
On Wed, Feb 11, 2009 at 03:22:52PM +0100, Roel Kluin wrote:
> >> With while (x++ < n) { ... } x can reach n+1.
> > 
> > Yes, but it looks like here is even more...
> > i is also misused here and array can be overriden, so additional
> > break/return is needed.
> 
> Thanks, is this how it should be?

It looks (almost) OK to me. :-) Except this > 80 line.

On the other hand, I wonder if it's not a good time to make it more
readable; I mean the first while (): length, ";", and maybe ++j
similarly to i now?

BTW, I hope you remember about irda.

Jarek P.

> -------------------->8----------------8<-----------------------
> 
> With while (x++ < n) { ... } x can reach n+1. As Jarek Poplawski pointed out, array
> pcb->data.raw was not correctly used.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
> index 6124605..4cf3050 100644
> --- a/drivers/net/3c505.c
> +++ b/drivers/net/3c505.c
> @@ -497,12 +497,15 @@ static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
>  	do {
>  		j = 0;
>  		while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
> -		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);
> +		pcb->data.raw[i] = inb_command(dev->base_addr);
> +	} while (++i < MAX_PCB_DATA && (stat & ASF_PCB_MASK) != ASF_PCB_END && j <= 20000);
> +
>  	spin_unlock_irqrestore(&adapter->lock, flags);
> -	if (j >= 20000) {
> +	if (i >= MAX_PCB_DATA) {
> +		INVALID_PCB_MSG(i);
> +		return false;
> +	}
> +	if (j > 20000) {
>  		TIMEOUT_MSG(__LINE__);
>  		return false;
>  	}
--
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..4cf3050 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -497,12 +497,15 @@  static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
 	do {
 		j = 0;
 		while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
-		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);
+		pcb->data.raw[i] = inb_command(dev->base_addr);
+	} while (++i < MAX_PCB_DATA && (stat & ASF_PCB_MASK) != ASF_PCB_END && j <= 20000);
+
 	spin_unlock_irqrestore(&adapter->lock, flags);
-	if (j >= 20000) {
+	if (i >= MAX_PCB_DATA) {
+		INVALID_PCB_MSG(i);
+		return false;
+	}
+	if (j > 20000) {
 		TIMEOUT_MSG(__LINE__);
 		return false;
 	}