From patchwork Tue Oct 31 16:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 160197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp363629vqg; Tue, 31 Oct 2023 09:33:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzZpaAJzlDeuudpnXU1eQzcgDXsCNQnmdMeF/BaOTUl85CUGX1+iNxJESKVNDAG/fkLemo X-Received: by 2002:a05:6e02:3113:b0:359:398d:7c31 with SMTP id bg19-20020a056e02311300b00359398d7c31mr1675679ilb.4.1698769992722; Tue, 31 Oct 2023 09:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698769992; cv=none; d=google.com; s=arc-20160816; b=oAM+2QHeUwVoTbgpgHyrh8JeOrfLMdYkcGJK3fhJWS3ozC7BAhTrkGGw8OSf25YVt5 vicV2+jFp3G4lPwKZ59yTCsPeG02zq4jTZ4JAU33GfHPJzKNdWFT4IvOZdH4k+lvW+FN hmh8ZCA1632cLd3SrqN2SEXBPjQ7epMYOYW76tnU6J1fMovFdCyzTwFqy+V2YrdInvEi 6iWg6BFLxWIecQ21ni4cAEde7CCaQgwyHU3yK7c2HO0UBS687k6tlDctNWASIGOwEww4 cZw4jpTcNHn6rwHIZa3X/mF9klit8MdnML6K/5cnv5fT9OZ76+gf+cIZNPorclXx3w9R 6vVg== 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=ARXOSBKGUUPDwevHrxoh+LOz0HRWiSJssojf7QO4Re0=; fh=NPTCYP6kV89VhZcTyqjnuKz2OW5UZUbu4oezKHT17AA=; b=Ae9KMhi+S5l7/TAMg8/ZP8XfxSuv7cpsJ6UGmP2TXRCRadUrZJEA3PCLSJB6X3zoWN hYLqZ2/Gg/cCA/LMfIBu0lgNuaAyv01FE55qduWIsOewEzZDx/hj/417lTvG9sS65ohV /0e0h8rUkw741MG9dnAVzLLDZBRWT5zaSi5Otpx/NdWb3QEeZuyT3KzQNSLwo+6i2uu+ Cu/I6uSELepNtLDGpI+0lVZkuFuD94ahlmupVULv2QqHPxn7Od5OzWDlzmjN6VtVOBIZ MYNu+VFTjA71E/tKDWPGE5FVol90GOb/6dKfKzaYYMl9zA5BLf6QlhLnBXfXOCHeIJGa Wn1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=F3Pa6WYW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id m5-20020a632605000000b005b928e39430si1257576pgm.67.2023.10.31.09.33.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 09:33:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=F3Pa6WYW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 7165A804A630; Tue, 31 Oct 2023 09:33:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346080AbjJaQcS (ORCPT + 33 others); Tue, 31 Oct 2023 12:32:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345387AbjJaQbw (ORCPT ); Tue, 31 Oct 2023 12:31:52 -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 35A2918B; Tue, 31 Oct 2023 09:31:36 -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 A912F66073B5; Tue, 31 Oct 2023 16:31:34 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1698769895; bh=6OByUfiYmown+37pp4jYIRU8BDesYsod95qP0wK3edE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F3Pa6WYWIPOnG7UN0NlXMBpnASoJAP5Jk88EK0wOOYckg69ulYDrMsVhjkbd5y0B8 0jcAaJYzKDEDg6BgY4Jah1imB+cITnHQ5KhubiOVRUBhNo6WF908teTcinStBWewC4 Gk5qjKsPF3fIFhEOmqzEGyLCk5HFHoudXIFjzBo7jjjUkqZmHDaMQICYtLZaPSbdAM T5sk5KMfqC4p28VZOefLpy3AvsdDX2mybnEF9VSFNR68Jkk7FfSQ0zuhOWBgx73I0C 3OBIOemgO7xAk+VLyLJ7Zq+lfsJ8qGfK5AX1b51XldMQoEEYs9SJWeGykJDBO/Hw/1 GEdQ+BnTP9SUQ== 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 v14 14/56] media: sti: hva: Use vb2_get_buffer() instead of directly access to buffers array Date: Tue, 31 Oct 2023 17:30:22 +0100 Message-Id: <20231031163104.112469-15-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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Tue, 31 Oct 2023 09:33:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781289443507296248 X-GMAIL-MSGID: 1781289443507296248 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. 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; }