linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: linux-media@vger.kernel.org
Cc: kernel@pengutronix.de, pawel@osciak.com,
	hverkuil-cisco@xs4all.nl, mchehab@kernel.org,
	Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH v2 0/2] vb2: check for events before checking for buffers
Date: Thu, 27 Jun 2019 14:44:31 +0200	[thread overview]
Message-ID: <20190627124433.31051-1-m.tretter@pengutronix.de> (raw)

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.

As suggested by Hans, I renamed __v4l2_m2m_poll() to v4l2_m2m_poll_for_data()
in patch 2/2.

Michael

Changelog:

v1 -> v2:
- rename __v4l2_m2m_poll() to v4l2_m2m_poll_for_data

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(-)

-- 
2.20.1


             reply	other threads:[~2019-06-27 12:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-27 12:44 Michael Tretter [this message]
2019-06-27 12:44 ` [PATCH v2 1/2] media: vb2: reorder checks in vb2_poll() Michael Tretter
2019-06-27 12:44 ` [PATCH v2 2/2] media: v4l2-mem2mem: reorder checks in v4l2_m2m_poll() Michael Tretter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190627124433.31051-1-m.tretter@pengutronix.de \
    --to=m.tretter@pengutronix.de \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=kernel@pengutronix.de \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=pawel@osciak.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).