From patchwork Mon Apr 25 09:04:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 8924691 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 56FFBBF29F for ; Mon, 25 Apr 2016 09:05:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 56C23201D3 for ; Mon, 25 Apr 2016 09:05:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D03E20173 for ; Mon, 25 Apr 2016 09:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754013AbcDYJEv (ORCPT ); Mon, 25 Apr 2016 05:04:51 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:35348 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750793AbcDYJEu (ORCPT ); Mon, 25 Apr 2016 05:04:50 -0400 Received: by mail-lf0-f45.google.com with SMTP id c126so112763636lfb.2; Mon, 25 Apr 2016 02:04:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=lEILPwx/xjjHld9w9kH/+nOyu/YcTb1VAuCa4Nkf+yo=; b=zwMGiFILyjJamimSE1c0kCOqaw0zMQuqFgqEZJJxQkWCeFoCuCnml8edUGvP/3Xfo+ s5E0L04mdvXVrwjHCmHlorWKlbFboFADIU4lz282SR8dqMchhIJw0pOCz0aOG7udkETw J6JdU3SlYqhYMGjVkyngINefj0y3MnbcmZY5/XNwlXsTFJk8L9KtEe8SGgjDXjatlLEl 5e2vlcHL6CGg8S8rpUPzGLiFGOPhtyM202J4qG7rQgpIkg4nORHKVB++WNOUGgRDLBrd F/Skaff74+UfcG+5lxB70CMaKOICoMgq50eqhz54fFZwmeHR7u8VMVnRXM4JJV0LzKHF xqDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lEILPwx/xjjHld9w9kH/+nOyu/YcTb1VAuCa4Nkf+yo=; b=KJSeQlXxihBj2mRc9eKbATcP3HkCiDyw/Z2MAlyYIArZ7Xzm/3ct9XnsvW8MnFcN2e wDW2PeBDLPgPx2V8hFOu5Kv674oPHQdELxE2rGmnRvtUYeJHfGcRGLYgorzP70q1CFGJ bU41Ob/t8lZsqRcicJjtA1pg63fE0BtY+RZAtjyHiug2zuFYGD1U+qxex8FX/3NznOju gVrfPEegsjdPcmMmr14t2tvs5ReZzx/5GXb5rOscoLz7/c+yXk/qZb5lSfmycGST+wvv YUPw7UYRDXCKF9B92ybI1NXi0nOXpHw8eZayC8MTUDplF6Ss3nOlK+ka3s4VSvQt6gzF mBOw== X-Gm-Message-State: AOPr4FWJUQIbmhcAD5qdDyvzfX2qYe5x65F/Q1HjX6kKz7Uhap5MPWjYsNUTGth69MzXTA== X-Received: by 10.25.165.135 with SMTP id o129mr2445029lfe.162.1461575088195; Mon, 25 Apr 2016 02:04:48 -0700 (PDT) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id zu6sm4281241lbb.16.2016.04.25.02.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Apr 2016 02:04:47 -0700 (PDT) From: Ricardo Ribalda Delgado To: Pawel Osciak , Marek Szyprowski , Kyungmin Park , Mauro Carvalho Chehab , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Delgado , Junghak Sung , stable@vger.kernel.org Subject: [PATCH v4] media: vb2: Fix regression on poll() for RW mode Date: Mon, 25 Apr 2016 11:04:45 +0200 Message-Id: <1461575085-27821-1-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.8.0.rc3 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When using a device is read/write mode, vb2 does not handle properly the first select/poll operation. The reason for this, is that when this code has been refactored, some of the operations have changed their order, and now fileio emulator is not started. The reintroduced check to the core is enabled by a quirk flag, that avoids this check by other subsystems like DVB. Reported-by: Dimitrios Katsaros Cc: Junghak Sung Fixes: 49d8ab9feaf2 ("media] media: videobuf2: Separate vb2_poll()") Cc: stable@vger.kernel.org Signed-off-by: Ricardo Ribalda Delgado --- v4: Reported by Hans Rewrite comments Thanks! drivers/media/v4l2-core/videobuf2-core.c | 10 ++++++++++ drivers/media/v4l2-core/videobuf2-v4l2.c | 14 ++++++-------- include/media/videobuf2-core.h | 4 ++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 5d016f496e0e..6b3a81504a7a 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -2298,6 +2298,16 @@ unsigned int vb2_core_poll(struct vb2_queue *q, struct file *file, return POLLERR; /* + * If this quirk is set and QBUF hasn't been called yet then + * return POLLERR as well. This only affects capture queues, output + * queues will always initialize waiting_for_buffers to false. + * This quirk is set by V4L2 for backwards compatibility reasons. + */ + if (q->quirk_poll_must_check_waiting_for_buffers && + q->waiting_for_buffers && (req_events & (POLLIN | POLLRDNORM))) + return POLLERR; + + /* * For output streams you can call write() as long as there are fewer * buffers queued than there are buffers available. */ diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c index 91f552124050..0b1b8c7b6ce5 100644 --- a/drivers/media/v4l2-core/videobuf2-v4l2.c +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c @@ -765,6 +765,12 @@ int vb2_queue_init(struct vb2_queue *q) q->is_output = V4L2_TYPE_IS_OUTPUT(q->type); q->copy_timestamp = (q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) == V4L2_BUF_FLAG_TIMESTAMP_COPY; + /* + * For compatibility with vb1: if QBUF hasn't been called yet, then + * return POLLERR as well. This only affects capture queues, output + * queues will always initialize waiting_for_buffers to false. + */ + q->quirk_poll_must_check_waiting_for_buffers = true; return vb2_core_queue_init(q); } @@ -818,14 +824,6 @@ unsigned int vb2_poll(struct vb2_queue *q, struct file *file, poll_table *wait) poll_wait(file, &fh->wait, wait); } - /* - * For compatibility with vb1: if QBUF hasn't been called yet, then - * return POLLERR as well. This only affects capture queues, output - * queues will always initialize waiting_for_buffers to false. - */ - if (q->waiting_for_buffers && (req_events & (POLLIN | POLLRDNORM))) - return POLLERR; - return res | vb2_core_poll(q, file, wait); } EXPORT_SYMBOL_GPL(vb2_poll); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 8a0f55b6c2ba..3a1620946068 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -400,6 +400,9 @@ struct vb2_buf_ops { * @fileio_read_once: report EOF after reading the first buffer * @fileio_write_immediately: queue buffer after each write() call * @allow_zero_bytesused: allow bytesused == 0 to be passed to the driver + * @quirk_poll_must_check_waiting_for_buffers: Return POLLERR at poll when QBUF + * has not been called. This is a vb1 idiom that has been adopted + * also by vb2. * @lock: pointer to a mutex that protects the vb2_queue struct. The * driver can set this to a mutex to let the v4l2 core serialize * the queuing ioctls. If the driver wants to handle locking @@ -463,6 +466,7 @@ struct vb2_queue { unsigned fileio_read_once:1; unsigned fileio_write_immediately:1; unsigned allow_zero_bytesused:1; + unsigned quirk_poll_must_check_waiting_for_buffers:1; struct mutex *lock; void *owner;