Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp248147rdg; Thu, 12 Oct 2023 04:49:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErr/qm72u511ysY8avA+3+/A2g90ixpHDm0jhRBB+rbo59lgwfGlVV+JgyngBkoMldD97c X-Received: by 2002:a17:902:e84c:b0:1bc:4f04:17f4 with SMTP id t12-20020a170902e84c00b001bc4f0417f4mr31030064plg.30.1697111344024; Thu, 12 Oct 2023 04:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697111344; cv=none; d=google.com; s=arc-20160816; b=PvklnbBRXiRF/uspsdD76UMpLs04u9CWT/2ndeP3GtRXT4ARgBBI9E1m18F2tg3Bfl /Ot65972s935qe2DlDd8bC2QTGvi86s4q0F0XqX1+OQX/MM1Ef8K5woMkQOX4MEE17hl EOqch5NGOfamXehYPhn9QyPWwkqSFAJ5y6qgWTdQdF7cx3zjgw4ZVfhgt7jS+UTeJ5RG IR4f1TlMvZCk5tj8yecrLHCZjnaoG02W9DYJZ7Peq7q8YtVsGiE4kQM/GuyenoD1aFW6 7TsqkY+O9W5zzFvUU0Dj2l8ETEJrYc//WC/vh1DsJDu5bDIQmyeO0N/9q+q+vt1ce+U6 V/GQ== 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=B09KGIG+dGa9eyLZuv6Yc26Yj7bDl61pGIsQ9S5qtwY=; fh=NPTCYP6kV89VhZcTyqjnuKz2OW5UZUbu4oezKHT17AA=; b=u1sqbxUYbeAI5NYFkrFEPWjUeXhEGGypdxylIkEfZlIzwB6+NM1aw4epCoQk8/gZAu cqswcElYO00JTXYnNQimRbjkP3y4rQ1I7SQjanE1OQlLHNRxubURDoAJ7qRlX+aNK8Wt oW2CwH4jvBTESUxIJ1I2S3e6kuryUAhYd6E4fAqQIeZg+8bOouhKPbE5U9V8cHW4ewmc 9KC4iC4++0DyArMea1b6agHp8YjZ5EMpoSvxBoTZSWIXITFL9wjH574fy6MMLrKHfHi7 JR6QQpOw6Po9A0eI7S4pccsmebbU+OwIGlvo6/qv89VPOqzkSC73iKT0SOnmTWheifAx PBWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZjxLpWSv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p10-20020a170902e74a00b001c76e9f12a3si2187048plf.575.2023.10.12.04.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:49:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZjxLpWSv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 0BEB1822CBFD; Thu, 12 Oct 2023 04:49:02 -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 S1378581AbjJLLsl (ORCPT + 99 others); Thu, 12 Oct 2023 07:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378420AbjJLLq7 (ORCPT ); Thu, 12 Oct 2023 07:46:59 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B80DD7; Thu, 12 Oct 2023 04:46:58 -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 B96386607363; Thu, 12 Oct 2023 12:46:56 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697111217; bh=Hv6K096kuas0tXEWfFOtf8PobL2avYs7g7RnPKhbESI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZjxLpWSveTl5mI39YW3w3hnP4PhPurR3mMTD6rz5mEIWqdX9O6WD6n+3CP83NfN8y epDyHS6WEw80cpQwfEfnCl1XUvTLXAHsGwpe10zZ7/7kzfBEbvkuLF8V6r585LLz5w G7i3jTLIucF3X/OG4OWcenlXnCpI+gxPa/AwfI5KiD6NMEiK8enGegE0t50PmTT1AO 3Nfl+vYuqmUn+dxI3uu2OTZhHM8nIO5sCEn08tN7bxN79PYW+lZck69jHI/9XFpeLl T2Q/EmJD1HGoi8TXEuWFTiKGDYzD2GgLI+OQcPLVZXjHw1GsaU33jHcdf4tnc7e8/h qagE1kl/ECLTA== 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 , Jean-Christophe Trotin Subject: [PATCH v11 14/56] media: sti: hva: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 12 Oct 2023 13:46:00 +0200 Message-Id: <20231012114642.19040-15-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: 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:49:02 -0700 (PDT) Use vb2_get_buffer() instead of directly access to vb2_buffer buffer array. 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. Remove index range test since it is done by vb2_get_buffer(). Signed-off-by: Benjamin Gaignard CC: Jean-Christophe Trotin --- drivers/media/platform/st/sti/hva/hva-v4l2.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/st/sti/hva/hva-v4l2.c b/drivers/media/platform/st/sti/hva/hva-v4l2.c index 3a848ca32a0e..cfe83e9dc01b 100644 --- a/drivers/media/platform/st/sti/hva/hva-v4l2.c +++ b/drivers/media/platform/st/sti/hva/hva-v4l2.c @@ -569,14 +569,11 @@ static int hva_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) struct vb2_buffer *vb2_buf; vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, buf->type); - - if (buf->index >= vq->num_buffers) { - dev_dbg(dev, "%s buffer index %d out of range (%d)\n", - ctx->name, buf->index, vq->num_buffers); + vb2_buf = vb2_get_buffer(vq, buf->index); + if (!vb2_buf) { + dev_dbg(dev, "%s buffer index %d not found\n", ctx->name, buf->index); return -EINVAL; } - - vb2_buf = vb2_get_buffer(vq, buf->index); stream = to_hva_stream(to_vb2_v4l2_buffer(vb2_buf)); stream->bytesused = buf->bytesused; } -- 2.39.2