Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp247728rdg; Thu, 12 Oct 2023 04:48:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcXGBsJL/nT9oy+k0dRg9tFADHvzDFmBtIsWmA2WjeL5pwxGLLwjNHHilZbdVp2449YQyN X-Received: by 2002:a05:6a20:104f:b0:154:e7e6:85c8 with SMTP id gt15-20020a056a20104f00b00154e7e685c8mr20609145pzc.31.1697111289704; Thu, 12 Oct 2023 04:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697111289; cv=none; d=google.com; s=arc-20160816; b=kVUrgoqgeRCFmTy0csqXe7tbX5ZMy8MpRLu78REKmrePCRVc2lxscohbNmmBzjd/Iv cXHZi06LjKYV2P16L4swTOH2KZcHnzSCovffa+1BcU+XYMuWy+nUmGzokwr3ns2RIYEt wcNNNruVhvTkZ621FDHFSeztgxYIcyDlKUGox1+Inq49PJ25j7vlmZL7LZOKCbEpdmqX /zfBmi/HTVwRrnU2Hp9dnkZ7JVWRKwUL0x/bdpZlOITIHJ3gnh8obQFACOdcfywg1OQd 1U67Y2m8dqsug+HNliPajxzD8dLykv35Es81kSmmDjbL6ZOgHOyOpAUPef0fBkbPDw1w 1ccw== 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 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id il12-20020a17090b164c00b002746ab58dfcsi2244365pjb.18.2023.10.12.04.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:48:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; 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 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 46F8D825B521; Thu, 12 Oct 2023 04:48:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378921AbjJLLra (ORCPT + 99 others); Thu, 12 Oct 2023 07:47:30 -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 ); 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 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 , Bin Liu , Matthias Brugger 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=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:48:00 -0700 (PDT) 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 CC: Bin Liu CC: Matthias Brugger --- 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; -- 2.39.2