Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eaa215c2 authored by Rajeshwar Kurapaty's avatar Rajeshwar Kurapaty
Browse files

msm: vidc: Fix a race condition in core instances list access



While checking the supported load, we are accessing core
instance list and there are chances that it can be
modified else where. Add a mutex lock while accessing
the core instances list to avoid such scenarios.

CRs-Fixed: 566451
Change-Id: I2ac5d1e51720557790a151af66e2e9fb5d3d152f
Signed-off-by: default avatarRajeshwar Kurapaty <rkurapat@codeaurora.org>
parent 152d0efb
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -777,6 +777,7 @@ static void handle_sys_error(enum command_response cmd, void *data)
			mutex_lock(&core->lock);
			core->state = VIDC_CORE_INVALID;
			mutex_unlock(&core->lock);
			mutex_lock(&core->sync_lock);
			list_for_each_entry(inst, &core->instances,
					list) {
				mutex_lock(&inst->lock);
@@ -798,6 +799,7 @@ static void handle_sys_error(enum command_response cmd, void *data)
				msm_vidc_queue_v4l2_event(inst,
						V4L2_EVENT_MSM_VIDC_SYS_ERROR);
			}
			mutex_unlock(&core->sync_lock);
		} else {
			dprintk(VIDC_ERR,
				"Got SYS_ERR but unable to identify core");
@@ -825,6 +827,7 @@ static void handle_sys_watchdog_timeout(enum command_response cmd, void *data)
	mutex_lock(&core->lock);
	core->state = VIDC_CORE_INVALID;
	mutex_unlock(&core->lock);
	mutex_lock(&core->sync_lock);
	list_for_each_entry(inst, &core->instances, list) {
		if (inst) {
			msm_vidc_queue_v4l2_event(inst,
@@ -846,6 +849,7 @@ static void handle_sys_watchdog_timeout(enum command_response cmd, void *data)
			mutex_unlock(&inst->lock);
		}
	}
	mutex_unlock(&core->sync_lock);
}

static void handle_session_close(enum command_response cmd, void *data)
@@ -3246,10 +3250,12 @@ static int msm_vidc_load_supported(struct msm_vidc_inst *inst)
	int num_mbs_per_sec = 0;

	if (inst->state == MSM_VIDC_OPEN_DONE) {
		mutex_lock(&inst->core->sync_lock);
		num_mbs_per_sec = msm_comm_get_load(inst->core,
					MSM_VIDC_DECODER);
		num_mbs_per_sec += msm_comm_get_load(inst->core,
					MSM_VIDC_ENCODER);
		mutex_unlock(&inst->core->sync_lock);
		if (num_mbs_per_sec > inst->core->resources.max_load) {
			dprintk(VIDC_ERR,
				"H/w is overloaded. needed: %d max: %d\n",