Skip to content

Commit a7419d5

Browse files
author
Phil Elwell
committed
vchiq_arm: Access the dequeue_pending flag locked
Reading through this code looking for another problem (now found in userland) the use of dequeue_pending outside a lock didn't seem safe. Signed-off-by: Phil Elwell <[email protected]>
1 parent 43df7c1 commit a7419d5

File tree

1 file changed

+12
-5
lines changed
  • drivers/misc/vc04_services/interface/vchiq_arm

1 file changed

+12
-5
lines changed

drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
279279
USER_SERVICE_T *user_service;
280280
VCHIQ_SERVICE_T *service;
281281
VCHIQ_INSTANCE_T instance;
282+
int skip_completion = 0;
282283
DEBUG_INITIALISE(g_state.local)
283284

284285
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
@@ -345,9 +346,6 @@ service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
345346
user_service->msg_queue[user_service->msg_insert &
346347
(MSG_QUEUE_SIZE - 1)] = header;
347348
user_service->msg_insert++;
348-
spin_unlock(&msg_queue_spinlock);
349-
350-
up(&user_service->insert_event);
351349

352350
/* If there is a thread waiting in DEQUEUE_MESSAGE, or if
353351
** there is a MESSAGE_AVAILABLE in the completion queue then
@@ -356,13 +354,22 @@ service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
356354
if (((user_service->message_available_pos -
357355
instance->completion_remove) >= 0) ||
358356
user_service->dequeue_pending) {
359-
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
360357
user_service->dequeue_pending = 0;
361-
return VCHIQ_SUCCESS;
358+
skip_completion = 1;
362359
}
363360

361+
spin_unlock(&msg_queue_spinlock);
362+
363+
up(&user_service->insert_event);
364+
364365
header = NULL;
365366
}
367+
368+
if (skip_completion) {
369+
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
370+
return VCHIQ_SUCCESS;
371+
}
372+
366373
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
367374

368375
return add_completion(instance, reason, header, user_service,

0 commit comments

Comments
 (0)