vchiq_test: Fix client race condition
authorPhil Elwell <phil@raspberrypi.org>
Thu, 17 Nov 2016 17:28:04 +0000 (17:28 +0000)
committerPhil Elwell <phil@raspberrypi.org>
Thu, 17 Nov 2016 17:36:16 +0000 (17:36 +0000)
There is a potential race between the callback thread and the main test
thread when switching between asynchronous and synchronous modes.
The vchi_clnt_callback function tries to rapidly swallow zero-length
pong packets in asynchronous mode by looping in the callback until the
message queue is emptied. There is a danger that if the main test thread
switches to synchronous mode before the callback thread notices the
queue is empty that the callback thread will erroneously receive the
synchronous pong packet.

Remove the race by forcing the callback thread to leave dequeue loop
when a sync point (non-zero length reply) is received.

See: https://github.com/raspberrypi/linux/pull/1717

interface/vchiq_arm/vchiq_test.c

index 0fc8f9eec0eae822712a06526b9ceb1b80649a8a..0e02291dabaa2cbc4357d64019b8339fed34aa12 100644 (file)
@@ -1417,8 +1417,11 @@ vchi_clnt_callback(void *callback_param,
             if (actual > 1)
                g_server_error = pong_buf;
             if (actual != 0)
+            {
                /* Responses of length 0 are not sync points */
                vcos_event_signal(&g_server_reply);
+               break;
+            }
          }
       }
    }