From: Finn Thain Date: Sun, 1 Jan 2017 00:56:26 +0000 (-0500) Subject: via-cuda: Avoid TREQ race condition X-Git-Tag: v4.11-rc1~122^2~35 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=a64662432200f8af6f67cd3664885a323f6a2f2d;p=karo-tx-linux.git via-cuda: Avoid TREQ race condition When a read transaction completes, one of several things will happen: a new transfer is started by the driver, a new transfer request is raised by the Cuda (i.e. TREQ asserted), or both happen at once. When both happen at once, there is a race condition between the TREQ test in the read_done state and the same test in cuda_start(). Moreover, the former test uses a stale TREQ value. Theoretically, this can result in the undesirable outcome that the interrupt handler completes with the state machine 'idle' when it should instead start the next transaction. Avoid this race by calling cuda_start() first and then confirming that it succeeded. If not, test the current TREQ value before entering the 'reading' state. Tested-by: Stan Johnson Signed-off-by: Finn Thain Signed-off-by: Michael Ellerman --- diff --git a/drivers/macintosh/via-cuda.c b/drivers/macintosh/via-cuda.c index ae3da6b95229..32126958ac66 100644 --- a/drivers/macintosh/via-cuda.c +++ b/drivers/macintosh/via-cuda.c @@ -605,12 +605,11 @@ cuda_interrupt(int irq, void *arg) memcpy(ibuf, cuda_rbuf, ibuf_len); } reply_ptr = cuda_rbuf; - if (TREQ_asserted(status)) { + cuda_state = idle; + cuda_start(); + if (cuda_state == idle && TREQ_asserted(in_8(&via[B]))) { assert_TIP(); cuda_state = reading; - } else { - cuda_state = idle; - cuda_start(); } break;