[v11,11/56] media: mediatek: jpeg: Use vb2_get_buffer() instead of directly access to buffers array
Message ID | 20231012114642.19040-12-benjamin.gaignard@collabora.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1164827vqb; Thu, 12 Oct 2023 04:47:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGP7wBmf+qM7HRSMOF5/N2pBf+SavxbSKumHLLNlb7wcxgPWNHGgIyICCjjwsT1JqpO0/S X-Received: by 2002:a05:6a21:197:b0:14e:2c56:7b02 with SMTP id le23-20020a056a21019700b0014e2c567b02mr29895329pzb.0.1697111262050; Thu, 12 Oct 2023 04:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697111262; cv=none; d=google.com; s=arc-20160816; b=KmOjcvMew9hFUbyQtl+P+OpQBswqAYbyfaB5YIu+nRGTZCBV/2o7yoVY9CaK8DNSCi jqCzzW4IfB1h3BBp9Zyp8rDbyLvVJhj+67+o9qWm2rs2T4KJuHyeHNMr+TevpBGR1ZCm gM1DstvXJhByv0UoWJCb/KZVmULmbFShHTCx4lAC1yeLQldxZs1wwwV/IVlMJ9oiIxib T2pPgP3OfIA0RfGF9d642rZLP6qBRdDbfyMA/HUDGehqXKIPJ7MwL045thkXOncqDi3J VNyJY3IyzPWDjc8BL4D1wFL8aTKOx0tlGvaepmeLVxhvRgFX0XIWlGO+Lj0mDmj0GSCh aDzA== 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=qrE62SaPzWqVf99DN374z0e59gOg9GbF/UW/QBDlGcU=; fh=+NS11/YTnD7GglrGYsYnSnUacC2YXoJUirkP5/1okOw=; b=FvR40en6hHRKvjn7/rfelVxYDgUWHFtZ2413wvTLfH/HyFXD5kGG77y1QiC183K6Ab raSMOBkYFPRknMPrE8KmQT3/29d1yKiiuhWPUuqaWk7l3FmvhO5xFv1suj+t6F50zXxc Z2AwDhtvwWYB/lKz5MLsvCKdwTM/SRX3JLHGB00d8Obkay69+iMqVLIdYGkK/GPkhcsg xFf9y6aGfwRtnJjVDA1lrSFTv2RgzIK20tRIcVqoheSqa74xAsyQUWnIpTOi7cM4CXym dclrtxMJ8f32doZaC49g1mfnUgOxQceIaoyaILYhYU+b+Xay8v6QQzs+xTW6eGUuZwst gzlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lIVod7tu; 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 r2-20020a632b02000000b00565e865d381si2038975pgr.447.2023.10.12.04.47.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:47:42 -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=lIVod7tu; 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 E4096822CAFD; Thu, 12 Oct 2023 04:47:40 -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 S1347197AbjJLLrc (ORCPT <rfc822;rua109.linux@gmail.com> + 19 others); Thu, 12 Oct 2023 07:47:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378368AbjJLLq5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 12 Oct 2023 07:46:57 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D513CA; Thu, 12 Oct 2023 04:46:56 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7ae7:b86d:c19a:877e]) (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 0FBFF6607357; Thu, 12 Oct 2023 12:46:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697111215; bh=MGLugV4XKBfs3FJS6N+PAFm552tDzbWRNRQyV9Pe41s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lIVod7tuTGDcKArBuubJAgvI/LrQ1zpDOLm2MxFdMDrYt7XopXrYAFtjoTTgFjiH9 3ewK/S5MnhjfjC8b4QkFGqA/owyrUS4jD4+E3bDhLE22mdc8L9bq+xOWlE3C+9ADVM CNMVtMjxnG2KpJtGUPKbHOaNMpU/klmnTqqzeaPjfzksXPjW+oD+JGFWv63h4aDB0t iJmhMbi2ewqVua4+gSHRXruY35gF8RF3CJ+RY0DUzlbXpToSwt/gU3qNrdM2KyQHSh o7cyZ5IcMrCELw8MyF3/NW0Jo/HP+GSIQpZKIBbhQ2WhJmCSSXtV7UyzPMeDA0Cgea nb5+KD9jLs+HQ== 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 v11 11/56] media: mediatek: jpeg: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 12 Oct 2023 13:45:57 +0200 Message-Id: <20231012114642.19040-12-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231012114642.19040-1-benjamin.gaignard@collabora.com> References: <20231012114642.19040-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 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]); Thu, 12 Oct 2023 04:47:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779550138465923619 X-GMAIL-MSGID: 1779550138465923619 |
Series |
Add DELETE_BUF ioctl
|
|
Commit Message
Benjamin Gaignard
Oct. 12, 2023, 11:45 a.m. UTC
Use vb2_get_buffer() instead of directly access to vb2_buffer buffer array.
This could allow to change the type bufs[] field of vb2_buffer structure if
needed.
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(-)
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;