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

Commit 41ac1670 authored by Vishalsingh Hajeri's avatar Vishalsingh Hajeri Committed by vhajeri
Browse files

msm: camera: crm: Add mutex lock to avoid race condition



mutex lock on crm device adds protection to avoid a scenario
wherein a sequence of calls made from UMD generates a race
condition. A scenario where a call to stop device is
followed by call to unlink, flush and release creates
race condition.

Change-Id: I257306a132047ad490f6fb626c2b7efda42b23d3
Signed-off-by: default avatarvhajeri <vhajeri@codeaurora.org>
parent ef9c8d03
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -2314,21 +2314,23 @@ int cam_req_mgr_schedule_request(

	if (!sched_req) {
		CAM_ERR(CAM_CRM, "csl_req is NULL");
		rc = -EINVAL;
		goto end;
		return -EINVAL;
	}

	mutex_lock(&g_crm_core_dev->crm_lock);
	link = (struct cam_req_mgr_core_link *)
		cam_get_device_priv(sched_req->link_hdl);
	if (!link) {
		CAM_DBG(CAM_CRM, "link ptr NULL %x", sched_req->link_hdl);
		return -EINVAL;
		rc = -EINVAL;
		goto end;
	}

	session = (struct cam_req_mgr_core_session *)link->parent;
	if (!session) {
		CAM_WARN(CAM_CRM, "session ptr NULL %x", sched_req->link_hdl);
		return -EINVAL;
		rc = -EINVAL;
		goto end;
	}

	CAM_DBG(CAM_CRM, "link %x req %lld, sync_mode %d",
@@ -2351,6 +2353,7 @@ int cam_req_mgr_schedule_request(
	CAM_DBG(CAM_CRM, "DONE dev %x req %lld sync_mode %d",
		sched_req->link_hdl, sched_req->req_id, sched_req->sync_mode);
end:
	mutex_unlock(&g_crm_core_dev->crm_lock);
	return rc;
}

@@ -2373,11 +2376,13 @@ int cam_req_mgr_sync_config(
		return -EINVAL;
	}

	mutex_lock(&g_crm_core_dev->crm_lock);
	/* session hdl's priv data is cam session struct */
	cam_session = (struct cam_req_mgr_core_session *)
		cam_get_device_priv(sync_info->session_hdl);
	if (!cam_session) {
		CAM_ERR(CAM_CRM, "NULL pointer");
		mutex_unlock(&g_crm_core_dev->crm_lock);
		return -EINVAL;
	}

@@ -2414,6 +2419,7 @@ int cam_req_mgr_sync_config(

done:
	mutex_unlock(&cam_session->lock);
	mutex_unlock(&g_crm_core_dev->crm_lock);
	return rc;
}

@@ -2439,6 +2445,7 @@ int cam_req_mgr_flush_requests(
		goto end;
	}

	mutex_lock(&g_crm_core_dev->crm_lock);
	/* session hdl's priv data is cam session struct */
	session = (struct cam_req_mgr_core_session *)
		cam_get_device_priv(flush_info->session_hdl);
@@ -2482,6 +2489,7 @@ int cam_req_mgr_flush_requests(
		&link->workq_comp,
		msecs_to_jiffies(CAM_REQ_MGR_SCHED_REQ_TIMEOUT));
end:
	mutex_unlock(&g_crm_core_dev->crm_lock);
	return rc;
}