[v14,11/56] media: mediatek: jpeg: Use vb2_get_buffer() instead of directly access to buffers array
Message ID | 20231031163104.112469-12-benjamin.gaignard@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp363114vqg; Tue, 31 Oct 2023 09:32:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkfLleS43E0nDelY5vrkKUr1LJ/6qXLg9R5qiLStNBQS1uMpJzmr/55HMuS2NoTW4/JBWY X-Received: by 2002:a17:90b:695:b0:280:472b:2e82 with SMTP id m21-20020a17090b069500b00280472b2e82mr6220761pjz.39.1698769947711; Tue, 31 Oct 2023 09:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698769947; cv=none; d=google.com; s=arc-20160816; b=uhiyF2j6Yt3ealf4RQWEjR9EuJeTbel9WO4b57bp6PEFmdIw7fM/jQQieOvFQyb+GA kXMu1Lh0p2H4xgYKublGURM2Dh/m+23f4e37viy5Ju8x4hVUj2NCnBQaGZAWSlqe+EuG GM4zLNCBiEetPtueLZiftAVOuGExXOQTM3GfGLL4qGHaNDMd6IAf2sIpcBa/IPJC4kHQ AfGSRS57MljzGtrS7pZLlagjH/7kmJmTzfzRvJKZbKCiNorO3k6nFOz2tbmw/5p5nR1U 29Lau7+1WJR0DwdWxHN+AzKt6tXuQ8+uSNsx7NMSED2Ul2mfBcsoibjJ1smaUD+5xPMo q95w== 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=8DpoE1AoK2fP+RIvieFAiWcgzt2e00XMFBFnulvtgj0=; fh=+NS11/YTnD7GglrGYsYnSnUacC2YXoJUirkP5/1okOw=; b=p3AgCzWFI4IJMuo3uJyKn5E9oHHeeC6Zz4KlTk/FtItYhdy5EbCb2jKQ+pjyk2T0gR 0NuCs0dEN5hI7phHpCLT12bmXiqWsrrtEduuU24i32BZjPsXPooNl8CP9OOVvcpECY5o ZFpUWljo9iUofnUpiM6+UU1tiFcXU9/kguNkMNn+0tcP1DLD2lFd0W7Kzy30+RdrQJdn itjZXMtgathoN5cyvM+Ei1IofwidHNMHYj62f5Ap5kkzv98UL+B3PUdQ0emcST4zp5u6 MJEveEKqEM84RFPm996eARG7AJS4iMPzlDA8EZkXF9XN1wLSsz4EAB5v71cxIn9azD92 fmCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bM6SdU76; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s62-20020a17090a69c400b002636d222400si1146361pjj.14.2023.10.31.09.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 09:32:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bM6SdU76; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7A778801B9F8; Tue, 31 Oct 2023 09:32:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346012AbjJaQcK (ORCPT <rfc822;chrisjones.unixmen@gmail.com> + 33 others); Tue, 31 Oct 2023 12:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345426AbjJaQbo (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 31 Oct 2023 12:31:44 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3824133; Tue, 31 Oct 2023 09:31:31 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:c562:2ef4:80c0:92f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4998266073B3; Tue, 31 Oct 2023 16:31:30 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1698769890; bh=U25RUhgn4wrEJgYWeqq/JM19FcBBlklJam1nCiVEFHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bM6SdU764gmV7W9zfq0bWi+KO5x5LCplcW8lcbaj+kCna2NqXwR+POH8B9lgZ8CBF ZOrCUSZ4glH3rnDjNIsBkXAJVBbInrLLhqelhLgweIRRVR79Os61k6cSEPZrKm/bqR E8Q1mM3fs/b3Y/1xGUAFN6k0jD9CfC1AhsQo+JoE3jA6gjfXwBEtEWIzvqnx0LO1ZD fRe6oCJWD9Tc1GS971+1Of4OxNKQQZbdFZ0OnGEkFnrnIUrMGAq2n/nve9P0aXnOU9 jKvUVk+huaTfo0gvDxLQKTuf1I+WrplWm9VGO1LyOrQhflErW1TGORrpYWtSibyhOz BkoNQ/ZGU839A== From: Benjamin Gaignard <benjamin.gaignard@collabora.com> To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard <benjamin.gaignard@collabora.com>, Bin Liu <bin.liu@mediatek.com>, Matthias Brugger <matthias.bgg@gmail.com> Subject: [PATCH v14 11/56] media: mediatek: jpeg: Use vb2_get_buffer() instead of directly access to buffers array Date: Tue, 31 Oct 2023 17:30:19 +0100 Message-Id: <20231031163104.112469-12-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231031163104.112469-1-benjamin.gaignard@collabora.com> References: <20231031163104.112469-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 31 Oct 2023 09:32:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781289397019487837 X-GMAIL-MSGID: 1781289397019487837 |
Series |
Add DELETE_BUF ioctl
|
|
Commit Message
Benjamin Gaignard
Oct. 31, 2023, 4:30 p.m. UTC
Use vb2_get_buffer() instead of direct access to the vb2_queue bufs array.
This allows us to change the type of the bufs in the future.
After each call to vb2_get_buffer() we need to be sure that we get
a valid pointer so check the return value of all of them.
Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
CC: Bin Liu <bin.liu@mediatek.com>
CC: Matthias Brugger <matthias.bgg@gmail.com>
---
drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
Comments
W dniu 31.10.2023 o 17:30, Benjamin Gaignard pisze: > Use vb2_get_buffer() instead of direct access to the vb2_queue bufs array. > This allows us to change the type of the bufs in the future. > After each call to vb2_get_buffer() we need to be sure that we get > a valid pointer so check the return value of all of them. > > Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com> Reviewed-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com> > CC: Bin Liu <bin.liu@mediatek.com> > CC: Matthias Brugger <matthias.bgg@gmail.com> > --- > drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > index 7194f88edc0f..73a063b1569b 100644 > --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > @@ -598,12 +598,11 @@ static int mtk_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) > goto end; > > vq = v4l2_m2m_get_vq(fh->m2m_ctx, buf->type); > - if (buf->index >= vq->num_buffers) { > - dev_err(ctx->jpeg->dev, "buffer index out of range\n"); > + vb = vb2_get_buffer(vq, buf->index); > + if (!vb) { > + dev_err(ctx->jpeg->dev, "buffer not found\n"); > return -EINVAL; > } > - > - vb = vq->bufs[buf->index]; > jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb); > jpeg_src_buf->bs_size = buf->m.planes[0].bytesused; >
diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c index 7194f88edc0f..73a063b1569b 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c @@ -598,12 +598,11 @@ static int mtk_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) goto end; vq = v4l2_m2m_get_vq(fh->m2m_ctx, buf->type); - if (buf->index >= vq->num_buffers) { - dev_err(ctx->jpeg->dev, "buffer index out of range\n"); + vb = vb2_get_buffer(vq, buf->index); + if (!vb) { + dev_err(ctx->jpeg->dev, "buffer not found\n"); return -EINVAL; } - - vb = vq->bufs[buf->index]; jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb); jpeg_src_buf->bs_size = buf->m.planes[0].bytesused;