From patchwork Fri Jan 16 15:14:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Towle X-Patchwork-Id: 27933 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 1YC8tm-0000T6-T1; Fri, 16 Jan 2015 16:33:22 +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-7) with esmtp id 1YC8tj-00076q-3A; Fri, 16 Jan 2015 16:33:21 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753434AbbAPPdS (ORCPT + 1 other); Fri, 16 Jan 2015 10:33:18 -0500 Received: from 82-70-136-246.dsl.in-addr.zen.co.uk ([82.70.136.246]:61760 "EHLO xk120" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753044AbbAPPdR (ORCPT ); Fri, 16 Jan 2015 10:33:17 -0500 X-Greylist: delayed 912 seconds by postgrey-1.27 at vger.kernel.org; Fri, 16 Jan 2015 10:33:17 EST Received: from william by xk120 with local (Exim 4.80) (envelope-from ) id 1YC8ex-0000GM-QX; Fri, 16 Jan 2015 15:18:03 +0000 From: William Towle To: linux-kernel@lists.codethink.co.uk, linux-media@vger.kernel.org Subject: [PATCH 2/2] media: rcar_vin: move buffer management to .stop_streaming handler Date: Fri, 16 Jan 2015 15:14:27 +0000 Message-Id: <1421421267-886-3-git-send-email-william.towle@codethink.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1421421267-886-2-git-send-email-william.towle@codethink.co.uk> References: <1421421267-886-2-git-send-email-william.towle@codethink.co.uk> 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: 2015.1.16.50023 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, REFERENCES 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' This commit moves the "buffer in use" logic from the .buf_cleanup handler into .stop_streaming, based on advice that this is its proper logical home. By ensuring the list of pointers in priv->queue_buf[] is managed as soon as possible, we avoid warnings concerning buffers in ACTIVE state when the system cleans up after streaming stops. This fixes a problem with modification of buffers after their content has been cleared for passing to userspace. Signed-off-by: William Towle --- drivers/media/platform/soc_camera/rcar_vin.c | 47 +++++++++----------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c index 89c409b..022fa9d 100644 --- a/drivers/media/platform/soc_camera/rcar_vin.c +++ b/drivers/media/platform/soc_camera/rcar_vin.c @@ -485,37 +485,10 @@ 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 - */ - for (i = 0; i < MAX_BUFFER_NUM; i++) { - if (priv->queue_buf[i]) { - vb2_buffer_done(priv->queue_buf[i], - VB2_BUF_STATE_ERROR); - priv->queue_buf[i] = NULL; - } - } - } else { - list_del_init(to_buf_list(vb)); - } + list_del_init(to_buf_list(vb)); spin_unlock_irq(&priv->lock); } @@ -532,13 +505,25 @@ static void rcar_vin_stop_streaming(struct vb2_queue *vq) struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct rcar_vin_priv *priv = ici->priv; struct list_head *buf_head, *tmp; + int i; spin_lock_irq(&priv->lock); - rcar_vin_wait_stop_streaming(priv); - list_for_each_safe(buf_head, tmp, &priv->capture) - list_del_init(buf_head); + for (i = 0; i < MAX_BUFFER_NUM; i++) { + if (priv->queue_buf[i]) { + vb2_buffer_done(priv->queue_buf[i], + VB2_BUF_STATE_ERROR); + priv->queue_buf[i] = NULL; + } + } + + list_for_each_safe(buf_head, tmp, &priv->capture) { + vb2_buffer_done(&list_entry(buf_head, + struct rcar_vin_buffer, list)->vb, + VB2_BUF_STATE_ERROR); + list_del_init(buf_head); + } spin_unlock_irq(&priv->lock); }