* [PATCH] applicom: Prevent unsigned wrap in ac_interrupt()
@ 2009-08-08 15:13 Roel Kluin
2009-08-09 20:30 ` Jiri Slaby
0 siblings, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2009-08-08 15:13 UTC (permalink / raw)
To: Andrew Morton, LKML
unsigned i wraps if this occurs in the first iteration.
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Or do we know this can't happen?
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index 73a0765..0df3e12 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -670,7 +670,7 @@ static irqreturn_t ac_interrupt(int vec, void *dev_instance)
}
Dummy = readb(apbs[i].RamIO + VERS);
- if(readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
+ if(i && readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
/* There's another int waiting on this card */
spin_unlock(&apbs[i].mutex);
i--;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] applicom: Prevent unsigned wrap in ac_interrupt()
2009-08-08 15:13 [PATCH] applicom: Prevent unsigned wrap in ac_interrupt() Roel Kluin
@ 2009-08-09 20:30 ` Jiri Slaby
2009-08-11 8:54 ` roel kluin
0 siblings, 1 reply; 4+ messages in thread
From: Jiri Slaby @ 2009-08-09 20:30 UTC (permalink / raw)
To: Roel Kluin; +Cc: Andrew Morton, LKML
On 08/08/2009 05:13 PM, Roel Kluin wrote:
> unsigned i wraps if this occurs in the first iteration.
Could you elaborate? I don't quite understand the point.
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> Or do we know this can't happen?
You mean the i--? It's followed by i++ in the for loop 3rd expression. Or?
>
> diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
> index 73a0765..0df3e12 100644
> --- a/drivers/char/applicom.c
> +++ b/drivers/char/applicom.c
> @@ -670,7 +670,7 @@ static irqreturn_t ac_interrupt(int vec, void *dev_instance)
> }
> Dummy = readb(apbs[i].RamIO + VERS);
>
> - if(readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
> + if(i && readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
> /* There's another int waiting on this card */
> spin_unlock(&apbs[i].mutex);
> i--;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] applicom: Prevent unsigned wrap in ac_interrupt()
2009-08-09 20:30 ` Jiri Slaby
@ 2009-08-11 8:54 ` roel kluin
2009-08-11 9:00 ` Jiri Slaby
0 siblings, 1 reply; 4+ messages in thread
From: roel kluin @ 2009-08-11 8:54 UTC (permalink / raw)
To: Jiri Slaby; +Cc: Andrew Morton, LKML
>> unsigned i wraps if this occurs in the first iteration.
>
> Could you elaborate? I don't quite understand the point.
`i' is unsigned. The last test in the loop is:
if(readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
/* There's another int waiting on this card */
spin_unlock(&apbs[i].mutex);
i--;
} else {
spin_unlock(&apbs[i].mutex);
}
In the first iteration `i' is 0, so if this condition evaluates to true
then `i' becomes 0xffffffff (since it's unsigned), the for loop test
fails and the i++ never occurs.
>> Or do we know this can't happen?
>
> You mean the i--? It's followed by i++ in the for loop 3rd expression. Or?
No, I meant: do we know the test can't evaluate to true in the first iteration?
Thanks,
Roel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] applicom: Prevent unsigned wrap in ac_interrupt()
2009-08-11 8:54 ` roel kluin
@ 2009-08-11 9:00 ` Jiri Slaby
0 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2009-08-11 9:00 UTC (permalink / raw)
To: roel kluin; +Cc: Andrew Morton, LKML
On 08/11/2009 10:54 AM, roel kluin wrote:
>>> unsigned i wraps if this occurs in the first iteration.
>>
>> Could you elaborate? I don't quite understand the point.
>
> `i' is unsigned. The last test in the loop is:
>
> if(readb(apbs[i].RamIO + RAM_IT_TO_PC)) {
> /* There's another int waiting on this card */
> spin_unlock(&apbs[i].mutex);
> i--;
> } else {
> spin_unlock(&apbs[i].mutex);
> }
>
> In the first iteration `i' is 0, so if this condition evaluates to true
> then `i' becomes 0xffffffff (since it's unsigned), the for loop test
> fails and the i++ never occurs.
Hmm, no. This is not how three `for' expressions are evaluated. The CFG
of "for (a; b; c) d;" is "a->(b->d->c)*". Read 6.8.5.3 of ANSI C99.
I.e. 0xff increments back to 0.
Am I still missing something?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-08-11 12:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-08 15:13 [PATCH] applicom: Prevent unsigned wrap in ac_interrupt() Roel Kluin
2009-08-09 20:30 ` Jiri Slaby
2009-08-11 8:54 ` roel kluin
2009-08-11 9:00 ` Jiri Slaby
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).