From patchwork Thu Sep 14 13:33:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 139784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp555339vqi; Thu, 14 Sep 2023 11:52:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7p81xas5IdfbSWKer8351uXO+PbyRRRyU3wCcZilQlo5DPmqhu9Yn/9saQuEukY3z77aC X-Received: by 2002:a05:6358:f484:b0:13f:e3eb:53a6 with SMTP id ku4-20020a056358f48400b0013fe3eb53a6mr4980890rwb.30.1694717552304; Thu, 14 Sep 2023 11:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694717552; cv=none; d=google.com; s=arc-20160816; b=Wi/VrSROvMRiny35CqvX9DQrOo+6B6U6mJmv6yEeHZL/HyjXp7S6e0d88zjY1T2y4P uMz3WlANncoCZaVxWuhgwUvp/66Sd/1QRSGf4u5bKQoAlGuVT+TIIqVrFJboKm/7JuyS 8AlfTUqGhs2oYs9YkHQzQZju/N2mUBHZFHLEHvKUYw/o9uNe6JmVEyPq5gMHYX2Tcy6i JkBIUeux+gYZJttxk4gxUv+Mmn4fR58gnPXX7rIrurJj5HwxeRjvufK/mlYVNpx1XyEP gbN2cPyabopCfGvMjpXjvGNKUkpSpJrp4a0gVWzsZL3Y3Q0Uz7fjLWdzjfRAhyAehjX8 UTNA== 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=MTUra0tlY/ay54IiK0T3ERwOy3egD+NX8ib2AgUUHFs=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=bOvg5xN+XhlHgPWc6kxRRbSBwnG1feTxtNi8Ygsbj/4vZm+G9V21VUjnPSHwRpSOz4 7BBcueOOTmgmH9SznUtozsd8h0+eAQas26B8/V0GN/+upk6Bt0js3nFjt5GtyIq7qXn7 KOl8FGO5uj8UM3Ghvc0I667CottNHYQJtixhfemkriyZArNADcrxhIGPqDmPcvLbkQcn tahVn338GwyAYbn0wUeRCTLTDYOQ8RSOQHTbBjb0uV9F2su036Tne6khPuZ5SkQIzHAj uD69ERtxbB134LdDcneKuDvsw1KuSbxKx1l3HAb64qZjxBpMaqbCZ5Wiuu/94TTwYETd zwpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oEps24M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b3-20020a655cc3000000b005653f748afcsi1867204pgt.729.2023.09.14.11.52.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 11:52:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oEps24M4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 CBDE680D6AFF; Thu, 14 Sep 2023 06:37:41 -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 S239857AbjINNf5 (ORCPT + 35 others); Thu, 14 Sep 2023 09:35:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239267AbjINNfM (ORCPT ); Thu, 14 Sep 2023 09:35:12 -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 AD03D2D62; Thu, 14 Sep 2023 06:33:56 -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 30932660739B; Thu, 14 Sep 2023 14:33:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1694698435; bh=toYAovS+izT0LEoEizCbJtlr0mGm+eGtkX0GLil3vcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oEps24M4VrGEsZjj534OIRuhGa5nrooJPEDbMc2XfeODZD/Snnj5GHpYmTeNJT9l+ CnU62Cjhug0VYXFFocoTcbn5nVVz7hP+auojoUhN8d0sz0+dt5wdAcgRJyGvIHOZxs vCeZB7SShgrnW4lDf+dTiEik1PFHIThDnbFZMxPLLIB2BZR8K5+bOvZb955q3xuhx9 56BPeGqp7XnfORhXvIKRsrY76WVS7I/k5Hdjk17tOl2cmfSRKgNs76OfI3XYNjMm4l xW6l0KS/HNEnfRoinzNpPeeTS9gcgrE2+B1lCiEu9EB4NTrO28oamIIUFNRIEB88yP ZS19F/X5nC2aA== 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 46/49] media: core: Free range of buffers Date: Thu, 14 Sep 2023 15:33:20 +0200 Message-Id: <20230914133323.198857-47-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 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 06:37:41 -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 groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777040152186784827 X-GMAIL-MSGID: 1777040152186784827 Improve __vb2_queue_free() and __vb2_free_mem() to free range of buffers and not only the last few buffers. Intoduce starting index to be flexible on range and change the loops according to this parameters. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index c5d4a388331b..88cdf4dcb07c 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -527,13 +527,12 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, /* * __vb2_free_mem() - release all video buffer memory for a given queue */ -static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) +static void __vb2_free_mem(struct vb2_queue *q, unsigned int start, unsigned int count) { - unsigned int buffer = 0; - long i = q->max_allowed_buffers; + unsigned int i, buffer = 0; struct vb2_buffer *vb; - for (i = q->max_allowed_buffers; i >= 0 && buffer < buffers; i--) { + for (i = start; i < q->max_allowed_buffers && buffer < count; i++) { vb = vb2_get_buffer(q, i); if (!vb) continue; @@ -550,19 +549,18 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) } /* - * __vb2_queue_free() - free buffers at the end of the queue - video memory and + * __vb2_queue_free() - free count buffers from start index of the queue - video memory and * related information, if no buffers are left return the queue to an * uninitialized state. Might be called even if the queue has already been freed. */ -static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) +static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned int count) { - unsigned int buffer; - long i = q->max_allowed_buffers; + unsigned int i, buffer; lockdep_assert_held(&q->mmap_lock); /* Call driver-provided cleanup function for each buffer, if provided */ - for (i = q->max_allowed_buffers, buffer = 0; i >= 0 && buffer < buffers; i--) { + for (i = start, buffer = 0; i < q->max_allowed_buffers && buffer < count; i++) { struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) @@ -574,7 +572,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) } /* Release video buffer memory */ - __vb2_free_mem(q, buffers); + __vb2_free_mem(q, start, count); #ifdef CONFIG_VIDEO_ADV_DEBUG /* @@ -659,8 +657,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) #endif /* Free vb2 buffers */ - for (i = q->max_allowed_buffers, buffer = 0; i > 0 && buffer < buffers; i--) { - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + for (i = start, buffer = 0; i < q->max_allowed_buffers && buffer < count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) continue; @@ -884,7 +882,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * queued without ever calling STREAMON. */ __vb2_queue_cancel(q); - __vb2_queue_free(q, q_num_bufs); + __vb2_queue_free(q, 0, q_num_bufs); mutex_unlock(&q->mmap_lock); /* @@ -995,7 +993,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * from already queued buffers and it will reset q->memory to * VB2_MEMORY_UNKNOWN. */ - __vb2_queue_free(q, allocated_buffers); + __vb2_queue_free(q, 0, allocated_buffers); mutex_unlock(&q->mmap_lock); return ret; } @@ -1135,7 +1133,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * from already queued buffers and it will reset q->memory to * VB2_MEMORY_UNKNOWN. */ - __vb2_queue_free(q, allocated_buffers); + __vb2_queue_free(q, 0, allocated_buffers); mutex_unlock(&q->mmap_lock); return -ENOMEM; } @@ -2617,7 +2615,7 @@ void vb2_core_queue_release(struct vb2_queue *q) __vb2_cleanup_fileio(q); __vb2_queue_cancel(q); mutex_lock(&q->mmap_lock); - __vb2_queue_free(q, q->max_allowed_buffers); + __vb2_queue_free(q, 0, q->max_allowed_buffers); kfree(q->bufs); q->bufs = NULL; bitmap_free(q->bufs_map);