Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp70733ybp; Thu, 3 Oct 2019 10:18:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyT9bnHleVeXNuazN+IzkTUMoUiXobRErcKV0FufmbfNWHuC02hNYA4VtiHAiseTggasx/3 X-Received: by 2002:a17:906:5584:: with SMTP id y4mr8686022ejp.89.1570123105537; Thu, 03 Oct 2019 10:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123105; cv=none; d=google.com; s=arc-20160816; b=KObcICtUcrxrhbeAOnIGEoPkKA4v5o72ThpsFMrLbN0SMsqh5n17Buni2GkQh817pw hj6cGRYYwNxjv31GjLVpPSsuCaRD9D8T/Bg1nxKd6kwQFjPBx5KMXkUu60jiUhYnM/x1 3/don4c/fuh/EOMfekqy23tpTAGIR2TSMBY26pDJhrFee9mNZEXvh1klJIqR1GW4Gk+A +MdZFjt8RcevZpQ2265rOfA88YpkEEhCRL14OCrfFA5kgldLaeA0bKgVWjetLKoJ+Iy4 l1Yi42QzDrTuEruAm2KdZe/PDeIMoPYVOlOswL7gugfzO9TQcUMuVRg3GPttAq+MipdY FpkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PN6LIk08ImWXGQqGdx64pu1V47nV43jwmAebX9bguNA=; b=kUg5mX6EEGF40ou0dpmSAE8emmOBD6BXz02BzlrFn9lfb26QWXQPnKWcsrIggaKBzM XB06Rmp+CRO5z66VhCqqQ3CUzrdglZ6iyPnv7hX2s9Ay0DmSa6e1dyrvTKmTuGIpGCLz tpYf5SaoFo0lukUmEXLpPDkpHZGcGX82/+9atcFsFv7HbWXu1FjolaQrTCLc8KMDyWWs 6LMTty5mKy2ckY2JnsPAkYoC8fwR/UEYI12dfc3pcP4VUK5cS+OQU8uLmvUbduPNOMCw vgUGCTFU01xbm/yJhotJMQuJnwh8xUOsin8nRJ1x8OsfQQBRkWqpNTiRPcW0vcqzbZ0l bmfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CidUrJPM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m20si1916020eds.363.2019.10.03.10.18.00; Thu, 03 Oct 2019 10:18:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CidUrJPM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404532AbfJCRPU (ORCPT + 99 others); Thu, 3 Oct 2019 13:15:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:57012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391026AbfJCQ0J (ORCPT ); Thu, 3 Oct 2019 12:26:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8E6D52133F; Thu, 3 Oct 2019 16:26:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119969; bh=dojeDYxDcSaMAmdiQPqZM0xxtY9cfX6MMKaYkfr+Zbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CidUrJPMFZ9cRlU/aBTpEhMpPc8a383ipNhZY5/oSU/Yt/hMGWjo7IzX2vZ515S1N VYuKKy62RrDqVxAsPX+TLvNxUIxdhw1WfzjUfdBAQVO5f/Cs1xDb3aI14Q682UYAcG 1p7bHeXGtPn3hiEwMXfD8C+UR9En7H9vv2VWVIWU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Tretter , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.2 049/313] media: vb2: reorder checks in vb2_poll() Date: Thu, 3 Oct 2019 17:50:27 +0200 Message-Id: <20191003154537.945046902@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Tretter [ Upstream commit 8d86a15649957c182e90fa2b1267c16699bc12f1 ] When reaching the end of stream, V4L2 clients may expect the V4L2_EOS_EVENT before being able to dequeue the last buffer, which has the V4L2_BUF_FLAG_LAST flag set. If the vb2_poll() function first checks for events and afterwards if buffers are available, a driver can queue the V4L2_EOS_EVENT event and return the buffer after the check for events but before the check for buffers. This causes vb2_poll() to signal that the buffer with V4L2_BUF_FLAG_LAST can be read without the V4L2_EOS_EVENT being available. First, check for available buffers and afterwards for events to ensure that if vb2_poll() signals POLLIN | POLLRDNORM for the V4L2_BUF_FLAG_LAST buffer, it also signals POLLPRI for the V4L2_EOS_EVENT. Signed-off-by: Michael Tretter Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/common/videobuf2/videobuf2-v4l2.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index fb9ac7696fc6e..bd9bfeee385fb 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -872,17 +872,19 @@ EXPORT_SYMBOL_GPL(vb2_queue_release); __poll_t vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) { struct video_device *vfd = video_devdata(file); - __poll_t res = 0; + __poll_t res; + + res = vb2_core_poll(q, file, wait); if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) { struct v4l2_fh *fh = file->private_data; poll_wait(file, &fh->wait, wait); if (v4l2_event_pending(fh)) - res = EPOLLPRI; + res |= EPOLLPRI; } - return res | vb2_core_poll(q, file, wait); + return res; } EXPORT_SYMBOL_GPL(vb2_poll); -- 2.20.1