From patchwork Mon Jan 26 17:08:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Towle X-Patchwork-Id: 28051 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 1YFn9f-0003sn-GG; Mon, 26 Jan 2015 18:08:51 +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 1YFn9d-0005vw-12; Mon, 26 Jan 2015 18:08:50 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754489AbbAZRIr (ORCPT + 1 other); Mon, 26 Jan 2015 12:08:47 -0500 Received: from 82-70-136-246.dsl.in-addr.zen.co.uk ([82.70.136.246]:54278 "EHLO xk120" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753100AbbAZRIq (ORCPT ); Mon, 26 Jan 2015 12:08:46 -0500 Received: from william by xk120 with local (Exim 4.80) (envelope-from ) id 1YFn9Y-00081J-P7; Mon, 26 Jan 2015 17:08:44 +0000 From: William Towle To: linux-kernel@lists.codethink.co.uk, linux-media@vger.kernel.org, Guennadi Liakhovetski , Sergei Shtylyov , Hans Verkuil Subject: [PATCH 2/2] media: rcar_vin: move buffer management to .stop_streaming handler Date: Mon, 26 Jan 2015 17:08:40 +0000 Message-Id: <1422292120-30496-3-git-send-email-william.towle@codethink.co.uk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1422292120-30496-1-git-send-email-william.towle@codethink.co.uk> References: <1422292120-30496-1-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.26.170028 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 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, __MULTIPLE_RCPTS_TO_X5 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. After the refactoring, the buf_init and buf_cleanup functions were found to contain only initialisation/release steps as are carried out elsewhere if omitted; these functions and references were removed. Signed-off-by: William Towle --- drivers/media/platform/soc_camera/rcar_vin.c | 62 ++++++-------------------- 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c index 89c409b..aa25a3b 100644 --- a/drivers/media/platform/soc_camera/rcar_vin.c +++ b/drivers/media/platform/soc_camera/rcar_vin.c @@ -480,72 +480,36 @@ static void rcar_vin_wait_stop_streaming(struct rcar_vin_priv *priv) } } -static void rcar_vin_videobuf_release(struct vb2_buffer *vb) +static void rcar_vin_stop_streaming(struct vb2_queue *vq) { - struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); + struct soc_camera_device *icd = soc_camera_from_vb2q(vq); 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; + struct list_head *buf_head, *tmp; + int i; spin_lock_irq(&priv->lock); + rcar_vin_wait_stop_streaming(priv); - /* 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], + if (priv->queue_buf[i]) { + vb2_buffer_done(priv->queue_buf[i], VB2_BUF_STATE_ERROR); - priv->queue_buf[i] = NULL; - } + priv->queue_buf[i] = NULL; } - } else { - list_del_init(to_buf_list(vb)); } - spin_unlock_irq(&priv->lock); -} - -static int rcar_vin_videobuf_init(struct vb2_buffer *vb) -{ - INIT_LIST_HEAD(to_buf_list(vb)); - return 0; -} - -static void rcar_vin_stop_streaming(struct vb2_queue *vq) -{ - struct soc_camera_device *icd = soc_camera_from_vb2q(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; - - spin_lock_irq(&priv->lock); - - rcar_vin_wait_stop_streaming(priv); - list_for_each_safe(buf_head, tmp, &priv->capture) + 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); } static struct vb2_ops rcar_vin_vb2_ops = { .queue_setup = rcar_vin_videobuf_setup, - .buf_init = rcar_vin_videobuf_init, - .buf_cleanup = rcar_vin_videobuf_release, .buf_queue = rcar_vin_videobuf_queue, .stop_streaming = rcar_vin_stop_streaming, .wait_prepare = soc_camera_unlock,