From patchwork Thu Sep 14 13:32:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 139692 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp477582vqi; Thu, 14 Sep 2023 09:38:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0OyKhqpl5OvSZjqVRqQZHh8rutAIxQEBz5kDPUB9QUj0XOVE96Nv3OtPIJHXZqKJnl30/ X-Received: by 2002:a05:6a20:2451:b0:158:1ade:8661 with SMTP id t17-20020a056a20245100b001581ade8661mr5217854pzc.18.1694709526251; Thu, 14 Sep 2023 09:38:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694709526; cv=none; d=google.com; s=arc-20160816; b=yptBzWoUgxQtDKsvea4B8o6fvFfMqO4r3r0DOxq2kG6wTZ0c0bBy9uGz7TG68/naFt ewSun5A8RCEJZFZpzrlmPXOodNXAMVYPcLt1xZjACfH+FW0ESFHjDYFHbskGD2qwzzaC 7RnOKzufbBlJUcoqvIWFH60Ax/WNbrnbbdRBpamdWm2NJ1OJICTd90FODW//xp0YHlf9 P+P4wGoWOXQYkUopoJZULbNgk+LdD9azzPs8a1KgSRYby+2VqZdIvUiYkSBm8Du6GQAr 3f2il/zRHEz7Bx/PghrQJpcznaMJ5q1h2GkvhOyVdXt267oaoq0nq7kJoLXyVuLgQ8NW 2hqw== 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=trr6491blVoX824BIpm3hJQQxxk/3K9MVWaQdjKCKgA=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=ffp9KtO+ngkkrpJU8L6SxB8lcQKpyX6X8SAoxwAIKJmWeSA8WC2UTcqy45GVGD4XE3 vBmACKADmP6P0Kbf3NUEeNg/eLwtEMMvKXf/hkSTu+aUZyd34lXD8H3eip+jYr1XtJVc mmaCEmhCP23PiLk/pAbqUjFPhZgnSwMGo3AdjnOoouVx8CPNpEEvFaw8d8LT1phij041 pMYXvEKznjN1NyReMn7pCatK5qkYQXIWMtfQrAX3MjvWRNu5Ugeku9Fl7O3r71HIGDoG Z+VRxhGuDnsNaBROgw1mLKkZe6/izNH7oAyXy9TTV4/CDFuX8+AANTQ5H/HE8I6xfTn3 KJ/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jEyKLGVx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ei52-20020a056a0080f400b0068fdb060072si1808965pfb.341.2023.09.14.09.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:38:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=jEyKLGVx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id A1BC9807614B; Thu, 14 Sep 2023 06:36:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239516AbjINNeY (ORCPT + 35 others); Thu, 14 Sep 2023 09:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239222AbjINNdy (ORCPT ); Thu, 14 Sep 2023 09:33:54 -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 0F68D1BF8; Thu, 14 Sep 2023 06:33:42 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:36f2:37bd:ccbb:373f]) (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 81ACF660734B; Thu, 14 Sep 2023 14:33:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1694698420; bh=orO42HgJZVmG5GsbDRr5p5aAYmAqR4f3jKdoimxCmR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEyKLGVxdNGIKeLMpz746kqo6Ve+WUl2NaNIpmLz08Xw4NXo6f3Gc+8JDHzt45sC2 BxamcwujM4l70xCIk0N+RjcA65h0NI4FnWqOfvPckyIa/R1SjIh63Xy8JkCtBmE6Tu tU9B8pJSm6Zvp/xCBnWU6IGAeUCRisISM8Xm57/PKT2jCAkgJEQBYAqoGqwVDKM1th EgcCyrb4S5gGIgS3P1306A7+0y6a03yUgJDstwdbiiD5DxZpwfNAQ8+Q+BLo6Z3acQ +VWLGLVn7lS+vvmwKPDhFceFJ9UjZeioznviCP+ph00kMU2B/MBXVeSgJnjAVw4YWV GQc8A6hsuyc4Q== 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 Subject: [PATCH v7 18/49] media: Remove duplicated index vs q->num_buffers check Date: Thu, 14 Sep 2023 15:32:52 +0200 Message-Id: <20230914133323.198857-19-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230914133323.198857-1-benjamin.gaignard@collabora.com> References: <20230914133323.198857-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 (pete.vger.email [0.0.0.0]); Thu, 14 Sep 2023 06:36:01 -0700 (PDT) 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777031736433981430 X-GMAIL-MSGID: 1777031736433981430 vb2_get_buffer() already check if the requested index is valid. Stop duplicating this kind of check everywhere. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-core.c | 8 ++++++++ drivers/media/common/videobuf2/videobuf2-v4l2.c | 13 ------------- include/media/videobuf2-core.h | 8 +------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index ee4df7c68397..2add7a6795e7 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -660,6 +660,14 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) } } +struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, unsigned int index) +{ + if (index < q->num_buffers) + return q->bufs[index]; + return NULL; +} +EXPORT_SYMBOL_GPL(vb2_get_buffer); + bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb) { unsigned int plane; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 87c2d5916960..f10b70d8e66a 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -378,11 +378,6 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md return -EINVAL; } - if (b->index >= q->num_buffers) { - dprintk(q, 1, "%s: buffer index out of range\n", opname); - return -EINVAL; - } - vb = vb2_get_buffer(q, b->index); if (!vb) { dprintk(q, 1, "%s: buffer is NULL\n", opname); @@ -829,10 +824,6 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev, return -EBUSY; } - if (b->index >= q->num_buffers) { - dprintk(q, 1, "buffer index out of range\n"); - return -EINVAL; - } vb = vb2_get_buffer(q, b->index); if (!vb) { dprintk(q, 1, "can't find the requested buffer\n"); @@ -904,10 +895,6 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb) { struct vb2_buffer *vb; - if (eb->index >= q->num_buffers) { - dprintk(q, 1, "buffer index out of range\n"); - return -EINVAL; - } vb = vb2_get_buffer(q, eb->index); if (!vb) { dprintk(q, 1, "can't find the requested buffer\n"); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 97153c69583f..25ca395616a7 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -1238,13 +1238,7 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q) * operation, so the buffer lifetime should be taken into * consideration. */ -static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, - unsigned int index) -{ - if (index < q->num_buffers) - return q->bufs[index]; - return NULL; -} +struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, unsigned int index); /* * The following functions are not part of the vb2 core API, but are useful