media: videobuf2: always call poll_wait() on queues
authorAlexandre Courbot <gnurou@gmail.com>
Tue, 1 Dec 2020 12:44:41 +0000 (13:44 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 4 Jan 2021 12:12:46 +0000 (13:12 +0100)
do_poll()/do_select() seem to set the _qproc member of poll_table to
NULL the first time they are called on a given table, making subsequent
calls of poll_wait() on that table no-ops. This is a problem for vb2
which calls poll_wait() on the V4L2 queues' waitqueues only when a
queue-related event is requested, which may not necessarily be the case
during the first poll.

Fix this by making the call to poll_wait() happen first thing and
unconditionally in vb2_core_poll().

Signed-off-by: Alexandre Courbot <gnurou@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/common/videobuf2/videobuf2-core.c

index 89e3839..02281d1 100644 (file)
@@ -2374,13 +2374,20 @@ __poll_t vb2_core_poll(struct vb2_queue *q, struct file *file,
        struct vb2_buffer *vb = NULL;
        unsigned long flags;
 
+       /*
+        * poll_wait() MUST be called on the first invocation on all the
+        * potential queues of interest, even if we are not interested in their
+        * events during this first call. Failure to do so will result in
+        * queue's events to be ignored because the poll_table won't be capable
+        * of adding new wait queues thereafter.
+        */
+       poll_wait(file, &q->done_wq, wait);
+
        if (!q->is_output && !(req_events & (EPOLLIN | EPOLLRDNORM)))
                return 0;
        if (q->is_output && !(req_events & (EPOLLOUT | EPOLLWRNORM)))
                return 0;
 
-       poll_wait(file, &q->done_wq, wait);
-
        /*
         * Start file I/O emulator only if streaming API has not been used yet.
         */