applicom: Prevent unsigned wrap in ac_interrupt()
PATCH 1/1 applicom: Prevent unsigned wrap in ac_interrupt()
unsigned i wraps if this occurs in the first iteration.
---
Or do we know this can't happen?
drivers/char/applicom.c +1 -1
@@ -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--;
Quoted 1 line · Roel Kluin
unsigned i wraps if this occurs in the first iteration.
Could you elaborate? I don't quite understand the point.
Quoted 3 lines
Signed-off-by Roel Kluin <[email protected]>---
Or do we know this can't happen?
You mean the i--? It's followed by i++ in the for loop 3rd expression. Or?
Quoted 14 lines
drivers/char/applicom.c +1
-1@@ -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--;
Quoted 3 lines
Quoted 1 line
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.
Quoted 3 lines
Quoted 1 line
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
Quoted 14 lines · roel kluin
Quoted 3 lines
Quoted 1 line
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); }
Quoted 3 lines
In the first iteration
i' is 0, so if this condition evaluates to true theni' becomes0xffffffff(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?