mbox series

[0/2] vb2: check for events before checking for buffers

Message ID 20190625141113.30301-1-m.tretter@pengutronix.de (mailing list archive)
Headers show
Series vb2: check for events before checking for buffers | expand

Message

Michael Tretter June 25, 2019, 2:11 p.m. UTC
The patches fix a race condition in the poll functions of v4l2 devices.

Whenever a driver returns a buffer with the V4L2_BUF_FLAG_LAST flag set, it
must also return a V4L2_EVENT_EOS. Checking for events before checking for
buffers creates a race condition where drivers can return the buffer and event
between the checks and thus only signal the buffer without the event.
Reordering the checks avoids the race condition.

I discovered this issue in the allegro-dvt driver [0].

Michael

[0] https://lore.kernel.org/linux-media/20190527154557.62278063@litschi.hi.pengutronix.de/

Michael Tretter (2):
  media: vb2: reorder checks in vb2_poll()
  media: v4l2-mem2mem: reorder checks in v4l2_m2m_poll()

 .../media/common/videobuf2/videobuf2-v4l2.c   |  8 ++--
 drivers/media/v4l2-core/v4l2-mem2mem.c        | 47 +++++++++++--------
 2 files changed, 32 insertions(+), 23 deletions(-)