]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: vb2: vb2_core_queue_init(): sanity check lock and wait_prepare/finish
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 2 Sep 2024 14:04:54 +0000 (16:04 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sat, 12 Oct 2024 13:54:07 +0000 (15:54 +0200)
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>
drivers/media/common/videobuf2/videobuf2-core.c

index 29a8d876e6c2819ea9b2aaedee73889ecd79fcb2..6335ac7b771a3051320f306907c221c98559c258 100644 (file)
@@ -2644,6 +2644,14 @@ int vb2_core_queue_init(struct vb2_queue *q)
        if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers))
                return -EINVAL;
 
+       /* Either both or none are set */
+       if (WARN_ON(!q->ops->wait_prepare ^ !q->ops->wait_finish))
+               return -EINVAL;
+
+       /* Warn if q->lock is NULL and no custom wait_prepare is provided */
+       if (WARN_ON(!q->lock && !q->ops->wait_prepare))
+               return -EINVAL;
+
        INIT_LIST_HEAD(&q->queued_list);
        INIT_LIST_HEAD(&q->done_list);
        spin_lock_init(&q->done_lock);