Skip to content

Commit c780d01

Browse files
Hans Verkuilmchehab
authored andcommitted
media: vb2: vb2_core_queue_init(): sanity check lock and wait_prepare/finish
Add two new checks: 1) wait_prepare and wait_finish callbacks are either both present or both unset, you can't mix. 2) if lock == NULL, then wait_prepare (and due to check 1 also wait_finish) must be present. These checks should prevent the case where lock == NULL, but there is no way to release/reacquire whatever lock is used when waiting for a buffer to arrive in VIDIOC_DQBUF. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 7e8ca48 commit c780d01

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,6 +2644,14 @@ int vb2_core_queue_init(struct vb2_queue *q)
26442644
if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers))
26452645
return -EINVAL;
26462646

2647+
/* Either both or none are set */
2648+
if (WARN_ON(!q->ops->wait_prepare ^ !q->ops->wait_finish))
2649+
return -EINVAL;
2650+
2651+
/* Warn if q->lock is NULL and no custom wait_prepare is provided */
2652+
if (WARN_ON(!q->lock && !q->ops->wait_prepare))
2653+
return -EINVAL;
2654+
26472655
INIT_LIST_HEAD(&q->queued_list);
26482656
INIT_LIST_HEAD(&q->done_list);
26492657
spin_lock_init(&q->done_lock);

0 commit comments

Comments
 (0)