From patchwork Thu Dec 18 14:50:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 27572 X-Patchwork-Delegate: g.liakhovetski@gmx.de Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1Y1cPJ-0003kO-8Q; Thu, 18 Dec 2014 15:50:25 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-6) with esmtp id 1Y1cPG-00064i-54; Thu, 18 Dec 2014 15:50:25 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751090AbaLROuU (ORCPT + 1 other); Thu, 18 Dec 2014 09:50:20 -0500 Received: from ducie-dc1.codethink.co.uk ([185.25.241.215]:52247 "EHLO ducie-dc1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750899AbaLROuU (ORCPT ); Thu, 18 Dec 2014 09:50:20 -0500 Received: from localhost (localhost [127.0.0.1]) by ducie-dc1.codethink.co.uk (Postfix) with ESMTP id E5AC24605EB; Thu, 18 Dec 2014 14:50:18 +0000 (GMT) X-Virus-Scanned: Debian amavisd-new at ducie-dc1.codethink.co.uk Received: from ducie-dc1.codethink.co.uk ([127.0.0.1]) by localhost (ducie-dc1.codethink.co.uk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mv3CTJGP2GST; Thu, 18 Dec 2014 14:50:16 +0000 (GMT) Received: from [10.24.1.188] (xylophone.dyn.ducie.codethink.co.uk [10.24.1.188]) by ducie-dc1.codethink.co.uk (Postfix) with ESMTPSA id 8851646011C; Thu, 18 Dec 2014 14:50:15 +0000 (GMT) Message-ID: <1418914215.22813.18.camel@xylophone.i.decadent.org.uk> Subject: [RFC PATCH 5/5] media: rcar_vin: move buffer management to .stop_streaming handler From: Ben Hutchings To: linux-media@vger.kernel.org Cc: Guennadi Liakhovetski , linux-kernel@codethink.co.uk, William Towle , Sergei Shtylyov , Hans Verkuil Date: Thu, 18 Dec 2014 14:50:15 +0000 In-Reply-To: <1418914070.22813.13.camel@xylophone.i.decadent.org.uk> References: <1418914070.22813.13.camel@xylophone.i.decadent.org.uk> Organization: Codethink Ltd. X-Mailer: Evolution 3.4.4-3 Mime-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.12.18.143622 X-PMX-Spam: Gauge=IIIIIIIII, Probability=9%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, MIME_LOWER_CASE 0.05, MSGID_ADDED_BY_MTA 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, CT_TEXT_PLAIN_UTF8_CAPS 0, REFERENCES 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' From: William Towle Move the buffer state test in the .buf_cleanup handler into .stop_streaming so that a) the vb2_queue API is not subverted, and b) tracking of active-state buffers via priv->queue_buf[] is handled as early as is possible Signed-off-by: William Towle --- drivers/media/platform/soc_camera/rcar_vin.c | 36 ++++++++++---------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c index 20dbedf..bf60074 100644 --- a/drivers/media/platform/soc_camera/rcar_vin.c +++ b/drivers/media/platform/soc_camera/rcar_vin.c @@ -486,28 +486,8 @@ static void rcar_vin_videobuf_release(struct vb2_buffer *vb) struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct rcar_vin_priv *priv = ici->priv; - unsigned int i; - int buf_in_use = 0; - spin_lock_irq(&priv->lock); - - /* Is the buffer in use by the VIN hardware? */ - for (i = 0; i < MAX_BUFFER_NUM; i++) { - if (priv->queue_buf[i] == vb) { - buf_in_use = 1; - break; - } - } - if (buf_in_use) { - rcar_vin_wait_stop_streaming(priv); - - /* - * Capturing has now stopped. The buffer we have been asked - * to release could be any of the current buffers in use, so - * release all buffers that are in use by HW - */ - priv->queue_buf[i] = NULL; - } + spin_lock_irq(&priv->lock); list_del_init(to_buf_list(vb)); @@ -533,8 +513,20 @@ static void rcar_vin_stop_streaming(struct vb2_queue *vq) rcar_vin_wait_stop_streaming(priv); for (i = 0; i < vq->num_buffers; ++i) - if (vq->bufs[i]->state == VB2_BUF_STATE_ACTIVE) + if (vq->bufs[i]->state == VB2_BUF_STATE_ACTIVE) { + int j; + + /* Is this a buffer we have told the + * hardware about? Update the associated + * list, if so + */ + for (j = 0; j < MAX_BUFFER_NUM; j++) { + if (priv->queue_buf[j] == vq->bufs[i]) { + priv->queue_buf[j] = NULL; + } + } vb2_buffer_done(vq->bufs[i], VB2_BUF_STATE_ERROR); + } list_for_each_safe(buf_head, tmp, &priv->capture) list_del_init(buf_head);