Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp451420pxb; Thu, 9 Sep 2021 04:55:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKzCeS+LJGfq73OX/LbxhpMFtlDT9ToQd6Fhoo0Q5Xoe/PvW7B3l7jAsRhy6ZFLClhi8WQ X-Received: by 2002:a17:906:3adb:: with SMTP id z27mr2994139ejd.291.1631188508790; Thu, 09 Sep 2021 04:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188508; cv=none; d=google.com; s=arc-20160816; b=lBtC0WC+EEew/QdgMWOnDtc4ALjpqlvZGF0b8fODXF11nDEgHOzSwQjhluelL0DHN+ K6a98F/DPM8fJkVL873fLvjpKr4HhCY8Hff71mbqegroDUW6IgQ9dNm7DjOHko9fVH+Q eDbf8wSOletry1LDmXrzWWxEzG2h7uv1kkf6qF94PxaHMdBI2p+5cfkJu7cZPSEQi57F c6v7GfuIhOHBn3jJb6ECAehLmpcRc9l3UqUiAntoMANRnVhNtyulUinv0gh93PGi3ghC fYnD+bVrZg0vI4Kpvz11OjeIqEUIgcTne9DB6O1KQiEKUuJEFUzZqT9LJ9lA+vwvDq8H iZBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=asZCgHjmhJ9iSr+a9nd2/nt5IPzAk4n+WgFHMUBxKuE=; b=s536+UTy7oNy9WfqndmMTQTFHvq1PbgArH7+jYYhCgR2zsm5AU+ioWHY1hDX0eTV4T IWnjNKWhKgU197v4s9XtxexEyY5xYcs1FCFvRORrUExmxEcdGgmPtULOz1EuQ75HFhsP odi7SU0/g/XKGVguXTz9o9yFyKMQuo9stZBqClduep9ElTt9W5uKXKh2KgPC8CMzGeoC eMPyuF6mJfunZurFjKdtLVoBATyh7ym61S+l3L1zer67S1xuSmtkg3qh/zLuAGEtvWcP fFMGYS0yEZFRTxCA4u28aQM9oPlnIxqw3MfAJSS1lnNAKvQLyC3Ua3s7cjRN84ML8sTc Ar5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="uGH9F5L/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jg30si1517115ejc.709.2021.09.09.04.54.43; Thu, 09 Sep 2021 04:55:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="uGH9F5L/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239082AbhIILvR (ORCPT + 99 others); Thu, 9 Sep 2021 07:51:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:54738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242204AbhIILsi (ORCPT ); Thu, 9 Sep 2021 07:48:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7334F61208; Thu, 9 Sep 2021 11:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187804; bh=4YGcCdxw4MTG0LbsryXAkz2ES/z/GJ0yp39prEeTR7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uGH9F5L/tx777rcVnLDnrkpr2MIdwVCGgYC6ugL2I9Pe1hAyAQK3qMAkHVPPXMt7O 0JQmKhJmoajFJoTfyMzLkDSV3+6+yWC58sVNdQHPVjsurnSQdd1GR4qcLh6CahFqlP aLzSxcv3+0DnfqMNcraPpAxl6hJYwasatrILmgeUB6cL+D/gqTMDxCaufXg55vMLVY wFhC3aE7YBmc8dutG0Zz+w710OdlvGwaNb9M9a1Yl0bdk5ogj4c6jjOD4YRpQ5IgBB eKvhF+BkUhiYzsrUygxhtkGo0JTre4dNP+qUvV5cSliedfLfPAO4oKknhWMTCoKNJO wx/Qpfwe0jNfw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Laurent Pinchart , Martin Kepplinger , Rui Miguel Silva , Mauro Carvalho Chehab , Sasha Levin , linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.14 107/252] media: imx: imx7-media-csi: Fix buffer return upon stream start failure Date: Thu, 9 Sep 2021 07:38:41 -0400 Message-Id: <20210909114106.141462-107-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Laurent Pinchart [ Upstream commit 0ada1697ed4256b38225319c9896661142a3572d ] When the stream fails to start, the first two buffers in the queue have been moved to the active_vb2_buf array and are returned to vb2 by imx7_csi_dma_unsetup_vb2_buf(). The function is called with the buffer state set to VB2_BUF_STATE_ERROR unconditionally, which is correct when stopping the stream, but not when the start operation fails. In that case, the state should be set to VB2_BUF_STATE_QUEUED. Fix it. Signed-off-by: Laurent Pinchart Tested-by: Martin Kepplinger Reviewed-by: Rui Miguel Silva Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/staging/media/imx/imx7-media-csi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 894c4de31790..2882964b8513 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -361,6 +361,7 @@ static void imx7_csi_dma_unsetup_vb2_buf(struct imx7_csi *csi, vb->timestamp = ktime_get_ns(); vb2_buffer_done(vb, return_status); + csi->active_vb2_buf[i] = NULL; } } } @@ -386,9 +387,10 @@ static int imx7_csi_dma_setup(struct imx7_csi *csi) return 0; } -static void imx7_csi_dma_cleanup(struct imx7_csi *csi) +static void imx7_csi_dma_cleanup(struct imx7_csi *csi, + enum vb2_buffer_state return_status) { - imx7_csi_dma_unsetup_vb2_buf(csi, VB2_BUF_STATE_ERROR); + imx7_csi_dma_unsetup_vb2_buf(csi, return_status); imx_media_free_dma_buf(csi->dev, &csi->underrun_buf); } @@ -537,9 +539,10 @@ static int imx7_csi_init(struct imx7_csi *csi) return 0; } -static void imx7_csi_deinit(struct imx7_csi *csi) +static void imx7_csi_deinit(struct imx7_csi *csi, + enum vb2_buffer_state return_status) { - imx7_csi_dma_cleanup(csi); + imx7_csi_dma_cleanup(csi, return_status); imx7_csi_init_default(csi); imx7_csi_dmareq_rff_disable(csi); clk_disable_unprepare(csi->mclk); @@ -702,7 +705,7 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable) ret = v4l2_subdev_call(csi->src_sd, video, s_stream, 1); if (ret < 0) { - imx7_csi_deinit(csi); + imx7_csi_deinit(csi, VB2_BUF_STATE_QUEUED); goto out_unlock; } @@ -712,7 +715,7 @@ static int imx7_csi_s_stream(struct v4l2_subdev *sd, int enable) v4l2_subdev_call(csi->src_sd, video, s_stream, 0); - imx7_csi_deinit(csi); + imx7_csi_deinit(csi, VB2_BUF_STATE_ERROR); } csi->is_streaming = !!enable; -- 2.30.2