From patchwork Thu Sep 18 21:57:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 4934321 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9EB2CBEEA5 for ; Thu, 18 Sep 2014 21:58:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C3FB920103 for ; Thu, 18 Sep 2014 21:57:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 854972015D for ; Thu, 18 Sep 2014 21:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932713AbaIRV5z (ORCPT ); Thu, 18 Sep 2014 17:57:55 -0400 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:34609 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932196AbaIRV5x (ORCPT ); Thu, 18 Sep 2014 17:57:53 -0400 Received: from lanttu.localdomain (salottisipuli.retiisi.org.uk [IPv6:2001:1bc8:102:7fc9::83:2]) by hillosipuli.retiisi.org.uk (Postfix) with ESMTP id 4D1DF600A1; Fri, 19 Sep 2014 00:57:50 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com Subject: [PATCH 1/3] vb2: Buffers returned to videobuf2 from start_streaming in QUEUED state Date: Fri, 19 Sep 2014 00:57:47 +0300 Message-Id: <1411077469-29178-2-git-send-email-sakari.ailus@iki.fi> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1411077469-29178-1-git-send-email-sakari.ailus@iki.fi> References: <1411077469-29178-1-git-send-email-sakari.ailus@iki.fi> 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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Patch "[media] v4l: vb2: Fix stream start and buffer completion race" has a sets q->start_streaming_called before calling queue op start_streaming() in order to fix a bug. This has the side effect that buffers returned to videobuf2 in VB2_BUF_STATE_QUEUED will cause a WARN_ON() to be called. Add a new field called done_buffers_queued_state to struct vb2_queue, which must be set if the new state of buffers returned to videobuf2 must be VB2_BUF_STATE_QUEUED, i.e. buffers returned in start_streaming op. Signed-off-by: Sakari Ailus Cc: Hans Verkuil --- drivers/media/v4l2-core/videobuf2-core.c | 5 +++-- include/media/videobuf2-core.h | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 7e6aff6..202e2a5 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c @@ -1174,7 +1174,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) return; - if (!q->start_streaming_called) { + if (q->done_buffers_queued_state) { if (WARN_ON(state != VB2_BUF_STATE_QUEUED)) state = VB2_BUF_STATE_QUEUED; } else if (WARN_ON(state != VB2_BUF_STATE_DONE && @@ -1742,9 +1742,10 @@ static int vb2_start_streaming(struct vb2_queue *q) __enqueue_in_driver(vb); /* Tell the driver to start streaming */ - q->start_streaming_called = 1; + q->done_buffers_queued_state = q->start_streaming_called = 1; ret = call_qop(q, start_streaming, q, atomic_read(&q->owned_by_drv_count)); + q->done_buffers_queued_state = 0; if (!ret) return 0; diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 5a10d8d..7c0dac6 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -380,6 +380,9 @@ struct v4l2_fh; * @streaming: current streaming state * @start_streaming_called: start_streaming() was called successfully and we * started streaming. + * @done_buffers_queued_state: buffers returned to videobuf2 must go + * to VB2_BUF_STATE_QUEUED state. This is the case whilst + * the driver's start_streaming op is called. * @error: a fatal error occurred on the queue * @fileio: file io emulator internal data, used only if emulator is active * @threadio: thread io internal data, used only if thread is active @@ -418,6 +421,7 @@ struct vb2_queue { unsigned int streaming:1; unsigned int start_streaming_called:1; + unsigned int done_buffers_queued_state:1; unsigned int error:1; struct vb2_fileio_data *fileio;