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

Commit 61511315 authored by Manish Poddar's avatar Manish Poddar Committed by Gerrit - the friendly Code Review server
Browse files

msm: camera: add different mutex lock for camera close



when camera_v4l2_close is called for one of the stream
and say backend is taking more time to delete the stream
and in between mediaserver crashes which call close camera
which lead to race condition. To avoid this added a lock
for close camera.

Change-Id: Idc4a72fd1d639619fafd3e2856d5bb502785c0bf
Signed-off-by: default avatarManish Poddar <mpoddar@codeaurora.org>
parent 1c2c6d7f
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -658,7 +658,11 @@ static int camera_v4l2_close(struct file *filep)
	struct msm_video_device *pvdev = video_drvdata(filep);
	struct camera_v4l2_private *sp = fh_to_private(filep->private_data);
	unsigned int opn_idx, mask;
	struct msm_session *session;
	BUG_ON(!pvdev);
	session = msm_session_find(pvdev->vdev->num);
	if (WARN_ON(!session))
		return -EIO;

	opn_idx = atomic_read(&pvdev->opened);
	pr_debug("%s: close stream_id=%d\n", __func__, sp->stream_id);
@@ -667,7 +671,7 @@ static int camera_v4l2_close(struct file *filep)
	atomic_set(&pvdev->opened, opn_idx);

	if (atomic_read(&pvdev->opened) == 0) {

		mutex_lock(&session->close_lock);
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
@@ -677,12 +681,14 @@ static int camera_v4l2_close(struct file *filep)

		msm_delete_command_ack_q(pvdev->vdev->num, 0);

		mutex_unlock(&session->close_lock);
		/* This should take care of both normal close
		 * and application crashes */
		camera_v4l2_vb2_q_release(filep);
		msm_destroy_session(pvdev->vdev->num);
		pm_relax(&pvdev->vdev->dev);
	} else {
		mutex_lock(&session->close_lock);
		camera_pack_event(filep, MSM_CAMERA_SET_PARM,
			MSM_CAMERA_PRIV_DEL_STREAM, -1, &event);
		msm_post_event(&event, MSM_POST_EVT_TIMEOUT);
@@ -692,6 +698,7 @@ static int camera_v4l2_close(struct file *filep)

		camera_v4l2_vb2_q_release(filep);
		msm_delete_stream(pvdev->vdev->num, sp->stream_id);
		mutex_unlock(&session->close_lock);
	}

	camera_v4l2_fh_release(filep);
+2 −0
Original line number Diff line number Diff line
@@ -415,6 +415,7 @@ int msm_create_session(unsigned int session_id, struct video_device *vdev)
	msm_enqueue(msm_session_q, &session->list);
	mutex_init(&session->lock);
	mutex_init(&session->lock_q);
	mutex_init(&session->close_lock);
	return 0;
}
EXPORT_SYMBOL(msm_create_session);
@@ -580,6 +581,7 @@ int msm_destroy_session(unsigned int session_id)
	msm_remove_session_cmd_ack_q(session);
	mutex_destroy(&session->lock);
	mutex_destroy(&session->lock_q);
	mutex_destroy(&session->close_lock);
	msm_delete_entry(msm_session_q, struct msm_session,
		list, session);
	buf_mgr_subdev = msm_sd_find("msm_buf_mngr");
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ struct msm_session {
	struct msm_queue_head stream_q;
	struct mutex lock;
	struct mutex lock_q;
	struct mutex close_lock;
};

int msm_post_event(struct v4l2_event *event, int timeout);