From patchwork Thu Jun 25 17:42:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11625821 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1764814B7 for ; Thu, 25 Jun 2020 17:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1D4F2082E for ; Thu, 25 Jun 2020 17:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406867AbgFYRnI (ORCPT ); Thu, 25 Jun 2020 13:43:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406863AbgFYRnI (ORCPT ); Thu, 25 Jun 2020 13:43:08 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93E38C08C5C1 for ; Thu, 25 Jun 2020 10:43:07 -0700 (PDT) Received: from localhost.localdomain (p200300cb8737cf00e4140a231ed1025d.dip0.t-ipconnect.de [IPv6:2003:cb:8737:cf00:e414:a23:1ed1:25d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 853972A5760; Thu, 25 Jun 2020 18:43:05 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org Subject: [PATCH 1/3] media: staging: rkisp1: params: don't reference the vb2 buffer after calling vb2_buffer_done Date: Thu, 25 Jun 2020 19:42:55 +0200 Message-Id: <20200625174257.22216-2-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200625174257.22216-1-dafna.hirschfeld@collabora.com> References: <20200625174257.22216-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The driver should not reference the buffer pointer of vb2_buffer after calling 'vb2_buffer_done' on that buffer since the call passes the buffer to userspace. Signed-off-by: Dafna Hirschfeld Acked-by: Helen Koike --- drivers/staging/media/rkisp1/rkisp1-params.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-params.c b/drivers/staging/media/rkisp1/rkisp1-params.c index 797e79de659c..762c2259b807 100644 --- a/drivers/staging/media/rkisp1/rkisp1-params.c +++ b/drivers/staging/media/rkisp1/rkisp1-params.c @@ -1457,9 +1457,9 @@ static void rkisp1_params_vb2_buf_queue(struct vb2_buffer *vb) new_params = (struct rkisp1_params_cfg *) (vb2_plane_vaddr(vb, 0)); vbuf->sequence = frame_sequence; - vb2_buffer_done(¶ms_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); params->is_first_params = false; params->cur_params = *new_params; + vb2_buffer_done(¶ms_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); return; } From patchwork Thu Jun 25 17:42:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11625823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7E6A60D for ; Thu, 25 Jun 2020 17:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E5E9208C7 for ; Thu, 25 Jun 2020 17:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406868AbgFYRnJ (ORCPT ); Thu, 25 Jun 2020 13:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406865AbgFYRnI (ORCPT ); Thu, 25 Jun 2020 13:43:08 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6D96C08C5DB for ; Thu, 25 Jun 2020 10:43:07 -0700 (PDT) Received: from localhost.localdomain (p200300cb8737cf00e4140a231ed1025d.dip0.t-ipconnect.de [IPv6:2003:cb:8737:cf00:e414:a23:1ed1:25d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 049272A5765; Thu, 25 Jun 2020 18:43:05 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org Subject: [PATCH 2/3] media: staging: rkisp1: params: don't release lock in isr before buffer is done Date: Thu, 25 Jun 2020 19:42:56 +0200 Message-Id: <20200625174257.22216-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200625174257.22216-1-dafna.hirschfeld@collabora.com> References: <20200625174257.22216-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In the irq handler 'rkisp1_params_isr', the lock 'config_lock' should be held as long as the current buffer is used. Otherwise the stop_streaming calback might remove it from the list and pass it to userspace while it is referenced in the irq handler. Signed-off-by: Dafna Hirschfeld --- drivers/staging/media/rkisp1/rkisp1-params.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-params.c b/drivers/staging/media/rkisp1/rkisp1-params.c index 762c2259b807..bf006dbeee2d 100644 --- a/drivers/staging/media/rkisp1/rkisp1-params.c +++ b/drivers/staging/media/rkisp1/rkisp1-params.c @@ -1210,10 +1210,11 @@ void rkisp1_params_isr(struct rkisp1_device *rkisp1, u32 isp_mis) if (!list_empty(¶ms->params)) cur_buf = list_first_entry(¶ms->params, struct rkisp1_buffer, queue); - spin_unlock(¶ms->config_lock); - if (!cur_buf) + if (!cur_buf) { + spin_unlock(¶ms->config_lock); return; + } new_params = (struct rkisp1_params_cfg *)(cur_buf->vaddr[0]); @@ -1228,13 +1229,11 @@ void rkisp1_params_isr(struct rkisp1_device *rkisp1, u32 isp_mis) isp_ctrl |= RKISP1_CIF_ISP_CTRL_ISP_CFG_UPD; rkisp1_write(params->rkisp1, isp_ctrl, RKISP1_CIF_ISP_CTRL); - spin_lock(¶ms->config_lock); list_del(&cur_buf->queue); - spin_unlock(¶ms->config_lock); - cur_buf->vb.sequence = frame_sequence; vb2_buffer_done(&cur_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); } + spin_unlock(¶ms->config_lock); } static const struct rkisp1_cif_isp_awb_meas_config rkisp1_awb_params_default_config = { From patchwork Thu Jun 25 17:42:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 11625825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E73814E3 for ; Thu, 25 Jun 2020 17:43:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 255DB20899 for ; Thu, 25 Jun 2020 17:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406869AbgFYRnJ (ORCPT ); Thu, 25 Jun 2020 13:43:09 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39094 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406853AbgFYRnI (ORCPT ); Thu, 25 Jun 2020 13:43:08 -0400 Received: from localhost.localdomain (p200300cb8737cf00e4140a231ed1025d.dip0.t-ipconnect.de [IPv6:2003:cb:8737:cf00:e414:a23:1ed1:25d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 765732A5763; Thu, 25 Jun 2020 18:43:06 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com Cc: dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org Subject: [PATCH 3/3] media: staging: rkisp1: params: in 'stop_streaming' don't release the lock while returning buffers Date: Thu, 25 Jun 2020 19:42:57 +0200 Message-Id: <20200625174257.22216-4-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200625174257.22216-1-dafna.hirschfeld@collabora.com> References: <20200625174257.22216-1-dafna.hirschfeld@collabora.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In the stop_streaming callback 'rkisp1_params_vb2_stop_streaming' there is no need to release the lock 'config_lock' and then acquire it again at each iteration when returning all buffers. This is because the stream is about to end and there is no need to let the isr access a buffer. Signed-off-by: Dafna Hirschfeld --- drivers/staging/media/rkisp1/rkisp1-params.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/drivers/staging/media/rkisp1/rkisp1-params.c b/drivers/staging/media/rkisp1/rkisp1-params.c index bf006dbeee2d..5169b02731f1 100644 --- a/drivers/staging/media/rkisp1/rkisp1-params.c +++ b/drivers/staging/media/rkisp1/rkisp1-params.c @@ -1488,19 +1488,13 @@ static void rkisp1_params_vb2_stop_streaming(struct vb2_queue *vq) /* stop params input firstly */ spin_lock_irqsave(¶ms->config_lock, flags); params->is_streaming = false; - spin_unlock_irqrestore(¶ms->config_lock, flags); for (i = 0; i < RKISP1_ISP_PARAMS_REQ_BUFS_MAX; i++) { - spin_lock_irqsave(¶ms->config_lock, flags); if (!list_empty(¶ms->params)) { buf = list_first_entry(¶ms->params, struct rkisp1_buffer, queue); list_del(&buf->queue); - spin_unlock_irqrestore(¶ms->config_lock, - flags); } else { - spin_unlock_irqrestore(¶ms->config_lock, - flags); break; } @@ -1508,6 +1502,7 @@ static void rkisp1_params_vb2_stop_streaming(struct vb2_queue *vq) vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); buf = NULL; } + spin_unlock_irqrestore(¶ms->config_lock, flags); } static int