powerpc: Fix spin_event_timeout() to be robust over context switches
authorGrant Likely <[email protected]>
Mon, 29 Jun 2009 13:40:51 +0000 (13:40 +0000)
committerBenjamin Herrenschmidt <[email protected]>
Wed, 8 Jul 2009 03:50:24 +0000 (13:50 +1000)
Current implementation of spin_event_timeout can be interrupted by an
IRQ or context switch after testing the condition, but before checking
the timeout.  This can cause the loop to report a timeout when the
condition actually became true in the middle.

This patch adds one final check of the condition upon exit of the loop
if the last test of the condition was still false.

Signed-off-by: Grant Likely <[email protected]>
Acked-by: Timur Tabi <[email protected]>
Signed-off-by: Benjamin Herrenschmidt <[email protected]>
arch/powerpc/include/asm/delay.h

index 1e2eb41fa0577ff8ecceb2d9711220c82ea22fab..52e4d54da2a9845d16db0773ca81310178707723 100644 (file)
@@ -63,6 +63,8 @@ extern void udelay(unsigned long usecs);
                        udelay(delay);                                         \
                else                                                           \
                        cpu_relax();                                           \
+       if (!__ret)                                                            \
+               __ret = (condition);                                           \
        __ret;                                                                 \
 })