Skip to content

Commit d99e8fa

Browse files
Phil Elwellpopcornmix
Phil Elwell
authored andcommitted
vchiq_arm: Add completion records under the mutex
An issue was observed when flushing openmax components which generate a large number of messages returning buffers to host. We occasionally found a duplicate message from 16 messages prior, resulting in a buffer returned twice. While only one thread adds completions, without the mutex you don't get the protection of the automatic memory barrier you get with synchronisation objects. Signed-off-by: Phil Elwell <[email protected]>
1 parent 203d8a5 commit d99e8fa

File tree

1 file changed

+12
-1
lines changed
  • drivers/staging/vc04_services/interface/vchiq_arm

1 file changed

+12
-1
lines changed

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,26 @@ add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
210210
VCHIQ_COMPLETION_DATA_T *completion;
211211
DEBUG_INITIALISE(g_state.local)
212212

213+
mutex_lock(&instance->completion_mutex);
214+
213215
while (instance->completion_insert ==
214216
(instance->completion_remove + MAX_COMPLETIONS)) {
215217
/* Out of space - wait for the client */
216218
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
217219
vchiq_log_trace(vchiq_arm_log_level,
218220
"add_completion - completion queue full");
219221
DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
222+
223+
mutex_unlock(&instance->completion_mutex);
220224
if (down_interruptible(&instance->remove_event) != 0) {
221225
vchiq_log_info(vchiq_arm_log_level,
222226
"service_callback interrupted");
223227
return VCHIQ_RETRY;
224-
} else if (instance->closing) {
228+
}
229+
230+
mutex_lock(&instance->completion_mutex);
231+
if (instance->closing) {
232+
mutex_unlock(&instance->completion_mutex);
225233
vchiq_log_info(vchiq_arm_log_level,
226234
"service_callback closing");
227235
return VCHIQ_SUCCESS;
@@ -254,8 +262,11 @@ add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
254262
if (reason == VCHIQ_MESSAGE_AVAILABLE)
255263
user_service->message_available_pos =
256264
instance->completion_insert;
265+
257266
instance->completion_insert++;
258267

268+
mutex_unlock(&instance->completion_mutex);
269+
259270
up(&instance->insert_event);
260271

261272
return VCHIQ_SUCCESS;

0 commit comments

Comments
 (0)