Skip to content

Commit bf3593d

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] vb2: fix vb2 state check when start_streaming fails
Commit bd994dd (vb2: Fix stream start and buffer completion race) broke the buffer state check in vb2_buffer_done. So accept all three possible states there since I can no longer tell the difference between vb2_buffer_done called from start_streaming or from elsewhere. Instead add a WARN_ON at the end of start_streaming that will check whether any buffers were added to the done list, since that implies that the wrong state was used as well. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: stable@vger.kernel.org # for v3.15 and up Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1 parent 44e8e69 commit bf3593d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,13 +1165,10 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
11651165
if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE))
11661166
return;
11671167

1168-
if (!q->start_streaming_called) {
1169-
if (WARN_ON(state != VB2_BUF_STATE_QUEUED))
1170-
state = VB2_BUF_STATE_QUEUED;
1171-
} else if (WARN_ON(state != VB2_BUF_STATE_DONE &&
1172-
state != VB2_BUF_STATE_ERROR)) {
1173-
state = VB2_BUF_STATE_ERROR;
1174-
}
1168+
if (WARN_ON(state != VB2_BUF_STATE_DONE &&
1169+
state != VB2_BUF_STATE_ERROR &&
1170+
state != VB2_BUF_STATE_QUEUED))
1171+
state = VB2_BUF_STATE_ERROR;
11751172

11761173
#ifdef CONFIG_VIDEO_ADV_DEBUG
11771174
/*
@@ -1783,6 +1780,12 @@ static int vb2_start_streaming(struct vb2_queue *q)
17831780
/* Must be zero now */
17841781
WARN_ON(atomic_read(&q->owned_by_drv_count));
17851782
}
1783+
/*
1784+
* If done_list is not empty, then start_streaming() didn't call
1785+
* vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED) but STATE_ERROR or
1786+
* STATE_DONE.
1787+
*/
1788+
WARN_ON(!list_empty(&q->done_list));
17861789
return ret;
17871790
}
17881791

0 commit comments

Comments
 (0)