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

Commit 471182d7 authored by Ashray Kulkarni's avatar Ashray Kulkarni Committed by Stephen Boyd
Browse files

v4l2: Add mutex to streamon() and dqbuf()in v4l2 framework.



When v4l2 streamon() is called the framework moves to streamon state,
after queueing the buffer. A state check is performed during dqbuf().
Sometimes when dqbuf() is called streamon() function has not completed
setting the state transisiton flag. This results in failure to dqbuf() as
the framework has not moved to streamon. This patch adds a mutex
around state transitions and dqbuf() calls.

Change-Id: I0eadc4aaffbed62facd7dd250893e50448d7e52b
Signed-off-by: default avatarAshray Kulkarni <ashrayk@codeaurora.org>
parent 5ffde09a
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -1556,9 +1556,14 @@ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
		dprintk(1, "dqbuf: invalid buffer type\n");
		return -EINVAL;
	}

	mutex_lock(&q->q_lock);
	ret = __vb2_get_done_vb(q, &vb, b, nonblocking);
	if (ret < 0)
	if (ret < 0) {
		mutex_unlock(&q->q_lock);
		return ret;
	}
	mutex_unlock(&q->q_lock);

	ret = call_qop(q, buf_finish, vb);
	if (ret) {
@@ -1672,15 +1677,17 @@ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
	/*
	 * Let driver notice that streaming state has been enabled.
	 */
	mutex_lock(&q->q_lock);
	ret = call_qop(q, start_streaming, q, atomic_read(&q->queued_count));
	if (ret) {
		dprintk(1, "streamon: driver refused to start streaming\n");
		__vb2_queue_cancel(q);
		mutex_unlock(&q->q_lock);
		return ret;
	}

	q->streaming = 1;

	mutex_unlock(&q->q_lock);
	dprintk(3, "Streamon successful\n");
	return 0;
}
@@ -2068,6 +2075,7 @@ int vb2_queue_init(struct vb2_queue *q)
	INIT_LIST_HEAD(&q->queued_list);
	INIT_LIST_HEAD(&q->done_list);
	spin_lock_init(&q->done_lock);
	mutex_init(&q->q_lock);
	init_waitqueue_head(&q->done_wq);

	if (q->buf_struct_size == 0)
+1 −0
Original line number Diff line number Diff line
@@ -344,6 +344,7 @@ struct vb2_queue {
	atomic_t			queued_count;
	struct list_head		done_list;
	spinlock_t			done_lock;
	struct mutex		q_lock;
	wait_queue_head_t		done_wq;

	void				*alloc_ctx[VIDEO_MAX_PLANES];