Explorar o código

video: driver: Acquire lock for fence fd creation

Acquire lock for fence fd creation to avoid sync_file_poll
race conditions in fence enabled case.

Change-Id: Icb45550cd6d2018112e99d886aedd98ac3922a2c
Signed-off-by: Akshata Sahukar <[email protected]>
Akshata Sahukar %!s(int64=3) %!d(string=hai) anos
pai
achega
96a1693ba4
Modificáronse 1 ficheiros con 21 adicións e 1 borrados
  1. 21 1
      driver/vidc/src/msm_vidc_fence.c

+ 21 - 1
driver/vidc/src/msm_vidc_fence.c

@@ -5,6 +5,9 @@
 
 #include "msm_vidc_fence.h"
 #include "msm_vidc_debug.h"
+#include "msm_vidc_driver.h"
+
+extern struct msm_vidc_core *g_core;
 
 static const char *msm_vidc_dma_fence_get_driver_name(struct dma_fence *df)
 {
@@ -92,6 +95,18 @@ int msm_vidc_create_fence_fd(struct msm_vidc_inst *inst,
 		return -EINVAL;
 	}
 
+	/*
+	 * Acquire inst->lock for fence fd creation
+	 * to avoid sync_file_create() and sync_file_poll()
+	 * race conditions in e2e playback usecase.
+	 */
+	inst = get_inst_ref(g_core, inst);
+	if (!inst) {
+		d_vpr_e("%s: invalid params\n", __func__);
+		return -EINVAL;
+	}
+	inst_lock(inst, __func__);
+
 	fence->fd = get_unused_fd_flags(0);
 	if (fence->fd < 0) {
 		i_vpr_e(inst, "%s: getting fd (%d) failed\n", __func__,
@@ -109,11 +124,16 @@ int msm_vidc_create_fence_fd(struct msm_vidc_inst *inst,
 
 	i_vpr_l(inst, "%s: created fd %d for fence %s\n", __func__,
 		fence->fd, fence->name);
-	return rc;
+
+	inst_unlock(inst, __func__);
+	put_inst(inst);
+	return 0;
 
 err_sync_file:
 	put_unused_fd(fence->fd);
 err_fd:
+	inst_unlock(inst, __func__);
+	put_inst(inst);
 	return rc;
 }