Skip to content

Commit c592b46

Browse files
Hans Verkuilmchehab
authored andcommitted
media: videobuf2-core: dequeue if start_streaming fails
If a vb2_queue sets q->min_buffers_needed then when the number of queued buffers reaches q->min_buffers_needed, vb2_core_qbuf() will call the start_streaming() callback. If start_streaming() returns an error, then that error was just returned by vb2_core_qbuf(), but the buffer was still queued. However, userspace expects that if VIDIOC_QBUF fails, the buffer is returned dequeued. So if start_streaming() fails, then remove the buffer from the queue, thus avoiding this unwanted side-effect. Signed-off-by: Hans Verkuil <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Tested-by: Kieran Bingham <[email protected]> Fixes: b3379c6 ("[media] vb2: only call start_streaming if sufficient buffers are queued") Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 76f22c9 commit c592b46

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

drivers/media/common/videobuf2/videobuf2-core.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,
15731573
struct media_request *req)
15741574
{
15751575
struct vb2_buffer *vb;
1576+
enum vb2_buffer_state orig_state;
15761577
int ret;
15771578

15781579
if (q->error) {
@@ -1673,6 +1674,7 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,
16731674
* Add to the queued buffers list, a buffer will stay on it until
16741675
* dequeued in dqbuf.
16751676
*/
1677+
orig_state = vb->state;
16761678
list_add_tail(&vb->queued_entry, &q->queued_list);
16771679
q->queued_count++;
16781680
q->waiting_for_buffers = false;
@@ -1703,8 +1705,17 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb,
17031705
if (q->streaming && !q->start_streaming_called &&
17041706
q->queued_count >= q->min_buffers_needed) {
17051707
ret = vb2_start_streaming(q);
1706-
if (ret)
1708+
if (ret) {
1709+
/*
1710+
* Since vb2_core_qbuf will return with an error,
1711+
* we should return it to state DEQUEUED since
1712+
* the error indicates that the buffer wasn't queued.
1713+
*/
1714+
list_del(&vb->queued_entry);
1715+
q->queued_count--;
1716+
vb->state = orig_state;
17071717
return ret;
1718+
}
17081719
}
17091720

17101721
dprintk(q, 2, "qbuf of buffer %d succeeded\n", vb->index);

0 commit comments

Comments
 (0)