From patchwork Thu Oct 19 12:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155503 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp358771vqb; Thu, 19 Oct 2023 05:52:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbRonRTWRBxryt1YI6e2w9hufF6HH1lkrBZxmb9LQfbLbwTGXvEB9w5LpmckFxKfVofz70 X-Received: by 2002:a05:6359:c07:b0:143:27e:d3cf with SMTP id gn7-20020a0563590c0700b00143027ed3cfmr1672172rwb.4.1697719975580; Thu, 19 Oct 2023 05:52:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697719975; cv=none; d=google.com; s=arc-20160816; b=ocx+3k+klLUtOn2A4Q2/tTrVXt7kCyM0zRk4hgFHoy9GUdhZ4eLzotjKbPOTmYkW/P 2T48cJZNPtE/nHKnrdOmzS4j0cXnKKNHj6a4mQ3qzSaTsVuNMSiRdfCMDWB/7pIJwMgB dDcC8msg8ALZAi9jWNZ5QlO0nTxk4vjuRdF1CcpFunF2wlDonmywzStBRtfA0F326EaB NsaHI5FllV1VoT/PJnzRCJTCHJcTbRI4J/EaoODtqAJeJFJ40E2mx968I/0gVJ/JMt42 0oBZmr7MlALwpE2TlBewYe/8ufJB/DvVsXE4R96qaGt/dFMb38yZWy0s9YmM9nsniXrE rwQQ== 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=sj9zEzSQKjeWdQkuGM7i4Hrn4i7fVVdzvjJAu2+KTlA=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=ojy0RthhSYH5rhY1P1ouNNFGCb99qrr3LtacMpimyJmwpIVBkQrtPZZsccpC2UZCLZ DXB3VHOz105voXKFvlJyJXhHt/2pwLAxlrPTGNYxMTDRG/WDdkmAnmm3cRS/mKrVFCjl sccDg3p9I+UqbeIXv8jcMpMDHiHTY06Xp/b20+VKjSUq33C0RoJ5sZUxDI9lkuBdSbtD jJORq2wRoLZR+DR8GDgpQCry1igXDkLDxVUW+QxbpMxHFEo5jTfatGCSLdXMO03z1cfL BR8kFwf72sd8w06AArLvjnKC32v6en97jWah/1464xFAGwwJoeldATHAeJ2E8/kdlKdA pwPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ox5lQuLL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d4-20020a056a0010c400b00690fec2f3b6si3395832pfu.193.2023.10.19.05.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:52:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ox5lQuLL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 3F153819704B; Thu, 19 Oct 2023 05:52:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345643AbjJSMwf (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345374AbjJSMwe (ORCPT ); Thu, 19 Oct 2023 08:52:34 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4636106; Thu, 19 Oct 2023 05:52:32 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 248FF660732E; Thu, 19 Oct 2023 13:52:31 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719951; bh=cMzVFA9/TUVo9VWr/5JcyqG4OOKgwWqTUUieq9IONwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ox5lQuLLysKewwxPRZbQsn/epHlYzy4PIi+wApDlBwGmeMRMjVO0DCzBRKwT/pNTE dFUyZHj7QVU51rzcfgGPYEoSDv7xxD7cHMpzOAZNEccLgG7aERRCR7XjG/XAMZEx5t x8EKEXHiINd46X0O66ExvFmciPDrGMydvwrx7/GD0E8folAbE3Sa/kLqqLhUwG1Sxg +4chB4EZf1OpBGwmcqhDuuZINPxaPIq/55KsLNVP72l5g/Nhz9rJoRCFNXvKQtaJSc xiW+Bt69y+XufPHlVlc1G2IlEu2V828w2OQVWqabEnYk758n8jSqMtTQDmOXilI2B9 fEPHA9VEaP6BQ== 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 v13 01/56] media: videobuf2: Rename offset parameter Date: Thu, 19 Oct 2023 14:51:27 +0200 Message-Id: <20231019125222.21370-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:52:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188421387703099 X-GMAIL-MSGID: 1780188421387703099 Rename 'off' parameter to 'offset' to clarify the code. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 27aee92f3eea..a5e57affeb30 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -356,23 +356,23 @@ static void __setup_offsets(struct vb2_buffer *vb) { struct vb2_queue *q = vb->vb2_queue; unsigned int plane; - unsigned long off = 0; + unsigned long offset = 0; if (vb->index) { struct vb2_buffer *prev = q->bufs[vb->index - 1]; struct vb2_plane *p = &prev->planes[prev->num_planes - 1]; - off = PAGE_ALIGN(p->m.offset + p->length); + offset = PAGE_ALIGN(p->m.offset + p->length); } for (plane = 0; plane < vb->num_planes; ++plane) { - vb->planes[plane].m.offset = off; + vb->planes[plane].m.offset = offset; dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n", - vb->index, plane, off); + vb->index, plane, offset); - off += vb->planes[plane].length; - off = PAGE_ALIGN(off); + offset += vb->planes[plane].length; + offset = PAGE_ALIGN(offset); } } @@ -2185,9 +2185,9 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type) EXPORT_SYMBOL_GPL(vb2_core_streamoff); /* - * __find_plane_by_offset() - find plane associated with the given offset off + * __find_plane_by_offset() - find plane associated with the given offset */ -static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, +static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset, unsigned int *_buffer, unsigned int *_plane) { struct vb2_buffer *vb; @@ -2218,7 +2218,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, vb = q->bufs[buffer]; for (plane = 0; plane < vb->num_planes; ++plane) { - if (vb->planes[plane].m.offset == off) { + if (vb->planes[plane].m.offset == offset) { *_buffer = buffer; *_plane = plane; return 0; @@ -2304,7 +2304,7 @@ EXPORT_SYMBOL_GPL(vb2_core_expbuf); int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) { - unsigned long off = vma->vm_pgoff << PAGE_SHIFT; + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; struct vb2_buffer *vb; unsigned int buffer = 0, plane = 0; int ret; @@ -2335,7 +2335,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) * Find the plane corresponding to the offset passed by userspace. This * will return an error if not MEMORY_MMAP or file I/O is in progress. */ - ret = __find_plane_by_offset(q, off, &buffer, &plane); + ret = __find_plane_by_offset(q, offset, &buffer, &plane); if (ret) goto unlock; @@ -2380,7 +2380,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q, unsigned long pgoff, unsigned long flags) { - unsigned long off = pgoff << PAGE_SHIFT; + unsigned long offset = pgoff << PAGE_SHIFT; struct vb2_buffer *vb; unsigned int buffer, plane; void *vaddr; @@ -2392,7 +2392,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q, * Find the plane corresponding to the offset passed by userspace. This * will return an error if not MEMORY_MMAP or file I/O is in progress. */ - ret = __find_plane_by_offset(q, off, &buffer, &plane); + ret = __find_plane_by_offset(q, offset, &buffer, &plane); if (ret) goto unlock; From patchwork Thu Oct 19 12:51:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359052vqb; Thu, 19 Oct 2023 05:53:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFjk/PoB7HtkGfJYYZtB5MBhb08ggzge3rcpFZCctl9Kgh6g9vW0rEWUNlLmCBe1w4GC8G7 X-Received: by 2002:a05:6a00:15cf:b0:6bb:def8:b09c with SMTP id o15-20020a056a0015cf00b006bbdef8b09cmr1965040pfu.1.1697720010835; Thu, 19 Oct 2023 05:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720010; cv=none; d=google.com; s=arc-20160816; b=KL1eH3D5xg3W+MGzBxs606pTm9N6PbOZoSiQ9cJmKsv7UVdkvJ+/e9LSIfDnSDpMZE hH3v+poApBCojGAtANbn31BiG1ruv9tt1Jjuj7mlV/OaON2qdOA/fb6szDDHy4iZGfep STgTvCEqUBQQKJG6kC0PSA5CPq3D+ZHoZGVcL24PwROJ8j1GIRSf0qGb4GXKuYeOlpeX 8ZWpQq0N8hr96ttmnHcR34hMxNbdlr7XN9m31uWqJ+Nx8BXplM5gl/ngY2fmgPcydtlW 1qseU9A6ZVLCyWi9mlOC8xngSHBPlD5jT+n167I7KnUYGVojwIfFN1QoemcLvXHEVsGw lbaA== 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=P++PSUnKxA1FoBnWZtRCB7asB3D81oFP8RoeOwSpsrM=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=X3vr1nWeedN3Q2f9WQJfcK01CPLVzh1hDdIapNDMJqqxmwcUF8jc49/yrL+z6S+1x3 nrlLH/VajacZ9XzB551jh12lls12JxFPt+KtlPlRrlENe2vVw9AMMXV8IVUWij5ou/zw UUEsKLsVAoIH6p8nj0u/VrW9z+g+023+JcIBKpmyw/cu3l/xI2qUMrZZUBqjc82WKu/8 vl1yLA6cr1P7jFuh5NT0kjMES+iVl7jgcD9U5FuJxPTwLkA6wlh7Lbqcm4bQoWldufo/ ilzS8Pek6dJ3Jot2YJuFYTuis8sALv/8vToVUkTquEmQxS1Jw40c4+LtkJfB4rEongWd 76IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=i9dS1+mQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id p40-20020a056a000a2800b006bbe72a826asi6445520pfh.180.2023.10.19.05.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=i9dS1+mQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id D26FF83762E1; Thu, 19 Oct 2023 05:53:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345751AbjJSMwj (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345649AbjJSMwf (ORCPT ); Thu, 19 Oct 2023 08:52:35 -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 3DBA2112; Thu, 19 Oct 2023 05:52:33 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 A17456607331; Thu, 19 Oct 2023 13:52:31 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719952; bh=7foNNb6amO3+FMMwIl173lEOz6gYhJG/dA79F9jwpAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9dS1+mQOAJtsUDP6CQAOSwd2HoajdX0VZDRle2Y/D6DE8GT/HTayhK8zFKqSUSzj L2oWPgKkGiR5NCLtcOF0ijNVgEjyrzEj3NyFuwwIOcTTd3oLAkJQ/eb+oCmF+Kg71X KMM72CakLpPkH7iBuXxHh50SGADIvjPApmjzkxY5wNMX15jDvTLI32Ig125izKAxHo ce9CvzVH/4bbjzLTxMiotzeTPkIZTF7toJAd5JR1WcXn4tj3dpFVSOjXyzBycS2N0c UE7W8N5FaFHugWkgXbCyMTq0EfQZtU8cbadNWdTSZJ5hm7l8nKzKgZDfzfrog2ebBb MxCtjFdUAV3gQ== 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 v13 02/56] media: videobuf2: Rework offset 'cookie' encoding pattern Date: Thu, 19 Oct 2023 14:51:28 +0200 Message-Id: <20231019125222.21370-3-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:53:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188458520428916 X-GMAIL-MSGID: 1780188458520428916 Change how offset 'cookie' field value is computed to make possible to use more buffers. The maximum number of buffers depends of PAGE_SHIFT value and can go up to 0x7fff when PAGE_SHIFT = 12. With this encoding pattern we know the maximum number that a queue could store so we can check it at queue init time. It also make easier and faster to find buffer and plane from using the offset field. Change __find_plane_by_offset() prototype to return the video buffer itself rather than it index. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index a5e57affeb30..09be8e026044 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -31,6 +31,11 @@ #include +#define PLANE_INDEX_SHIFT (PAGE_SHIFT + 3) +#define PLANE_INDEX_MASK 0x7 +#define MAX_BUFFER_INDEX BIT_MASK(30 - PLANE_INDEX_SHIFT) +#define BUFFER_INDEX_MASK (MAX_BUFFER_INDEX - 1) + static int debug; module_param(debug, int, 0644); @@ -358,21 +363,27 @@ static void __setup_offsets(struct vb2_buffer *vb) unsigned int plane; unsigned long offset = 0; - if (vb->index) { - struct vb2_buffer *prev = q->bufs[vb->index - 1]; - struct vb2_plane *p = &prev->planes[prev->num_planes - 1]; - - offset = PAGE_ALIGN(p->m.offset + p->length); - } + /* + * The offset "cookie" value has the following constraints: + * - a buffer can have up to 8 planes. + * - v4l2 mem2mem uses bit 30 to distinguish between + * OUTPUT (aka "source", bit 30 is 0) and + * CAPTURE (aka "destination", bit 30 is 1) buffers. + * - must be page aligned + * That led to this bit mapping when PAGE_SHIFT = 12: + * |30 |29 15|14 12|11 0| + * |DST_QUEUE_OFF_BASE|buffer index|plane index| 0 | + * where there are 15 bits to store the buffer index. + * Depending on PAGE_SHIFT value we can have fewer bits + * to store the buffer index. + */ + offset = vb->index << PLANE_INDEX_SHIFT; for (plane = 0; plane < vb->num_planes; ++plane) { - vb->planes[plane].m.offset = offset; + vb->planes[plane].m.offset = offset + (plane << PAGE_SHIFT); dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n", vb->index, plane, offset); - - offset += vb->planes[plane].length; - offset = PAGE_ALIGN(offset); } } @@ -2188,10 +2199,9 @@ EXPORT_SYMBOL_GPL(vb2_core_streamoff); * __find_plane_by_offset() - find plane associated with the given offset */ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset, - unsigned int *_buffer, unsigned int *_plane) + struct vb2_buffer **vb, unsigned int *plane) { - struct vb2_buffer *vb; - unsigned int buffer, plane; + unsigned int buffer; /* * Sanity checks to ensure the lock is held, MEMORY_MMAP is @@ -2209,24 +2219,15 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset, return -EBUSY; } - /* - * Go over all buffers and their planes, comparing the given offset - * with an offset assigned to each plane. If a match is found, - * return its buffer and plane numbers. - */ - for (buffer = 0; buffer < q->num_buffers; ++buffer) { - vb = q->bufs[buffer]; + /* Get buffer and plane from the offset */ + buffer = (offset >> PLANE_INDEX_SHIFT) & BUFFER_INDEX_MASK; + *plane = (offset >> PAGE_SHIFT) & PLANE_INDEX_MASK; - for (plane = 0; plane < vb->num_planes; ++plane) { - if (vb->planes[plane].m.offset == offset) { - *_buffer = buffer; - *_plane = plane; - return 0; - } - } - } + if (buffer >= q->num_buffers || *plane >= q->bufs[buffer]->num_planes) + return -EINVAL; - return -EINVAL; + *vb = q->bufs[buffer]; + return 0; } int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, @@ -2306,7 +2307,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) { unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; struct vb2_buffer *vb; - unsigned int buffer = 0, plane = 0; + unsigned int plane = 0; int ret; unsigned long length; @@ -2335,12 +2336,10 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) * Find the plane corresponding to the offset passed by userspace. This * will return an error if not MEMORY_MMAP or file I/O is in progress. */ - ret = __find_plane_by_offset(q, offset, &buffer, &plane); + ret = __find_plane_by_offset(q, offset, &vb, &plane); if (ret) goto unlock; - vb = q->bufs[buffer]; - /* * MMAP requires page_aligned buffers. * The buffer length was page_aligned at __vb2_buf_mem_alloc(), @@ -2368,7 +2367,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) if (ret) return ret; - dprintk(q, 3, "buffer %d, plane %d successfully mapped\n", buffer, plane); + dprintk(q, 3, "buffer %u, plane %d successfully mapped\n", vb->index, plane); return 0; } EXPORT_SYMBOL_GPL(vb2_mmap); @@ -2382,7 +2381,7 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q, { unsigned long offset = pgoff << PAGE_SHIFT; struct vb2_buffer *vb; - unsigned int buffer, plane; + unsigned int plane; void *vaddr; int ret; @@ -2392,12 +2391,10 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q, * Find the plane corresponding to the offset passed by userspace. This * will return an error if not MEMORY_MMAP or file I/O is in progress. */ - ret = __find_plane_by_offset(q, offset, &buffer, &plane); + ret = __find_plane_by_offset(q, offset, &vb, &plane); if (ret) goto unlock; - vb = q->bufs[buffer]; - vaddr = vb2_plane_vaddr(vb, plane); mutex_unlock(&q->mmap_lock); return vaddr ? (unsigned long)vaddr : -EINVAL; From patchwork Thu Oct 19 12:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359027vqb; Thu, 19 Oct 2023 05:53:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZBfGd5M+DRcXWxD/2FwzLDdlDy8jI5uls06cpgboPHWpCllcHij607Do1/j4xLCKVW75y X-Received: by 2002:a05:6359:6699:b0:135:5ede:f352 with SMTP id so25-20020a056359669900b001355edef352mr1545206rwb.8.1697720007085; Thu, 19 Oct 2023 05:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720007; cv=none; d=google.com; s=arc-20160816; b=N8hvQsM+TUfrTkwq/bGC+RPHVrnaYkzMvpXIdq02QPMF7MWhqV7fiUHkw2UvVuKi82 2Q2mjgPeU5Tu//yYR4k+UY0PCc5wPRwMudwSSvuiyOmR8XQaSNnQB8JqccYg0wa42pcr mxWvwdmF4mDXyTGxILhQElXLCam6YnbZuwIKH/eYv4zx1qoF2ZcIThFXL0k+YGsJte9w 2Dg0aJQinY3wBfT1H14DgIFaTpyhYooKW5GNPjm2bmDoDhwvjmYuV/EHfHwXOPTBZ+yf I6OCGeDlfmntEARpezDgNAC2ccnynAJD4iNc+BD/nbBoPfZImj2K3B3KYGAWqfwDAuMV VhNg== 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=EuTgtxyPbErCrKgvGy4Be2VTKeTj33LFpgdcasSoc4k=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=CXQP+I0jJa+Yy4tttBFX2C7eI+zryxmAyM3NX/u/1WH1QPPHM3kXkpW2jnA4p3Ys3u KXgssDy61sCX308hiujXqHulZkqF9QtZg0qGQ7aHW3hqz6pfOTCJDloPDBe5ZRbpG45w KVnWFiXU1EV1tYazRsbW7+dA+IdyqQLr6vjCxRyo4VLvDERnztDHIirBD7bcyKHGSW/e TBEoYHCQDvD2fIG94Tk0xcFM4yQQwzN1aca++P1jiC7S06EPEkFMduU7KrNZ4VVrmjJx hgg7138RLSZyFqCHRyqKGID4mSkjhga9YkkY3NZdHFr5JRS/OghUGrs5hRvo23Q4babu RPIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=EtIkbWAV; 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id f3-20020a056a00228300b006be3a6e8bc6si6477102pfe.283.2023.10.19.05.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:27 -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=EtIkbWAV; 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 CC4D78297687; Thu, 19 Oct 2023 05:53:18 -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 S1345844AbjJSMws (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345502AbjJSMwf (ORCPT ); Thu, 19 Oct 2023 08:52:35 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC00B115; Thu, 19 Oct 2023 05:52:33 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 26A8B6607332; Thu, 19 Oct 2023 13:52:32 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719952; bh=xMJ8tMojfr13gTY+PpecndOGeS4i3P9Tk9kRrGKcBSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EtIkbWAVNV0zrcnTNqNK5FgGVRgJwxe/LxAW0zi46t1YvYYgLO/Q8dlpSw4zeW/w+ iJwCM5dZ3+UpAgP13Ln7b78mpO3Mj+oY5gjEFCjo/KXZc34HmFSaCmAw9gcNeikulJ GwYctCrepjmRf/NvYuTXtcQPXiqVTmGIqAlBSp79QLrwNfv7dAM096Sqdelh8L0Jxf roturVKO7mkRKvEBfyAC0Y6x81eCUcShohkcl8shkvOYndlxr89g2nKidrW/z5ws1V Csh3WaPinlY4mpo1LP7e8aQa84DQkkik2iacyG7YoBeW7EqH0nCD3G1q/Cgu0vqMLJ m+kCJJ2xgPKhA== 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 v13 03/56] media: videobuf2: Stop spamming kernel log with all queue counter Date: Thu, 19 Oct 2023 14:51:29 +0200 Message-Id: <20231019125222.21370-4-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:53:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188453816489330 X-GMAIL-MSGID: 1780188453816489330 Only report unbalanced queue counters do avoid spamming kernel log with useless information. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 79 +++++++++++-------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 09be8e026044..47dba2a20d73 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -533,25 +533,26 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) #ifdef CONFIG_VIDEO_ADV_DEBUG /* - * Check that all the calls were balances during the life-time of this - * queue. If not (or if the debug level is 1 or up), then dump the - * counters to the kernel log. + * Check that all the calls were balanced during the life-time of this + * queue. If not then dump the counters to the kernel log. */ if (q->num_buffers) { bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || q->cnt_prepare_streaming != q->cnt_unprepare_streaming || q->cnt_wait_prepare != q->cnt_wait_finish; - if (unbalanced || debug) { - pr_info("counters for queue %p:%s\n", q, - unbalanced ? " UNBALANCED!" : ""); - pr_info(" setup: %u start_streaming: %u stop_streaming: %u\n", - q->cnt_queue_setup, q->cnt_start_streaming, - q->cnt_stop_streaming); - pr_info(" prepare_streaming: %u unprepare_streaming: %u\n", - q->cnt_prepare_streaming, q->cnt_unprepare_streaming); - pr_info(" wait_prepare: %u wait_finish: %u\n", - q->cnt_wait_prepare, q->cnt_wait_finish); + if (unbalanced) { + pr_info("unbalanced counters for queue %p:\n", q); + if (q->cnt_start_streaming != q->cnt_stop_streaming) + pr_info(" setup: %u start_streaming: %u stop_streaming: %u\n", + q->cnt_queue_setup, q->cnt_start_streaming, + q->cnt_stop_streaming); + if (q->cnt_prepare_streaming != q->cnt_unprepare_streaming) + pr_info(" prepare_streaming: %u unprepare_streaming: %u\n", + q->cnt_prepare_streaming, q->cnt_unprepare_streaming); + if (q->cnt_wait_prepare != q->cnt_wait_finish) + pr_info(" wait_prepare: %u wait_finish: %u\n", + q->cnt_wait_prepare, q->cnt_wait_finish); } q->cnt_queue_setup = 0; q->cnt_wait_prepare = 0; @@ -572,29 +573,37 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) vb->cnt_buf_prepare != vb->cnt_buf_finish || vb->cnt_buf_init != vb->cnt_buf_cleanup; - if (unbalanced || debug) { - pr_info(" counters for queue %p, buffer %d:%s\n", - q, buffer, unbalanced ? " UNBALANCED!" : ""); - pr_info(" buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n", - vb->cnt_buf_init, vb->cnt_buf_cleanup, - vb->cnt_buf_prepare, vb->cnt_buf_finish); - pr_info(" buf_out_validate: %u buf_queue: %u buf_done: %u buf_request_complete: %u\n", - vb->cnt_buf_out_validate, vb->cnt_buf_queue, - vb->cnt_buf_done, vb->cnt_buf_request_complete); - pr_info(" alloc: %u put: %u prepare: %u finish: %u mmap: %u\n", - vb->cnt_mem_alloc, vb->cnt_mem_put, - vb->cnt_mem_prepare, vb->cnt_mem_finish, - vb->cnt_mem_mmap); - pr_info(" get_userptr: %u put_userptr: %u\n", - vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr); - pr_info(" attach_dmabuf: %u detach_dmabuf: %u map_dmabuf: %u unmap_dmabuf: %u\n", - vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf, - vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf); - pr_info(" get_dmabuf: %u num_users: %u vaddr: %u cookie: %u\n", + if (unbalanced) { + pr_info("unbalanced counters for queue %p, buffer %d:\n", + q, buffer); + if (vb->cnt_buf_init != vb->cnt_buf_cleanup) + pr_info(" buf_init: %u buf_cleanup: %u\n", + vb->cnt_buf_init, vb->cnt_buf_cleanup); + if (vb->cnt_buf_prepare != vb->cnt_buf_finish) + pr_info(" buf_prepare: %u buf_finish: %u\n", + vb->cnt_buf_prepare, vb->cnt_buf_finish); + if (vb->cnt_buf_queue != vb->cnt_buf_done) + pr_info(" buf_out_validate: %u buf_queue: %u buf_done: %u buf_request_complete: %u\n", + vb->cnt_buf_out_validate, vb->cnt_buf_queue, + vb->cnt_buf_done, vb->cnt_buf_request_complete); + if (vb->cnt_mem_alloc != vb->cnt_mem_put) + pr_info(" alloc: %u put: %u\n", + vb->cnt_mem_alloc, vb->cnt_mem_put); + if (vb->cnt_mem_prepare != vb->cnt_mem_finish) + pr_info(" prepare: %u finish: %u\n", + vb->cnt_mem_prepare, vb->cnt_mem_finish); + if (vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr) + pr_info(" get_userptr: %u put_userptr: %u\n", + vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr); + if (vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf) + pr_info(" attach_dmabuf: %u detach_dmabuf: %u\n", + vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf); + if (vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf) + pr_info(" map_dmabuf: %u unmap_dmabuf: %u\n", + vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf); + pr_info(" get_dmabuf: %u num_users: %u\n", vb->cnt_mem_get_dmabuf, - vb->cnt_mem_num_users, - vb->cnt_mem_vaddr, - vb->cnt_mem_cookie); + vb->cnt_mem_num_users); } } #endif From patchwork Thu Oct 19 12:51:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155507 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp358982vqb; Thu, 19 Oct 2023 05:53:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFk5LAg9/nuhk8yF/LSrZXy4ufU5fqnwkJG5Eqr8/h1LO6ragNRfESLI3+B0R+YHCBTOBuf X-Received: by 2002:a05:6a00:13aa:b0:6bd:8c4a:ab8f with SMTP id t42-20020a056a0013aa00b006bd8c4aab8fmr1974273pfg.2.1697720001014; Thu, 19 Oct 2023 05:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720001; cv=none; d=google.com; s=arc-20160816; b=CCzIn1r89im8XLw7h+jet6QXXGdPQIS1YnH7YuYSBlmd4Hvj3Sr/VebLDz5OQooWoi LlDE377cKHOiilcj+a8y7hgARWLwM2nQAO4JfUTKmNu4K1b/Eqne0OwL/E4J8p8OF3SA a6fyMBjGR2hWM8F/kUEPPNR8KFfnXyrjwDp/RFGDdulwxOkCdCsycaapoVb4w7KNaXDt 7O0YlIVOAWUWVTHqEO7yU5rC29gaiK0bKf0ivU3SMoy1nE6MggsRUQMx/AHvhPnCwGAt WPjn24DA/WObHbd4Uoz8JO5qUQb86GktpahZz9TXI9yy/9D/HOe4ADXdX80Ta1XOrLZ7 flTw== 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=SA4PH414VIt/GPNkUC7sOlBqn6g4x3Gk9319dX1SY4M=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=zF/roTU7kOdV7k0ZR4RcronTNF9/Fr6U/pWVvO5d2CyQ8Ihjqy6CrsvHATeg9AKL2e 2IcTUqVFqL0+8G8ewfJaxcXX9oFk6ixb0aUlGVfbsOn4kQQANtKSjouESOoHs1qBe4t1 cLfu4ISQwN2yfaqzNQrL9tknJoihSJQWNu3IZR0yZ0xR+i9cnhQ5OCx/HB8EMaYiECOf ZLbzCXAhZnUow01oQDvoBDyLnR59Yj0HGN2wG2HDvoyF5JplFzE1/ck31ITUQ5tDHZzm LRprqJForU14JpFdItomuowbbELeaal5tHWZpWSePasD3uwH+PdU1boagSl0clK4prOs wG0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Zms2B9oY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k12-20020a056a00134c00b0068fcc84dda7si6374125pfu.327.2023.10.19.05.53.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Zms2B9oY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 933E3819705C; Thu, 19 Oct 2023 05:53:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345767AbjJSMwm (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345714AbjJSMwh (ORCPT ); Thu, 19 Oct 2023 08:52:37 -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 3EF9A106; Thu, 19 Oct 2023 05:52:34 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 A1A6A6607333; Thu, 19 Oct 2023 13:52:32 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719953; bh=XjK/Kp20BaSdyqAfCXYLxtuHEY30gjek0FvjTYy8X9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zms2B9oYILgkcSHUeED3BvjJ7QppuElpos3eU1ok5UVHrKGy/I8TEhZxV2aTrBONi gRxpEjAtPWM6imLcuN4QWLw8ClvdWBkE/IEh/kgSYS+o7wNp7e/hOc0AQXwJ3bJn6r i+IqTxfWRCiYeP3+5sAIMCzASG1u2VpiftsYbgBFaPUYF4o8OjpfZN5EcDT68GbJ3W y0HnZdrXHOdssFdY0WnGHp44Y0BXH/CYBGQU6xIzjHYGBWS52kQmEtrT6M6XLhmFXa aiChARf9HPJxHsEEAeaPeO9/CApVaDYxAgUuxnJTjuqhahDJzz2s2YnKHUlh50w3Nj 2KmhhU1T1XWNw== 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 v13 04/56] media: videobuf2: Use vb2_buffer instead of index Date: Thu, 19 Oct 2023 14:51:30 +0200 Message-Id: <20231019125222.21370-5-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:53:12 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188447468788928 X-GMAIL-MSGID: 1780188447468788928 Directly use vb2_buffer pointer instead of index inside queue array. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 40 +++++---------- .../media/common/videobuf2/videobuf2-v4l2.c | 51 +++++++++++-------- drivers/media/dvb-core/dvb_vb2.c | 6 +-- include/media/videobuf2-core.h | 16 +++--- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 47dba2a20d73..968b7c0e7934 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -654,9 +654,9 @@ static bool __buffers_in_use(struct vb2_queue *q) return false; } -void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb) +void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb) { - call_void_bufop(q, fill_user_buffer, q->bufs[index], pb); + call_void_bufop(q, fill_user_buffer, vb, pb); } EXPORT_SYMBOL_GPL(vb2_core_querybuf); @@ -1490,9 +1490,6 @@ static void vb2_req_unprepare(struct media_request_object *obj) WARN_ON(!vb->req_obj.req); } -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, - struct media_request *req); - static void vb2_req_queue(struct media_request_object *obj) { struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); @@ -1507,7 +1504,7 @@ static void vb2_req_queue(struct media_request_object *obj) * set. We just ignore that, and expect this will be caught the * next time vb2_req_prepare() is called. */ - err = vb2_core_qbuf(vb->vb2_queue, vb->index, NULL, NULL); + err = vb2_core_qbuf(vb->vb2_queue, vb, NULL, NULL); WARN_ON_ONCE(err && err != -EIO); mutex_unlock(vb->vb2_queue->lock); } @@ -1562,12 +1559,10 @@ unsigned int vb2_request_buffer_cnt(struct media_request *req) } EXPORT_SYMBOL_GPL(vb2_request_buffer_cnt); -int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) +int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb) { - struct vb2_buffer *vb; int ret; - vb = q->bufs[index]; if (vb->state != VB2_BUF_STATE_DEQUEUED) { dprintk(q, 1, "invalid buffer state %s\n", vb2_state_name(vb->state)); @@ -1654,10 +1649,9 @@ static int vb2_start_streaming(struct vb2_queue *q) return ret; } -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, +int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb, struct media_request *req) { - struct vb2_buffer *vb; enum vb2_buffer_state orig_state; int ret; @@ -1666,8 +1660,6 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, return -EIO; } - vb = q->bufs[index]; - if (!req && vb->state != VB2_BUF_STATE_IN_REQUEST && q->requires_requests) { dprintk(q, 1, "qbuf requires a request\n"); @@ -2240,9 +2232,8 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset, } int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, - unsigned int index, unsigned int plane, unsigned int flags) + struct vb2_buffer *vb, unsigned int plane, unsigned int flags) { - struct vb2_buffer *vb = NULL; struct vb2_plane *vb_plane; int ret; struct dma_buf *dbuf; @@ -2267,13 +2258,6 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, return -EINVAL; } - if (index >= q->num_buffers) { - dprintk(q, 1, "buffer index out of range\n"); - return -EINVAL; - } - - vb = q->bufs[index]; - if (plane >= vb->num_planes) { dprintk(q, 1, "buffer plane out of range\n"); return -EINVAL; @@ -2292,20 +2276,20 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, flags & O_ACCMODE); if (IS_ERR_OR_NULL(dbuf)) { dprintk(q, 1, "failed to export buffer %d, plane %d\n", - index, plane); + vb->index, plane); return -EINVAL; } ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE); if (ret < 0) { dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n", - index, plane, ret); + vb->index, plane, ret); dma_buf_put(dbuf); return ret; } dprintk(q, 3, "buffer %d, plane %d exported as %d descriptor\n", - index, plane, ret); + vb->index, plane, ret); *fd = ret; return 0; @@ -2710,7 +2694,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Queue all buffers. */ for (i = 0; i < q->num_buffers; i++) { - ret = vb2_core_qbuf(q, i, NULL, NULL); + ret = vb2_core_qbuf(q, q->bufs[i], NULL, NULL); if (ret) goto err_reqbufs; fileio->bufs[i].queued = 1; @@ -2895,7 +2879,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ if (copy_timestamp) b->timestamp = ktime_get_ns(); - ret = vb2_core_qbuf(q, index, NULL, NULL); + ret = vb2_core_qbuf(q, b, NULL, NULL); dprintk(q, 5, "vb2_qbuf result: %d\n", ret); if (ret) return ret; @@ -2998,7 +2982,7 @@ static int vb2_thread(void *data) if (copy_timestamp) vb->timestamp = ktime_get_ns(); if (!threadio->stop) - ret = vb2_core_qbuf(q, vb->index, NULL, NULL); + ret = vb2_core_qbuf(q, vb, NULL, NULL); call_void_qop(q, wait_prepare, q); if (ret || threadio->stop) break; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index c7a54d82a55e..d19d82a75ac6 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -364,13 +364,12 @@ static void set_buffer_cache_hints(struct vb2_queue *q, } static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mdev, - struct v4l2_buffer *b, bool is_prepare, - struct media_request **p_req) + struct vb2_buffer *vb, struct v4l2_buffer *b, + bool is_prepare, struct media_request **p_req) { const char *opname = is_prepare ? "prepare_buf" : "qbuf"; struct media_request *req; struct vb2_v4l2_buffer *vbuf; - struct vb2_buffer *vb; int ret; if (b->type != q->type) { @@ -378,23 +377,11 @@ 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; - } - - if (q->bufs[b->index] == NULL) { - /* Should never happen */ - dprintk(q, 1, "%s: buffer is NULL\n", opname); - return -EINVAL; - } - if (b->memory != q->memory) { dprintk(q, 1, "%s: invalid memory type\n", opname); return -EINVAL; } - vb = q->bufs[b->index]; vbuf = to_vb2_v4l2_buffer(vb); ret = __verify_planes_array(vb, b); if (ret) @@ -667,7 +654,7 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b) vb = q->bufs[b->index]; ret = __verify_planes_array(vb, b); if (!ret) - vb2_core_querybuf(q, b->index, b); + vb2_core_querybuf(q, vb, b); return ret; } EXPORT_SYMBOL(vb2_querybuf); @@ -723,6 +710,7 @@ EXPORT_SYMBOL_GPL(vb2_reqbufs); int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, struct v4l2_buffer *b) { + struct vb2_buffer *vb; int ret; if (vb2_fileio_is_active(q)) { @@ -733,9 +721,15 @@ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, if (b->flags & V4L2_BUF_FLAG_REQUEST_FD) return -EINVAL; - ret = vb2_queue_or_prepare_buf(q, mdev, b, true, NULL); + if (b->index >= q->num_buffers) { + dprintk(q, 1, "buffer index out of range\n"); + return -EINVAL; + } + vb = q->bufs[b->index]; - return ret ? ret : vb2_core_prepare_buf(q, b->index, b); + ret = vb2_queue_or_prepare_buf(q, mdev, vb, b, true, NULL); + + return ret ? ret : vb2_core_prepare_buf(q, vb, b); } EXPORT_SYMBOL_GPL(vb2_prepare_buf); @@ -803,6 +797,7 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev, struct v4l2_buffer *b) { struct media_request *req = NULL; + struct vb2_buffer *vb; int ret; if (vb2_fileio_is_active(q)) { @@ -810,10 +805,16 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev, return -EBUSY; } - ret = vb2_queue_or_prepare_buf(q, mdev, b, false, &req); + if (b->index >= q->num_buffers) { + dprintk(q, 1, "buffer index out of range\n"); + return -EINVAL; + } + vb = q->bufs[b->index]; + + ret = vb2_queue_or_prepare_buf(q, mdev, vb, b, false, &req); if (ret) return ret; - ret = vb2_core_qbuf(q, b->index, b, req); + ret = vb2_core_qbuf(q, vb, b, req); if (req) media_request_put(req); return ret; @@ -873,7 +874,15 @@ EXPORT_SYMBOL_GPL(vb2_streamoff); int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb) { - return vb2_core_expbuf(q, &eb->fd, eb->type, eb->index, + struct vb2_buffer *vb; + + if (eb->index >= q->num_buffers) { + dprintk(q, 1, "buffer index out of range\n"); + return -EINVAL; + } + vb = q->bufs[eb->index]; + + return vb2_core_expbuf(q, &eb->fd, eb->type, vb, eb->plane, eb->flags); } EXPORT_SYMBOL_GPL(vb2_expbuf); diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c index 909df82fed33..b322ef179f05 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -360,7 +360,7 @@ int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) dprintk(1, "[%s] buffer index out of range\n", ctx->name); return -EINVAL; } - vb2_core_querybuf(&ctx->vb_q, b->index, b); + vb2_core_querybuf(&ctx->vb_q, q->bufs[b->index], b); dprintk(3, "[%s] index=%d\n", ctx->name, b->index); return 0; } @@ -370,7 +370,7 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp) struct vb2_queue *q = &ctx->vb_q; int ret; - ret = vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, exp->index, + ret = vb2_core_expbuf(&ctx->vb_q, &exp->fd, q->type, q->bufs[exp->index], 0, exp->flags); if (ret) { dprintk(1, "[%s] index=%d errno=%d\n", ctx->name, @@ -391,7 +391,7 @@ int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) dprintk(1, "[%s] buffer index out of range\n", ctx->name); return -EINVAL; } - ret = vb2_core_qbuf(&ctx->vb_q, b->index, b, NULL); + ret = vb2_core_qbuf(&ctx->vb_q, q->bufs[b->index], b, NULL); if (ret) { dprintk(1, "[%s] index=%d errno=%d\n", ctx->name, b->index, ret); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 4b6a9d2ea372..cd3ff1cd759d 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -747,7 +747,7 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q); /** * vb2_core_querybuf() - query video buffer information. * @q: pointer to &struct vb2_queue with videobuf2 queue. - * @index: id number of the buffer. + * @vb: pointer to struct &vb2_buffer. * @pb: buffer struct passed from userspace. * * Videobuf2 core helper to implement VIDIOC_QUERYBUF() operation. It is called @@ -759,7 +759,7 @@ int vb2_wait_for_all_buffers(struct vb2_queue *q); * * Return: returns zero on success; an error code otherwise. */ -void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); +void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb); /** * vb2_core_reqbufs() - Initiate streaming. @@ -823,7 +823,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace * to the kernel. * @q: pointer to &struct vb2_queue with videobuf2 queue. - * @index: id number of the buffer. + * @vb: pointer to struct &vb2_buffer. * @pb: buffer structure passed from userspace to * &v4l2_ioctl_ops->vidioc_prepare_buf handler in driver. * @@ -839,13 +839,13 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * * Return: returns zero on success; an error code otherwise. */ -int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); +int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb); /** * vb2_core_qbuf() - Queue a buffer from userspace * * @q: pointer to &struct vb2_queue with videobuf2 queue. - * @index: id number of the buffer + * @vb: pointer to struct &vb2_buffer. * @pb: buffer structure passed from userspace to * v4l2_ioctl_ops->vidioc_qbuf handler in driver * @req: pointer to &struct media_request, may be NULL. @@ -867,7 +867,7 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); * * Return: returns zero on success; an error code otherwise. */ -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, +int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb, struct media_request *req); /** @@ -931,7 +931,7 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type); * @fd: pointer to the file descriptor associated with DMABUF * (set by driver). * @type: buffer type. - * @index: id number of the buffer. + * @vb: pointer to struct &vb2_buffer. * @plane: index of the plane to be exported, 0 for single plane queues * @flags: file flags for newly created file, as defined at * include/uapi/asm-generic/fcntl.h. @@ -945,7 +945,7 @@ int vb2_core_streamoff(struct vb2_queue *q, unsigned int type); * Return: returns zero on success; an error code otherwise. */ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, - unsigned int index, unsigned int plane, unsigned int flags); + struct vb2_buffer *vb, unsigned int plane, unsigned int flags); /** * vb2_core_queue_init() - initialize a videobuf2 queue From patchwork Thu Oct 19 12:51:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155506 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp358937vqb; Thu, 19 Oct 2023 05:53:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw0QAfRPerNCQyR/pEeIkNi9Wm24MJz8mmidSaFzmkJ+lzFn05ya/rBwFjBKaDGgx+938g X-Received: by 2002:a05:6870:3114:b0:1ea:7c8a:c9dc with SMTP id v20-20020a056870311400b001ea7c8ac9dcmr2381921oaa.26.1697719995258; Thu, 19 Oct 2023 05:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697719995; cv=none; d=google.com; s=arc-20160816; b=NEvhVFyUna251PywyJHMOIGhbKT2pSH5kEF9UXKk4N/I+tZtXaqNJSU35N5Kv1rIQ8 J7gkmWQ1IlmR4IfS8+squ6zqhSeNpVXt8Skq1dWsKpDW0CFwcvva9314I3jS1Nko/tt1 3EGYYk0rbSH1Fq5gnkOBjdp7WETF+S75NmeN8+PdTeaDDGbQkEHq61tW8vKJnGWrRlq/ SGcQvoIj4rfghDnQeFWCjzhz23KbX21JM0345ANKd4ZeI9cf1qMKZU9qYzQpvUYS3PAb CJJJphN7QMphW7XxKZgCUOilP9BtC6Km7LifMcQNPRRpQZZcgAIGC2TCLPkfVMtT7s8T QMbg== 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=IyJJADZSpmqADNeTG6MH8RSOpAUM69lMLg9ZwAA5iIU=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=S09uZ8G63SnbxsT8uo98uj0iZgxtEb1uedi3QBHarRFWsafaAUiJSF4g2IdNkl+JKo Q5MfWw8+fjX1BtYmrrZsXT7tNf6WQihsAZ8iDE8lnyDjIc8ywmSwwxiR0VR/8RVgDjip nvB7xyYaHxZF2778rkEzKwBXZBh518rdzQ7l/9O9TOgZcFnYotgGPv32xFXi7r/Lzm79 ZHJqm79HxOk/2OK8FZffcc2g1ukhNXlwfLdQ8E+4d2FKlT5N4BqACF+tr+VF8bPD1WfZ Sbt2xvkL6fEOAKQ9E7S1R5EwfyRDzygkBRphLSpap8nwL4Ecus7G4JuLbXDdixUXKJS/ F4/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=B3I1uS86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b69-20020a633448000000b005789f552066si4688097pga.335.2023.10.19.05.53.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=B3I1uS86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 A8E3E822D020; Thu, 19 Oct 2023 05:53:13 -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 S1345790AbjJSMw6 (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345730AbjJSMwi (ORCPT ); Thu, 19 Oct 2023 08:52:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17A5B114; Thu, 19 Oct 2023 05:52:34 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 2B9936607337; Thu, 19 Oct 2023 13:52:33 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719953; bh=YAPcE4GwBPzczfVixhAFwcfw6h1irmkzkcxoL2IsBYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B3I1uS864tlgy40Z0xFfI04T4OEbKVAv35Wdc2+26w5Or+LCCFFGP3DWfjGnhK1PT Orh8x50miZvEP66oeJm2KMyvbUUAeE6OjyhlAIt9xTH/YPI68O01KDTdGL04uc6iTo xSAOr2EKabJCDBDURhSZ0GdkX7lhDq/75swziDUNFre1xWz5Kva8qn2AFEvMRNQFxP Gg2dGo9rJkcN5gmXti4qAwenLKY28wLwts23A6ZSLjR0/znX74cn//VWO+u3ejLOJd W4KwwhM3SJYIVyPh5wZn6Qm1RvPzXwAhZj5iUiaR0R6m9vanmEsYO7ZhQgGmhO8Dx3 sTyYdjgeTs2XA== 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 v13 05/56] media: videobuf2: Access vb2_queue bufs array through helper functions Date: Thu, 19 Oct 2023 14:51:31 +0200 Message-Id: <20231019125222.21370-6-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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, 19 Oct 2023 05:53:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188441673771224 X-GMAIL-MSGID: 1780188441673771224 This patch adds 2 helpers functions to add and remove vb2 buffers from a queue. With these 2 and vb2_get_buffer(), bufs field of struct vb2_queue becomes like a private member of the structure. After each call to vb2_get_buffer() we need to be sure that we get a valid pointer in preparation for when buffers can be deleted. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 151 +++++++++++++----- .../media/common/videobuf2/videobuf2-v4l2.c | 50 ++++-- 2 files changed, 149 insertions(+), 52 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 968b7c0e7934..b406a30a9b35 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -408,6 +408,31 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) vb->skip_cache_sync_on_finish = 1; } +/** + * vb2_queue_add_buffer() - add a buffer to a queue + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @vb: pointer to &struct vb2_buffer to be added to the queue. + * @index: index where add vb2_buffer in the queue + */ +static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index) +{ + WARN_ON(index >= VB2_MAX_FRAME || q->bufs[index]); + + q->bufs[index] = vb; + vb->index = index; + vb->vb2_queue = q; +} + +/** + * vb2_queue_remove_buffer() - remove a buffer from a queue + * @vb: pointer to &struct vb2_buffer to be removed from the queue. + */ +static void vb2_queue_remove_buffer(struct vb2_buffer *vb) +{ + vb->vb2_queue->bufs[vb->index] = NULL; + vb->vb2_queue = NULL; +} + /* * __vb2_queue_alloc() - allocate vb2 buffer structures and (for MMAP type) * video buffer memory for all buffers/planes on the queue and initializes the @@ -436,9 +461,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, } vb->state = VB2_BUF_STATE_DEQUEUED; - vb->vb2_queue = q; vb->num_planes = num_planes; - vb->index = q->num_buffers + buffer; vb->type = q->type; vb->memory = memory; init_buffer_cache_hints(q, vb); @@ -446,9 +469,9 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, vb->planes[plane].length = plane_sizes[plane]; vb->planes[plane].min_length = plane_sizes[plane]; } - call_void_bufop(q, init_buffer, vb); - q->bufs[vb->index] = vb; + vb2_queue_add_buffer(q, vb, q->num_buffers + buffer); + call_void_bufop(q, init_buffer, vb); /* Allocate video buffer memory for the MMAP type */ if (memory == VB2_MEMORY_MMAP) { @@ -456,7 +479,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, if (ret) { dprintk(q, 1, "failed allocating memory for buffer %d\n", buffer); - q->bufs[vb->index] = NULL; + vb2_queue_remove_buffer(vb); kfree(vb); break; } @@ -471,7 +494,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, dprintk(q, 1, "buffer %d %p initialization failed\n", buffer, vb); __vb2_buf_mem_free(vb); - q->bufs[vb->index] = NULL; + vb2_queue_remove_buffer(vb); kfree(vb); break; } @@ -494,7 +517,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; ++buffer) { - vb = q->bufs[buffer]; + vb = vb2_get_buffer(q, buffer); if (!vb) continue; @@ -522,7 +545,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) /* Call driver-provided cleanup function for each buffer, if provided */ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; ++buffer) { - struct vb2_buffer *vb = q->bufs[buffer]; + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); if (vb && vb->planes[0].mem_priv) call_void_vb_qop(vb, buf_cleanup, vb); @@ -563,15 +586,20 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) q->cnt_unprepare_streaming = 0; } for (buffer = 0; buffer < q->num_buffers; ++buffer) { - struct vb2_buffer *vb = q->bufs[buffer]; - bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put || - vb->cnt_mem_prepare != vb->cnt_mem_finish || - vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr || - vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf || - vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf || - vb->cnt_buf_queue != vb->cnt_buf_done || - vb->cnt_buf_prepare != vb->cnt_buf_finish || - vb->cnt_buf_init != vb->cnt_buf_cleanup; + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + bool unbalanced; + + if (!vb) + continue; + + unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put || + vb->cnt_mem_prepare != vb->cnt_mem_finish || + vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr || + vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf || + vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf || + vb->cnt_buf_queue != vb->cnt_buf_done || + vb->cnt_buf_prepare != vb->cnt_buf_finish || + vb->cnt_buf_init != vb->cnt_buf_cleanup; if (unbalanced) { pr_info("unbalanced counters for queue %p, buffer %d:\n", @@ -611,8 +639,13 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) /* Free vb2 buffers */ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; ++buffer) { - kfree(q->bufs[buffer]); - q->bufs[buffer] = NULL; + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + + if (!vb) + continue; + + vb2_queue_remove_buffer(vb); + kfree(vb); } q->num_buffers -= buffers; @@ -648,7 +681,12 @@ static bool __buffers_in_use(struct vb2_queue *q) { unsigned int buffer; for (buffer = 0; buffer < q->num_buffers; ++buffer) { - if (vb2_buffer_in_use(q, q->bufs[buffer])) + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + + if (!vb) + continue; + + if (vb2_buffer_in_use(q, vb)) return true; } return false; @@ -1633,7 +1671,11 @@ static int vb2_start_streaming(struct vb2_queue *q) * correctly return them to vb2. */ for (i = 0; i < q->num_buffers; ++i) { - vb = q->bufs[i]; + vb = vb2_get_buffer(q, i); + + if (!vb) + continue; + if (vb->state == VB2_BUF_STATE_ACTIVE) vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED); } @@ -2034,12 +2076,18 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * to vb2 in stop_streaming(). */ if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { - for (i = 0; i < q->num_buffers; ++i) - if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) { - pr_warn("driver bug: stop_streaming operation is leaving buf %p in active state\n", - q->bufs[i]); - vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR); + for (i = 0; i < q->num_buffers; ++i) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); + + if (!vb) + continue; + + if (vb->state == VB2_BUF_STATE_ACTIVE) { + pr_warn("driver bug: stop_streaming operation is leaving buffer %u in active state\n", + vb->index); + vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); } + } /* Must be zero now */ WARN_ON(atomic_read(&q->owned_by_drv_count)); } @@ -2073,9 +2121,14 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). */ for (i = 0; i < q->num_buffers; ++i) { - struct vb2_buffer *vb = q->bufs[i]; - struct media_request *req = vb->req_obj.req; + struct vb2_buffer *vb; + struct media_request *req; + vb = vb2_get_buffer(q, i); + if (!vb) + continue; + + req = vb->req_obj.req; /* * If a request is associated with this buffer, then * call buf_request_cancel() to give the driver to complete() @@ -2224,10 +2277,12 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset, buffer = (offset >> PLANE_INDEX_SHIFT) & BUFFER_INDEX_MASK; *plane = (offset >> PAGE_SHIFT) & PLANE_INDEX_MASK; - if (buffer >= q->num_buffers || *plane >= q->bufs[buffer]->num_planes) + *vb = vb2_get_buffer(q, buffer); + if (!*vb) + return -EINVAL; + if (*plane >= (*vb)->num_planes) return -EINVAL; - *vb = q->bufs[buffer]; return 0; } @@ -2615,6 +2670,7 @@ struct vb2_fileio_data { static int __vb2_init_fileio(struct vb2_queue *q, int read) { struct vb2_fileio_data *fileio; + struct vb2_buffer *vb; int i, ret; unsigned int count = 0; @@ -2665,11 +2721,18 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) if (ret) goto err_kfree; + /* + * Userspace can never add or delete buffers later, so there + * will never be holes. It is safe to assume that vb2_get_buffer(q, 0) + * will always return a valid vb pointer + */ + vb = vb2_get_buffer(q, 0); + /* * Check if plane_count is correct * (multiplane buffers are not supported). */ - if (q->bufs[0]->num_planes != 1) { + if (vb->num_planes != 1) { ret = -EBUSY; goto err_reqbufs; } @@ -2678,12 +2741,15 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Get kernel address of each buffer. */ for (i = 0; i < q->num_buffers; i++) { - fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0); + /* vb can never be NULL when using fileio. */ + vb = vb2_get_buffer(q, i); + + fileio->bufs[i].vaddr = vb2_plane_vaddr(vb, 0); if (fileio->bufs[i].vaddr == NULL) { ret = -EINVAL; goto err_reqbufs; } - fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0); + fileio->bufs[i].size = vb2_plane_size(vb, 0); } /* @@ -2811,15 +2877,17 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ fileio->cur_index = index; buf = &fileio->bufs[index]; - b = q->bufs[index]; + + /* b can never be NULL when using fileio. */ + b = vb2_get_buffer(q, index); /* * Get number of bytes filled by the driver */ buf->pos = 0; buf->queued = 0; - buf->size = read ? vb2_get_plane_payload(q->bufs[index], 0) - : vb2_plane_size(q->bufs[index], 0); + buf->size = read ? vb2_get_plane_payload(b, 0) + : vb2_plane_size(b, 0); /* Compensate for data_offset on read in the multiplanar case. */ if (is_multiplanar && read && b->planes[0].data_offset < buf->size) { @@ -2862,7 +2930,8 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ * Queue next buffer if required. */ if (buf->pos == buf->size || (!read && fileio->write_immediately)) { - struct vb2_buffer *b = q->bufs[index]; + /* b can never be NULL when using fileio. */ + struct vb2_buffer *b = vb2_get_buffer(q, index); /* * Check if this is the last buffer to read. @@ -2889,7 +2958,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ */ buf->pos = 0; buf->queued = 1; - buf->size = vb2_plane_size(q->bufs[index], 0); + buf->size = vb2_plane_size(b, 0); fileio->q_count += 1; /* * If we are queuing up buffers for the first time, then @@ -2960,7 +3029,9 @@ static int vb2_thread(void *data) * Call vb2_dqbuf to get buffer back. */ if (prequeue) { - vb = q->bufs[index++]; + vb = vb2_get_buffer(q, index++); + if (!vb) + continue; prequeue--; } else { call_void_qop(q, wait_finish, q); @@ -2969,7 +3040,7 @@ static int vb2_thread(void *data) call_void_qop(q, wait_prepare, q); dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret); if (!ret) - vb = q->bufs[index]; + vb = vb2_get_buffer(q, index); } if (ret || threadio->stop) break; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index d19d82a75ac6..2ffb097bf00a 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -377,6 +377,12 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md return -EINVAL; } + vb = vb2_get_buffer(q, b->index); + if (!vb) { + dprintk(q, 1, "%s: buffer %u is NULL\n", opname, b->index); + return -EINVAL; + } + if (b->memory != q->memory) { dprintk(q, 1, "%s: invalid memory type\n", opname); return -EINVAL; @@ -615,11 +621,22 @@ static const struct vb2_buf_ops v4l2_buf_ops = { struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp) { unsigned int i; + struct vb2_buffer *vb2; - for (i = 0; i < q->num_buffers; i++) - if (q->bufs[i]->copied_timestamp && - q->bufs[i]->timestamp == timestamp) - return vb2_get_buffer(q, i); + /* + * This loop doesn't scale if there is a really large number of buffers. + * Maybe something more efficient will be needed in this case. + */ + for (i = 0; i < q->num_buffers; i++) { + vb2 = vb2_get_buffer(q, i); + + if (!vb2) + continue; + + if (vb2->copied_timestamp && + vb2->timestamp == timestamp) + return vb2; + } return NULL; } EXPORT_SYMBOL_GPL(vb2_find_buffer); @@ -647,11 +664,12 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b) return -EINVAL; } - if (b->index >= q->num_buffers) { - dprintk(q, 1, "buffer index out of range\n"); + vb = vb2_get_buffer(q, b->index); + if (!vb) { + dprintk(q, 1, "can't find the requested buffer %u\n", b->index); return -EINVAL; } - vb = q->bufs[b->index]; + ret = __verify_planes_array(vb, b); if (!ret) vb2_core_querybuf(q, vb, b); @@ -721,11 +739,11 @@ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, if (b->flags & V4L2_BUF_FLAG_REQUEST_FD) return -EINVAL; - if (b->index >= q->num_buffers) { - dprintk(q, 1, "buffer index out of range\n"); + vb = vb2_get_buffer(q, b->index); + if (!vb) { + dprintk(q, 1, "can't find the requested buffer %u\n", b->index); return -EINVAL; } - vb = q->bufs[b->index]; ret = vb2_queue_or_prepare_buf(q, mdev, vb, b, true, NULL); @@ -809,7 +827,11 @@ int vb2_qbuf(struct vb2_queue *q, struct media_device *mdev, dprintk(q, 1, "buffer index out of range\n"); return -EINVAL; } - vb = q->bufs[b->index]; + vb = vb2_get_buffer(q, b->index); + if (!vb) { + dprintk(q, 1, "can't find the requested buffer %u\n", b->index); + return -EINVAL; + } ret = vb2_queue_or_prepare_buf(q, mdev, vb, b, false, &req); if (ret) @@ -880,7 +902,11 @@ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb) dprintk(q, 1, "buffer index out of range\n"); return -EINVAL; } - vb = q->bufs[eb->index]; + vb = vb2_get_buffer(q, eb->index); + if (!vb) { + dprintk(q, 1, "can't find the requested buffer %u\n", eb->index); + return -EINVAL; + } return vb2_core_expbuf(q, &eb->fd, eb->type, vb, eb->plane, eb->flags); From patchwork Thu Oct 19 12:51:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp358829vqb; Thu, 19 Oct 2023 05:53:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJZJgrzK/GotULtgredPmTklD/0L4WKbigicbQiwVEWnB6/CcNq7rXLtQ0BiA9UxM0GUiO X-Received: by 2002:a05:6a21:47c6:b0:15e:b8a1:57b9 with SMTP id as6-20020a056a2147c600b0015eb8a157b9mr1768233pzc.24.1697719981852; Thu, 19 Oct 2023 05:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697719981; cv=none; d=google.com; s=arc-20160816; b=cYOnSPmdxVAQMdgRIcouo6DcQPJ/HkKJM51qIcHphR/0A05ZR20vF1hdj6sY+JnMSc CgSzULaukFX5eC/ncCnlnK4Ia7LG3vTNm8dCz3BMMmDQqCrX7EuCupvOrXosiDysWsEN QV96EVK6U3sP9UIHrXakafWvCZs9wKE/eRongNt/sITSjzCsBp9ZdripSVAHu1inqdBw P4yNYmwLFzjkRSrSeEtey44rDi554avXApuS1iU0p5GKddHNv4kDMiQ4RqJBSTVM5QDB 7Sk24G2QFrIS7dKPlUpRapCmNW+fUv+GiPvLU+spkt7cQjatUqs4A/ucVdnX2h7czgAc SNdw== 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=Y6AR+miMPP121mWIcGoHC27lbGw2XaVJcw9mhisXWqg=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=NiQ0+09tkSrAN9d1E6NGOfKB+LULj+cDDn8/WVfXHC3aul0VhzanM+dFvnErJ4C3H2 cLTXH/mrk0OHMS1OW9fxLKt+NBJfBMyNRASmobRmI/bR2BLr0mxGwSHva+rOktczlLhZ 8W8/uhTonZjZESyJ1vzDFfj5cY6JO3uEDRIKYdlg26Iwo7KPhVs48IeZIvP5ehx1iifL XLP9gz7/dMAfeKCRklq5TJrJ1TgAsw+I6sS4uCtWWkOdqmgtDC1EplA1uxAugHJW8sEw eZKcvEZCm0EMt0D5/3KgGAxmjKo13J2auyPMbvzGkR0FaL+S+cml4GdfrXiitQU/Urmg Spew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=UAgRcnQ8; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id c27-20020a631c1b000000b0058555ea0a21si4407627pgc.571.2023.10.19.05.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:01 -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=UAgRcnQ8; 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 4876D822CFA7; Thu, 19 Oct 2023 05:52:58 -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 S1345787AbjJSMwp (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345374AbjJSMwg (ORCPT ); Thu, 19 Oct 2023 08:52:36 -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 327A8119; Thu, 19 Oct 2023 05:52:35 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 A7ED8660733B; Thu, 19 Oct 2023 13:52:33 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719954; bh=u0/tUxGMIK/59pYU6cqm9FB8VhmlcNZDctLEaz6jcAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UAgRcnQ8C3IP76jLgwmGlm4Nrrh9/Xtp3WDe6OOVohY3419w5F4ZVy4bmzkI7xCx7 b6wtFrVpb00XxyHK9nHNvsJG6SughwbpeKq1NvQrbHKU/JG+qcBbnUP6zcsA+6AkQu ktbcjl1o9mvYxUgw1kagqP9pTiMnhYF0/gJ0NuehHywsdrYWJlQuoOfyVl25xDkGrP gm2itye59nyHHHfYuaZP17ttiHx1Ovz3S2LZ3dzOsivJj5DncXt43Xk4Ij4uOgaMi3 zslTKMAvNb9Z5evHrv78GiVOCpdCr0+UWqQCOfJHXXmJdJqX/fA0rOZe6HXV0AG8xC EBRKAmzZpuskg== 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 v13 06/56] media: videobuf2: Remove duplicated index vs q->num_buffers check Date: Thu, 19 Oct 2023 14:51:32 +0200 Message-Id: <20231019125222.21370-7-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, URIBL_BLOCKED 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, 19 Oct 2023 05:52:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188427557894552 X-GMAIL-MSGID: 1780188427557894552 vb2_get_buffer() already checks if the requested index is valid. Stop duplicating this kind of check everywhere. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-v4l2.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 2ffb097bf00a..c6ebc8d2c537 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -823,10 +823,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 %u\n", b->index); @@ -898,10 +894,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 %u\n", eb->index); From patchwork Thu Oct 19 12:51:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155514 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359483vqb; Thu, 19 Oct 2023 05:54:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+EdVkOwzkZSd0YV/hciiJmq+DaOOi5/MAGK+uVZAUt5XBjtWONOzOUVqA2KBIvHcdZKX+ X-Received: by 2002:a05:6a20:4295:b0:14d:6309:fc96 with SMTP id o21-20020a056a20429500b0014d6309fc96mr2189664pzj.4.1697720067576; Thu, 19 Oct 2023 05:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720067; cv=none; d=google.com; s=arc-20160816; b=aJQoTxGzzF/CPTccqER1G6mXqH5i1QUqSxsXh1VON+stpEInwPf5cLl3+d2Tc7i3cM udmYTe3o3Nx6GlMGbiHHA3tg2Q+PvaXaq3Gs4RjrcUAwcsFHh8DIqKI49HnBlvDpU51E lq0UiEL+1zjw5YDGI2jZNNOos36BISdCUFBFornKmukMg1i74EWOXkIRFOvXFYrBIZ7L 9d8mamB32UtrDYALhgkicy81rOGVpRndH8zwsPv5slCakVkRgERqQWnQkdCeHQA9D4ba MA0awkfeT8m36KQdBjTaRX7TzLn388YEjkhUrmmbJl1L6Zo8NYzb++wcQ22jM+gW6AEI dLTg== 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=UcK1M6ba+qPsIpOiLnurj5VZil6Dh9wjABNphkn5ocE=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=mNqnimycAE+tFaG7hVMr997zlb6uaLXK7MWVWeAldzV5zLE5rthq1c+PuODQTc1ZbI MqQ8LZdc9MSo1Q/lZCfewU9nJeQAtmNBewz4VbLA0OVaNBANi94Jy/AaXMkDd8LChnw8 ZtLLkKdp6RJfHRLCMhap+v7Fa+j0z8vkaaFt561RTksctgbCkiSi982Fiw56OlEDbFF2 1uLVRVPJjYRAmkTq2bKj+k+V4Gwvy5TgdtSr3ZFG/ljhJ+uhMCL85P45Ruu+4E9ywTVW MoOlwehxNH2kjtJgiSSPJGprbwKwyutrSRm45BEL1IRYaNQxZXJqRoWCBJD4iN/6V0hE Z/Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=FVNQYpwd; 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 p17-20020a639511000000b00573fc6de956si3208894pgd.223.2023.10.19.05.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:54:27 -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=FVNQYpwd; 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 589D081ADCC3; Thu, 19 Oct 2023 05:54:18 -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 S1345895AbjJSMxH (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345728AbjJSMwi (ORCPT ); Thu, 19 Oct 2023 08:52:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A47A7112; Thu, 19 Oct 2023 05:52:35 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 30B06660733F; Thu, 19 Oct 2023 13:52:34 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719954; bh=lM3wXK65Q+RBpyeYExb53Y3bnLmIcGL+rErhrVO2B80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FVNQYpwdc8DuSqvFyyhSDk4fL8gSr6zFuuBoaMyQuyI8raxmb86EuMNyJyYiaASMO w0xlmdpID1lTgcgb2q8P5/fMHUzPRnHWRoVKp4wUn3J3jJIL4lLIXi92nqfgKTgHzG T6euM+j9iaNxZWt2XKA9GNEP33kwhnVlalGfFBiLMGSUx07i05FkfC51+w1QDLMM2d 68ngutdxllUtGK9SCJ/nOTblUnwOj0oVsbTzpJKUZ3AJAaQqjoJcTXbja1KTv5Av49 7W9VgqnH9p89g3TPNngbgzsRW1imM+gM+bUiTimEUyKFVeDfbWwE9OxSW9FGcReLM6 v+v4Oqqe8KLFw== 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 v13 07/56] media: videobuf2: Add helper to get queue number of buffers Date: Thu, 19 Oct 2023 14:51:33 +0200 Message-Id: <20231019125222.21370-8-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:54:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188517352262231 X-GMAIL-MSGID: 1780188517352262231 In the future a side effect of introducing DELETE_BUFS ioctl is the create of 'holes' (i.e. unused buffers) in bufs arrays. To know which entries of the bufs arrays are used a bitmap will be added in struct vb2_queue. That will also mean that the number of buffers will be computed given the number of bit set in this bitmap. To smoothly allow this evolution all drives must stop using directly num_buffers field from struct vb2_queue. Signed-off-by: Benjamin Gaignard --- include/media/videobuf2-core.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index cd3ff1cd759d..8f9d9e4af5b1 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -1139,6 +1139,15 @@ static inline bool vb2_fileio_is_active(struct vb2_queue *q) return q->fileio; } +/** + * vb2_get_num_buffers() - get the number of buffer in a queue + * @q: pointer to &struct vb2_queue with videobuf2 queue. + */ +static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q) +{ + return q->num_buffers; +} + /** * vb2_is_busy() - return busy status of the queue. * @q: pointer to &struct vb2_queue with videobuf2 queue. @@ -1147,7 +1156,7 @@ static inline bool vb2_fileio_is_active(struct vb2_queue *q) */ static inline bool vb2_is_busy(struct vb2_queue *q) { - return (q->num_buffers > 0); + return vb2_get_num_buffers(q) > 0; } /** From patchwork Thu Oct 19 12:51:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359218vqb; Thu, 19 Oct 2023 05:53:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGLBq/Qj1/8xrSFDn7ByrgD3v4YckXegONT+mhTx+PiCJolZjWHuHaDJWKF2Ho70oIMnl1 X-Received: by 2002:a17:90a:5185:b0:27c:f1f8:2628 with SMTP id u5-20020a17090a518500b0027cf1f82628mr1965891pjh.47.1697720032836; Thu, 19 Oct 2023 05:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720032; cv=none; d=google.com; s=arc-20160816; b=nyDMqsFgtrGBtUdgXEMPUU8sVHDMJeKUN6RDIyYmCk4UeSj1JdVfdJkrOCcqiDeU+k 6lqrL2qme/fjno1BAYku7aKTeajMZyX0l8FSG7VNIeWapOYVcAz1rOfEguTmMjuKUKIc PMnOtZJ0W33dXQz05rbn3vgpkXihONxC2FcUJfzhdHTmeJAaVbtx0bc9uCMKGfBAGBtD RZbUXma7O6MxOZ0SKwcRG91jFy5wrvJfIx+XoSSFvZQ91Lx6lsmEywxSFBvnHx4UjmJM smOCV9cgqBCFl3J3lj34hQNJPavlF6zuwFdueDrihgtk5FeylqPtyNURlheZ2NHQdbX4 6vbw== 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=iWmHL8Of6DBw/g3XEBJR3E+ZMFz/yY6lkptLTAnFnAY=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=NKbCApgVeZJxHG3QQzCMjxzSkUwTw1xJ37V9pMyBxG8klk+vxC2rR7LUaP014WadbQ VddCr62LeFpaoEMzJSED8hbjMFaEJhmdRkOqBILE/YoDtXqHyYOOZoilzR98lDxeEljh 0vO06imtbJJ2ButL4c8DlMzUng0Nv2N9F9dROYdUbiME/80I6qkYHKrCyd8O8cHr7/CX rnoFwSwouvN36xHh13vIHepnCFQwTCwumLQvi0Af2OK6VCWsophLlxXsNbyxtxRm99ja W4sWoQZ74v+sbBe27Wak6D8NJNVp2onmgJd+12gM2jSnHobr0ofXqhUxNMcCcuS/Lox8 m8lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NT3rFbaL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id z21-20020a17090ab11500b002790fa91d77si2092819pjq.145.2023.10.19.05.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NT3rFbaL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 5A4D280A9E11; Thu, 19 Oct 2023 05:53:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345931AbjJSMxQ (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345746AbjJSMwj (ORCPT ); Thu, 19 Oct 2023 08:52:39 -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 3CADA115; Thu, 19 Oct 2023 05:52:36 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 A86F86607341; Thu, 19 Oct 2023 13:52:34 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719955; bh=DeELvsvGfX8ufPLrGM7lR1Bfmn8jvw7ej7nSKD+mebw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NT3rFbaLac+W+nlACtRlThRPNEkJ/LM2tLRRqz3KsPCV5V3jG3hvQi7sSlgCQmOFU YtCZEk8TKiNir2o84JP3qBwcK24c0bQXDRJfh0BILDXeTtw0bc23n189BFu0MdIbxO SfEgXPLAgRudP85UkhJh9s1e+LsnmfgE1x2A16oc8tVcPuTh5ux3W7BmrnuZO/fqMy eUq3ItE0byZIHfNEx66Cu+3s/o957klD+43O9KWhGYEb1FN1AR8+vaIgvOW78sTNym 8+l+TBSMq+12KOw8Se0x/l78vKHi7eZSKYsXssGiicMXESotZjD9Ld9hckTznEhWdh Y+UrDc2/scbXw== 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 v13 08/56] media: videobuf2: Use vb2_get_num_buffers() helper Date: Thu, 19 Oct 2023 14:51:34 +0200 Message-Id: <20231019125222.21370-9-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:53:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188481144945216 X-GMAIL-MSGID: 1780188481144945216 Stop using queue num_buffers field directly, instead use vb2_get_num_buffers(). This prepares for the future 'delete buffers' feature where there are holes in the buffer indices. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 92 +++++++++++-------- .../media/common/videobuf2/videobuf2-v4l2.c | 4 +- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index b406a30a9b35..c5c5ae4d213d 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -444,13 +444,14 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, unsigned int num_buffers, unsigned int num_planes, const unsigned plane_sizes[VB2_MAX_PLANES]) { + unsigned int q_num_buffers = vb2_get_num_buffers(q); unsigned int buffer, plane; struct vb2_buffer *vb; int ret; /* Ensure that q->num_buffers+num_buffers is below VB2_MAX_FRAME */ num_buffers = min_t(unsigned int, num_buffers, - VB2_MAX_FRAME - q->num_buffers); + VB2_MAX_FRAME - q_num_buffers); for (buffer = 0; buffer < num_buffers; ++buffer) { /* Allocate vb2 buffer structures */ @@ -470,7 +471,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, vb->planes[plane].min_length = plane_sizes[plane]; } - vb2_queue_add_buffer(q, vb, q->num_buffers + buffer); + vb2_queue_add_buffer(q, vb, q_num_buffers + buffer); call_void_bufop(q, init_buffer, vb); /* Allocate video buffer memory for the MMAP type */ @@ -514,8 +515,9 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) { unsigned int buffer; struct vb2_buffer *vb; + unsigned int q_num_buffers = vb2_get_num_buffers(q); - for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; + for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; ++buffer) { vb = vb2_get_buffer(q, buffer); if (!vb) @@ -539,11 +541,12 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) { unsigned int buffer; + unsigned int q_num_buffers = vb2_get_num_buffers(q); lockdep_assert_held(&q->mmap_lock); /* Call driver-provided cleanup function for each buffer, if provided */ - for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; + for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; ++buffer) { struct vb2_buffer *vb = vb2_get_buffer(q, buffer); @@ -559,7 +562,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) * Check that all the calls were balanced during the life-time of this * queue. If not then dump the counters to the kernel log. */ - if (q->num_buffers) { + if (q_num_buffers) { bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || q->cnt_prepare_streaming != q->cnt_unprepare_streaming || q->cnt_wait_prepare != q->cnt_wait_finish; @@ -585,7 +588,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) q->cnt_stop_streaming = 0; q->cnt_unprepare_streaming = 0; } - for (buffer = 0; buffer < q->num_buffers; ++buffer) { + for (buffer = 0; buffer < vb2_get_num_buffers(q); buffer++) { struct vb2_buffer *vb = vb2_get_buffer(q, buffer); bool unbalanced; @@ -637,7 +640,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) #endif /* Free vb2 buffers */ - for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; + for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; ++buffer) { struct vb2_buffer *vb = vb2_get_buffer(q, buffer); @@ -649,7 +652,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) } q->num_buffers -= buffers; - if (!q->num_buffers) { + if (!vb2_get_num_buffers(q)) { q->memory = VB2_MEMORY_UNKNOWN; INIT_LIST_HEAD(&q->queued_list); } @@ -680,7 +683,7 @@ EXPORT_SYMBOL(vb2_buffer_in_use); static bool __buffers_in_use(struct vb2_queue *q) { unsigned int buffer; - for (buffer = 0; buffer < q->num_buffers; ++buffer) { + for (buffer = 0; buffer < vb2_get_num_buffers(q); ++buffer) { struct vb2_buffer *vb = vb2_get_buffer(q, buffer); if (!vb) @@ -806,6 +809,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count) { unsigned int num_buffers, allocated_buffers, num_planes = 0; + unsigned int q_num_bufs = vb2_get_num_buffers(q); unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; unsigned int i; @@ -821,7 +825,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, return -EBUSY; } - if (*count == 0 || q->num_buffers != 0 || + if (*count == 0 || q_num_bufs != 0 || (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory) || !verify_coherency_flags(q, non_coherent_mem)) { /* @@ -839,7 +843,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_buffers); + __vb2_queue_free(q, q_num_bufs); mutex_unlock(&q->mmap_lock); /* @@ -934,7 +938,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, if (ret < 0) { /* * Note: __vb2_queue_free() will subtract 'allocated_buffers' - * from q->num_buffers and it will reset q->memory to + * from already queued buffers and it will reset q->memory to * VB2_MEMORY_UNKNOWN. */ __vb2_queue_free(q, allocated_buffers); @@ -968,10 +972,11 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int num_planes = 0, num_buffers, allocated_buffers; unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; - bool no_previous_buffers = !q->num_buffers; - int ret; + unsigned int q_num_bufs = vb2_get_num_buffers(q); + bool no_previous_buffers = !q_num_bufs; + int ret = 0; - if (q->num_buffers == VB2_MAX_FRAME) { + if (q_num_bufs == VB2_MAX_FRAME) { dprintk(q, 1, "maximum number of buffers already allocated\n"); return -ENOBUFS; } @@ -1000,7 +1005,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return -EINVAL; } - num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers); + num_buffers = min(*count, VB2_MAX_FRAME - q_num_bufs); if (requested_planes && requested_sizes) { num_planes = requested_planes; @@ -1032,7 +1037,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, num_buffers = allocated_buffers; /* - * q->num_buffers contains the total number of buffers, that the + * num_buffers contains the total number of buffers, that the * queue driver has set up */ ret = call_qop(q, queue_setup, q, &num_buffers, @@ -1053,7 +1058,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, if (ret < 0) { /* * Note: __vb2_queue_free() will subtract 'allocated_buffers' - * from q->num_buffers and it will reset q->memory to + * from already queued buffers and it will reset q->memory to * VB2_MEMORY_UNKNOWN. */ __vb2_queue_free(q, allocated_buffers); @@ -1670,7 +1675,7 @@ static int vb2_start_streaming(struct vb2_queue *q) * Forcefully reclaim buffers if the driver did not * correctly return them to vb2. */ - for (i = 0; i < q->num_buffers; ++i) { + for (i = 0; i < vb2_get_num_buffers(q); ++i) { vb = vb2_get_buffer(q, i); if (!vb) @@ -2076,7 +2081,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * to vb2 in stop_streaming(). */ if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { - for (i = 0; i < q->num_buffers; ++i) { + for (i = 0; i < vb2_get_num_buffers(q); i++) { struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) @@ -2120,7 +2125,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * call to __fill_user_buffer() after buf_finish(). That order can't * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). */ - for (i = 0; i < q->num_buffers; ++i) { + for (i = 0; i < vb2_get_num_buffers(q); i++) { struct vb2_buffer *vb; struct media_request *req; @@ -2168,6 +2173,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) int vb2_core_streamon(struct vb2_queue *q, unsigned int type) { + unsigned int q_num_bufs = vb2_get_num_buffers(q); int ret; if (type != q->type) { @@ -2180,12 +2186,12 @@ int vb2_core_streamon(struct vb2_queue *q, unsigned int type) return 0; } - if (!q->num_buffers) { + if (!q_num_bufs) { dprintk(q, 1, "no buffers have been allocated\n"); return -EINVAL; } - if (q->num_buffers < q->min_buffers_needed) { + if (q_num_bufs < q->min_buffers_needed) { dprintk(q, 1, "need at least %u allocated buffers\n", q->min_buffers_needed); return -EINVAL; @@ -2513,7 +2519,8 @@ 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->num_buffers); + __vb2_queue_free(q, vb2_get_num_buffers(q)); + q->num_buffers = 0; mutex_unlock(&q->mmap_lock); } EXPORT_SYMBOL_GPL(vb2_core_queue_release); @@ -2542,7 +2549,7 @@ __poll_t vb2_core_poll(struct vb2_queue *q, struct file *file, /* * Start file I/O emulator only if streaming API has not been used yet. */ - if (q->num_buffers == 0 && !vb2_fileio_is_active(q)) { + if (vb2_get_num_buffers(q) == 0 && !vb2_fileio_is_active(q)) { if (!q->is_output && (q->io_modes & VB2_READ) && (req_events & (EPOLLIN | EPOLLRDNORM))) { if (__vb2_init_fileio(q, 1)) @@ -2580,7 +2587,7 @@ __poll_t vb2_core_poll(struct vb2_queue *q, struct file *file, * For output streams you can call write() as long as there are fewer * buffers queued than there are buffers available. */ - if (q->is_output && q->fileio && q->queued_count < q->num_buffers) + if (q->is_output && q->fileio && q->queued_count < vb2_get_num_buffers(q)) return EPOLLOUT | EPOLLWRNORM; if (list_empty(&q->done_list)) { @@ -2629,8 +2636,8 @@ struct vb2_fileio_buf { * struct vb2_fileio_data - queue context used by file io emulator * * @cur_index: the index of the buffer currently being read from or - * written to. If equal to q->num_buffers then a new buffer - * must be dequeued. + * written to. If equal to number of already queued buffers + * then a new buffer must be dequeued. * @initial_index: in the read() case all buffers are queued up immediately * in __vb2_init_fileio() and __vb2_perform_fileio() just cycles * buffers. However, in the write() case no buffers are initially @@ -2640,7 +2647,7 @@ struct vb2_fileio_buf { * buffers. This means that initially __vb2_perform_fileio() * needs to know what buffer index to use when it is queuing up * the buffers for the first time. That initial index is stored - * in this field. Once it is equal to q->num_buffers all + * in this field. Once it is equal to num_buffers all * available buffers have been queued and __vb2_perform_fileio() * should start the normal dequeue/queue cycle. * @@ -2690,7 +2697,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) /* * Check if streaming api has not been already activated. */ - if (q->streaming || q->num_buffers > 0) + if (q->streaming || vb2_get_num_buffers(q) > 0) return -EBUSY; /* @@ -2740,7 +2747,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) /* * Get kernel address of each buffer. */ - for (i = 0; i < q->num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(q); i++) { /* vb can never be NULL when using fileio. */ vb = vb2_get_buffer(q, i); @@ -2759,18 +2766,23 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) /* * Queue all buffers. */ - for (i = 0; i < q->num_buffers; i++) { - ret = vb2_core_qbuf(q, q->bufs[i], NULL, NULL); + for (i = 0; i < vb2_get_num_buffers(q); i++) { + struct vb2_buffer *vb2 = vb2_get_buffer(q, i); + + if (!vb2) + continue; + + ret = vb2_core_qbuf(q, vb2, NULL, NULL); if (ret) goto err_reqbufs; fileio->bufs[i].queued = 1; } /* * All buffers have been queued, so mark that by setting - * initial_index to q->num_buffers + * initial_index to num_buffers */ - fileio->initial_index = q->num_buffers; - fileio->cur_index = q->num_buffers; + fileio->initial_index = vb2_get_num_buffers(q); + fileio->cur_index = fileio->initial_index; } /* @@ -2964,12 +2976,12 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ * If we are queuing up buffers for the first time, then * increase initial_index by one. */ - if (fileio->initial_index < q->num_buffers) + if (fileio->initial_index < vb2_get_num_buffers(q)) fileio->initial_index++; /* * The next buffer to use is either a buffer that's going to be - * queued for the first time (initial_index < q->num_buffers) - * or it is equal to q->num_buffers, meaning that the next + * queued for the first time (initial_index < num_buffers) + * or it is equal to num_buffers, meaning that the next * time we need to dequeue a buffer since we've now queued up * all the 'first time' buffers. */ @@ -3016,7 +3028,7 @@ static int vb2_thread(void *data) int ret = 0; if (q->is_output) { - prequeue = q->num_buffers; + prequeue = vb2_get_num_buffers(q); copy_timestamp = q->copy_timestamp; } diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index c6ebc8d2c537..7d798fb15c0b 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -627,7 +627,7 @@ struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp) * This loop doesn't scale if there is a really large number of buffers. * Maybe something more efficient will be needed in this case. */ - for (i = 0; i < q->num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(q); i++) { vb2 = vb2_get_buffer(q, i); if (!vb2) @@ -761,7 +761,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) fill_buf_caps(q, &create->capabilities); validate_memory_flags(q, create->memory, &create->flags); - create->index = q->num_buffers; + create->index = vb2_get_num_buffers(q); if (create->count == 0) return ret != -EBUSY ? ret : 0; From patchwork Thu Oct 19 12:51:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp358922vqb; Thu, 19 Oct 2023 05:53:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEF1HsZIE5+3vUAQlPiemA3++BsoAKB2RRrcvi6htOTQtS32SdayJ2hUwz6tqCAvwfxhdmP X-Received: by 2002:a9d:6c95:0:b0:6bd:c7c3:aac2 with SMTP id c21-20020a9d6c95000000b006bdc7c3aac2mr2165498otr.18.1697719993416; Thu, 19 Oct 2023 05:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697719993; cv=none; d=google.com; s=arc-20160816; b=zh7Kfo1iWoX4xdug1arNSWIfcZuBVNcK7IiGBk7CJbMFnjrN4WAw9BVaiySuFj2zdq fH1x4Mzm5QG3k9QfnCD1xGjpJ6gqyBcqRt6Gc7mScl4r5Adi+j1t72OGnqnNZQoGcIsT jqHqiUwmnPLYWDAM8Vhg9wfi/+9e5cFdCYQDsIRmMHlpeAfyelchZLbKT1vwOLnWnK5M 1jzzbBS36VvcQAArsaPUJ8C15xmKuy/qMFFSpXXSdTmr+n4WgEQ6h7T3A6d6BF+ermtU 4BE/9cXJ2lodZV7CvNu1ekU5VD4oTotCBpR+wvmeQSrdv4LYIflq6/mX5nU4yoCbBaOn QOhA== 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=dlNPY6ibXmdkraUjakRUfz9D8ble9LZN70JvmimE7r4=; fh=YhVWgOX82fKLE5M+MoEX/CwrdcPd8SQ1dctjbZBk3rU=; b=C8o1mnnVntf/n4Cdu+Uu4nI6UJ3npIi0Nvpg7mfr+g+5kthXtuC6VsWHqNV+Nzu/mW uaPECN5BvokP+2T0A4CdFORVABkcufViD13Kf2tAzt8uv9xridr9VcShj9vT2mInByQ1 tWoenWVI+nW4S8nLxw7rNTfva3Dfd8WRDWVD8L54GreRpwzGEhuf3vw9lGXfU/R7CnKt DbPv0OY8C4ULE+38m2Z6XV7GFa9AUqUkc1xCgogusEvowNS7FfI9MMZDU5FwFdV+2waj UrrA+t8OIXBmnk0bHAWrHJ2YjmZi00hJj8lr4RjIK7TYgWJlMnoYpqRPOAJFsDEDTpxF t1Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=V4UW61H+; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j7-20020a056a00174700b0068e37843a1bsi6308215pfc.162.2023.10.19.05.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:13 -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=V4UW61H+; 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 DD920822CF93; Thu, 19 Oct 2023 05:53:11 -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 S1345824AbjJSMwx (ORCPT + 25 others); Thu, 19 Oct 2023 08:52:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345736AbjJSMwi (ORCPT ); Thu, 19 Oct 2023 08:52:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B11B4106; Thu, 19 Oct 2023 05:52:36 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 2F7266607334; Thu, 19 Oct 2023 13:52:35 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719955; bh=FY7GH0xZdlXO2pRrzaejblo22FLeSWf56n9mo0hrqhY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4UW61H+rmeUc64KKsJ2SYKaVsxYfNI2z+CWLGzXBZ3IrrgniR5M9SvRUu5KqJZtk s23/lNatpqO85X0KnJq+lKeXjC1Vp4yp/DbpQJaaGskGJ1M6zaMi9r3+OGAUNiXzDF aFXDfSEJ17KMwTsW3lQzKpJehxKDDK7GUqKm4j66+PibxMAgI7PfLwnX3Z3WbGEk0B QWu3FqeSxRL/4+wrXgQIHTB8nWE4HcGAIRe1aBEihEH2/5H0IM9a9XA8bGBi3aNV+O DPpGbHhVl7jLWKqLGGd3JnDwA/zSfhKc3Ao75gQXl1zLwfPKe6DKjoHkAWlFp/abd8 0rLlJppf8Q2bA== 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 , Zhou Peng Subject: [PATCH v13 09/56] media: amphion: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 19 Oct 2023 14:51:35 +0200 Message-Id: <20231019125222.21370-10-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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, 19 Oct 2023 05:53:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188440033481765 X-GMAIL-MSGID: 1780188440033481765 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. Signed-off-by: Benjamin Gaignard CC: Ming Qian CC: Zhou Peng --- drivers/media/platform/amphion/vpu_dbg.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c index 982c2c777484..a462d6fe4ea9 100644 --- a/drivers/media/platform/amphion/vpu_dbg.c +++ b/drivers/media/platform/amphion/vpu_dbg.c @@ -140,11 +140,18 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) vq = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); for (i = 0; i < vq->num_buffers; i++) { - struct vb2_buffer *vb = vq->bufs[i]; - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_buffer *vb; + struct vb2_v4l2_buffer *vbuf; + + vb = vb2_get_buffer(vq, i); + if (!vb) + continue; if (vb->state == VB2_BUF_STATE_DEQUEUED) continue; + + vbuf = to_vb2_v4l2_buffer(vb); + num = scnprintf(str, sizeof(str), "output [%2d] state = %10s, %8s\n", i, vb2_stat_name[vb->state], @@ -155,11 +162,18 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) vq = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); for (i = 0; i < vq->num_buffers; i++) { - struct vb2_buffer *vb = vq->bufs[i]; - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_buffer *vb; + struct vb2_v4l2_buffer *vbuf; + + vb = vb2_get_buffer(vq, i); + if (!vb) + continue; if (vb->state == VB2_BUF_STATE_DEQUEUED) continue; + + vbuf = to_vb2_v4l2_buffer(vb); + num = scnprintf(str, sizeof(str), "capture[%2d] state = %10s, %8s\n", i, vb2_stat_name[vb->state], From patchwork Thu Oct 19 12:51:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155509 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359053vqb; Thu, 19 Oct 2023 05:53:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEwB5t1sLcAMPl37SzVcyN+xSimA0e7MA07fZkYLy/hz3F84iLOBcpS2Vf2JFSrefUfMuNx X-Received: by 2002:a05:6359:3219:b0:132:d333:4a5c with SMTP id rj25-20020a056359321900b00132d3334a5cmr1675012rwb.10.1697720010838; Thu, 19 Oct 2023 05:53:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720010; cv=none; d=google.com; s=arc-20160816; b=KYRfrE8tEKl33PzDpn6hxz/hhi3AJ9p9viaUMlV/SmfE2yj93VGT3A0aCvg42a+v6p kCyL9yvN6rEIBPBonDtEUxVViklLChDnJnoMxBbPrDbortQfZUd4M0J+b/w5LB1gyGFv HXM+iBNnQ1EFvp1rMS3J3pY83DSsmr65eeVbfAdaRiRObrgNvNLfTuwmXZcBK3jduLaF SFlAwASshqbQd/BLVQyco8aO8TBsGbWUoz6X4TYsL13gvdZ7elaEHFOCoAMYw+XAp6aa OHm/caBmY1OBFUVIOn4hY+tD36JBs06fnHgu6xB7ps5YG9OGnWzwdFo/5kyyKAXXU8bq s4Tw== 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=ZkzUmLRg7Xnu1pLEglSiK4xCI6tZYQt8wr3MwL9ylEY=; fh=YhVWgOX82fKLE5M+MoEX/CwrdcPd8SQ1dctjbZBk3rU=; b=m+cmc1BSdILseXvheYD+cBAtI5vDu0F39+zqFVDd9LbNJJNHVjliE9ijtmCo3vjeeE DAQrBEJLbJU41j7Iiyes4GitdEEod9GMTPYPGURYXjveDnHmeZsqeOlbEX1+Q9NxZNKR 6bu8PWI1p6HxWgcIM0NQP/CirfqIzUWCZiNzJgRsr7R9PCrqq2J2myvcR42anJE8CNgC xmpgNR45Hm4+xp5EMUhVAcNRgN928ZzIq+F1B336ejYSHLbeC69ntVOYiDB+hJdK6EF0 My0Qfw+M3SDPLoWA6JSUvErZTQB18mWkPTKFsm3y4m51Ak9t2hU3P96Hbh/WHQBsxcw9 yy4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=kTPkF2AQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id z19-20020a63e113000000b0057cbd803b30si4473744pgh.654.2023.10.19.05.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=kTPkF2AQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 9A45582E297E; Thu, 19 Oct 2023 05:53:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345761AbjJSMxB (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345735AbjJSMwi (ORCPT ); Thu, 19 Oct 2023 08:52:38 -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 3FFB8119; Thu, 19 Oct 2023 05:52:37 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 B3E2B6607345; Thu, 19 Oct 2023 13:52:35 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719956; bh=PuFoOUa6JL13sN6HuBrtSIThFlotKKJZbkNL+kdatwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kTPkF2AQznyVYC8DaPRrFbF0ogUdZ1fQlt8GomTaaDRXpNDUcTUfevb96D5sZ/SAZ Yq+ZxuGcoZ+ftzW5buE7C719XceaEvpP3G/f5QEfsuvJgrUaItpChLGFuG5nsmNnGD auE1UFWhSI/bG9t3h5zRFfz6/Uim1byTGgq8kJcDNn4rNMXi+fn5vC2ubWymywUpcC Jwg0Gn2cYj5g9UL1zOUtCPP0saBhtmzCHj8BHV5Xx47KyjR2mWhkXReoM0uR9SOAib g9y5A5KzCgvrICbHPhQ4VxhtKrlNX4Dx7ezB/0d9Zmwd581ux94GdN19KzhmKYHBHU cYx1aCiYOj1cA== 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 , Zhou Peng Subject: [PATCH v13 10/56] media: amphion: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:36 +0200 Message-Id: <20231019125222.21370-11-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:53:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188458309443498 X-GMAIL-MSGID: 1780188458309443498 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Ming Qian CC: Zhou Peng --- drivers/media/platform/amphion/vpu_dbg.c | 8 ++++---- drivers/media/platform/amphion/vpu_v4l2.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c index a462d6fe4ea9..940e5bda5fa3 100644 --- a/drivers/media/platform/amphion/vpu_dbg.c +++ b/drivers/media/platform/amphion/vpu_dbg.c @@ -87,7 +87,7 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) num = scnprintf(str, sizeof(str), "output (%2d, %2d): fmt = %c%c%c%c %d x %d, %d;", vb2_is_streaming(vq), - vq->num_buffers, + vb2_get_num_buffers(vq), inst->out_format.pixfmt, inst->out_format.pixfmt >> 8, inst->out_format.pixfmt >> 16, @@ -111,7 +111,7 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) num = scnprintf(str, sizeof(str), "capture(%2d, %2d): fmt = %c%c%c%c %d x %d, %d;", vb2_is_streaming(vq), - vq->num_buffers, + vb2_get_num_buffers(vq), inst->cap_format.pixfmt, inst->cap_format.pixfmt >> 8, inst->cap_format.pixfmt >> 16, @@ -139,7 +139,7 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) return 0; vq = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); - for (i = 0; i < vq->num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(vq); i++) { struct vb2_buffer *vb; struct vb2_v4l2_buffer *vbuf; @@ -161,7 +161,7 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) } vq = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); - for (i = 0; i < vq->num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(vq); i++) { struct vb2_buffer *vb; struct vb2_v4l2_buffer *vbuf; diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c index 0f6e4c666440..87afb4a18d5d 100644 --- a/drivers/media/platform/amphion/vpu_v4l2.c +++ b/drivers/media/platform/amphion/vpu_v4l2.c @@ -439,7 +439,7 @@ int vpu_get_num_buffers(struct vpu_inst *inst, u32 type) else q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); - return q->num_buffers; + return vb2_get_num_buffers(q); } static void vpu_m2m_device_run(void *priv) @@ -587,7 +587,7 @@ static int vpu_vb2_start_streaming(struct vb2_queue *q, unsigned int count) fmt->sizeimage[0], fmt->bytesperline[0], fmt->sizeimage[1], fmt->bytesperline[1], fmt->sizeimage[2], fmt->bytesperline[2], - q->num_buffers); + vb2_get_num_buffers(q)); vb2_clear_last_buffer_dequeued(q); ret = call_vop(inst, start, q->type); if (ret) From patchwork Thu Oct 19 12:51:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359844vqb; Thu, 19 Oct 2023 05:55:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6sDulR+1T9xEp1bw5X7CM4ByGPMlNS5Jp05HNJyYnlAnqJs9b2GdZZbP6VFDsAMPlj8SM X-Received: by 2002:a05:6a21:7794:b0:160:97a3:cae9 with SMTP id bd20-20020a056a21779400b0016097a3cae9mr2056940pzc.54.1697720110911; Thu, 19 Oct 2023 05:55:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720110; cv=none; d=google.com; s=arc-20160816; b=jN1mv5JQc/TR2m2WiBqEuWWTtBC6zZ7VdAsR3yqHabTOkaLkP0Ir2YzIEYcGBNxqP+ +hpuXl9JKwASXDRsFqemyycfobyKaHAvc83QwqWyt8ndDsjLHPgxVwmQ715ZrYCyZNFV SxXaKgyHBns4xxWwZZ/I2eOpCx7/5ddeSpdo7AL0CtAcIu3TLtpo/7vAfb5ly90/WWSs cG3dVBnvZR/81FS03uw0ULJoPbpVRP09aZ90T3DlDjQu+3C8EQV9zs7cGtwtUjXATsaG MDQUJhwthNN1aytYJsnIK3iKrVbwhxVh6+A6phTUHv5yZOAVc7Ur3pWcRSe9iBXuKK57 /ChQ== 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=8DpoE1AoK2fP+RIvieFAiWcgzt2e00XMFBFnulvtgj0=; fh=+NS11/YTnD7GglrGYsYnSnUacC2YXoJUirkP5/1okOw=; b=KGdzd9kCQ4hDqiMq6cG0cedVfaqrEJR1VOO/aLvgNXk/yjAfkcXd00qqjr2KgRZh/o i1Y88+F9kZSvzO0Y9Vf9tLW8gFsTOWQhLt+/X1RlIoVNXOSbX3asqAe1vcNvHffISBZR TP52eWI3RZTmFhWdnsyfhUp/vF96SmObaEFvhPF3eRqt3rGLXqJub/tALIVzuQJDYhVr GaDXi6OtByjeIBrCWLGy/GZVXwjX2Zw8YQwx5gE8RwzJDeUSve2XPSDn7crhgeP7qygj V13cmCkP73QVByKXpVtnQ3gwuikRM26CLAfxQw2GiIyUS+2flhJJUKMBWoD2eOo+X7Lz 8knQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=AYpmPP36; 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 bb20-20020a17090b009400b0027367e0c931si2038278pjb.129.2023.10.19.05.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:10 -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=AYpmPP36; 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 3440F8232677; Thu, 19 Oct 2023 05:54:59 -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 S1345961AbjJSMxW (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345754AbjJSMwj (ORCPT ); Thu, 19 Oct 2023 08:52:39 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8EF512D; Thu, 19 Oct 2023 05:52:37 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 33CCD6607347; Thu, 19 Oct 2023 13:52:36 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719956; bh=U25RUhgn4wrEJgYWeqq/JM19FcBBlklJam1nCiVEFHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AYpmPP36T5mPlYAQ7Ljy1EP2tvHb4iQb5fs2G7SGU61EmhAkf7s7SPmgA/jwHxORZ 77IBBOP8nPtKSQr4wPDLxe2O1oVoVdTAfzGTB2gunIGV/Lqm1+PcxifxMQuMBnf2Le cS2eGpXcsaEAKiM9/3Cdwl0Ur8FLSQPonBhM7tGNNvbPR0KvQFBrYOVwQatbNEpNyb xvdPCYMjh4kzc4TEy/SFtvRzmh9xYUTsitvPkf1heJxMZlV+C1O9I5oxUoY7g5k0Oy UbB8Ff82YtWx1jsbO4pEcfmox9FBANJZ4lAs9MqDSoxy1M6dZ1KrG5fLMrGCus0Ehs S3FOa+K7h674A== 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 v13 11/56] media: mediatek: jpeg: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 19 Oct 2023 14:51:37 +0200 Message-Id: <20231019125222.21370-12-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 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]); Thu, 19 Oct 2023 05:54:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188562817464653 X-GMAIL-MSGID: 1780188562817464653 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. 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; From patchwork Thu Oct 19 12:51:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155520 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359854vqb; Thu, 19 Oct 2023 05:55:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGYQqULDHUWt7Hm6Dajk2KyWpxEKtB1QjspFdlR+8vYjXvLvks8IIfT6f4K+jbB91k+z9p X-Received: by 2002:a17:902:e5c7:b0:1c9:aac5:df1a with SMTP id u7-20020a170902e5c700b001c9aac5df1amr2477819plf.51.1697720112591; Thu, 19 Oct 2023 05:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720112; cv=none; d=google.com; s=arc-20160816; b=dQT2Vo/YNbQx+rH/huzRUsZtMSipcyLMVkftZwIU/oy0xLUMawHQztozkoSVmFfLHd LhzFziojkJUEKLrBdTQ7EqKCRq4bU23/mFCBapMNVXgeFuIZINqEe+1e/f+A3y8GHj8Q PY+A8XTEWkghviic3V4W9OO/H5Ir7TLwHSwgrWcpDaTTHSgFLbPXfsDNcy9I0QAGaoqj 5IZ7vGRLbVVeja4MZayX+WajugaP1ADCH2FMJ7yiVQf4Xmk1Tu0vwNpElFvqMT7myIsb KwD7Yyxd0FC9QqwJpkeQs7wl6OJYiTj9pj3IaCYo0a4R2OuoGNRJuBG7K5CoNVNNt0Zr tuIw== 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=h6Wt5ZXH7wEpvAHo+HItmpVGbqd9IQOis/K3NFElIIY=; fh=+NS11/YTnD7GglrGYsYnSnUacC2YXoJUirkP5/1okOw=; b=fI9eK6HbzxKHL3fAjbYCG2rrSyZd4LB617J+kEfa2vX6mZuK2l1upGm2QH7MEofyRi o0SKIxBnTP76wrSlX86hGW7WKL4QQjKqoJ2dxmhbn7GMVykvGFOEpy1K9gxaoRcrE20V QB7VrZHcYXLzBfY8TRbaNCih0tj9dbFT3x8HRXoqX83yTrqiGEiZ02KzD/2ve7y/Pb// T4kaooAszIjXvxIo07YG98upJx4u845TMjpANfj2Ks8dcW3QueFXjpkdlWQC2xoREkbm T3ygYTBdMYI5xnBDXj5RKj9lkeJctythLrsPG/aEvAN6dmG7HjGMJdIM8D37gq6GilDB gYuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=DTNGc1ii; 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 u14-20020a170902e5ce00b001c32fe6cdf9si2179340plf.386.2023.10.19.05.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:12 -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=DTNGc1ii; 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 5D700822B2EC; Thu, 19 Oct 2023 05:55: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 S1345972AbjJSMx1 (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345755AbjJSMwj (ORCPT ); Thu, 19 Oct 2023 08:52:39 -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 5D7AB130; Thu, 19 Oct 2023 05:52:38 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 B6B7F660734C; Thu, 19 Oct 2023 13:52:36 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719957; bh=LFTEg/R/Wor/QN2odw5Z+gHhYekb/C2BteTgt/nxpjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DTNGc1iiCyHnMzVXBjmWdOhVXbh9Q+qh0aZx+rDjQw8dNkm/dc7AKnsuotx8dBZJ8 NF0U1uCUdlYotWfJsbXcE5kZHxKTj/7Dl7s+qvLAxF5OLA2UoSgLD5bXCo+Pign29B AhOLH5i2uCQb5ZrhDX9HRLF5v3XZEcTMvtrw8plKTWjZnYVAJlsTZCS6V5l+MLu7ja S/VKJCTsj7K51FZmqJGdX2UiVNj9fxrVv6soSPpxTqjTvdWmTtgHmMyJq6q10H0nLT KFgRhPN463QQlOwdjRYB1acRAMO8GuPhI/T3k+nQTCkfRZ88wtemuUQg7DSplY7+bx 6HCx3kNvCgb/w== 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 v13 12/56] media: mediatek: vdec: Remove useless loop Date: Thu, 19 Oct 2023 14:51:38 +0200 Message-Id: <20231019125222.21370-13-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 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]); Thu, 19 Oct 2023 05:55:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188564503575881 X-GMAIL-MSGID: 1780188564503575881 Simplify code by removing useless loop by using video buffer index. Signed-off-by: Benjamin Gaignard CC: Bin Liu CC: Matthias Brugger --- .../mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c index e393e3e668f8..69d37b93bd35 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_if.c @@ -1695,13 +1695,8 @@ static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst return -EINVAL; /* update internal buffer's width/height */ - for (i = 0; i < vq->num_buffers; i++) { - if (vb == vq->bufs[i]) { - instance->dpb[i].width = w; - instance->dpb[i].height = h; - break; - } - } + instance->dpb[vb->index].width = w; + instance->dpb[vb->index].height = h; /* * get buffer's width/height from instance From patchwork Thu Oct 19 12:51:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155513 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359415vqb; Thu, 19 Oct 2023 05:54:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAm2kOqZ79jwXqiLu+dM249j+idXErUJelUwKWcmcYoFd3odhVxLhMW2LcajeTMD7LKb6S X-Received: by 2002:a05:6a20:549b:b0:16b:d853:90be with SMTP id i27-20020a056a20549b00b0016bd85390bemr1921148pzk.25.1697720060077; Thu, 19 Oct 2023 05:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720060; cv=none; d=google.com; s=arc-20160816; b=NrlDO5GAlu3Ut9qv4LAw5A5XQIQ1/J/2EkcCCh/OA+QL3nxDNy3zASc0nHKoeNUe79 DgUkUdJJAqIeZiXRPz0DxnH4/rdWWqWaDXe3gxJozR87gH3kO7PN3qA8eJfuMPDgMQNO 78oVzhqrxEaY57EhCv2RHwVXOfuDyAWIes9z3r7l938AqiIj5ikPCjdhiYqqZofqMF0D FKoo729b0yBjJibPhOkJ4NckT6jG1Fl1+fTx98INkZYtQglNGre1Y9B/5V7GiNqzIhSX TqDJoAfNutU2mgwOBpu5knNiu2xRzCQChgYu1TfNIuTyBFC0NPXsJbTjbWNXfA6kqUtl dfYQ== 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=PsLoD+WAnvw+y2C6s/Kx1I7li9WEBddqHhS2AkeQ4aY=; fh=+NS11/YTnD7GglrGYsYnSnUacC2YXoJUirkP5/1okOw=; b=CGNJOqPhiX9YbnbLiX/karDaarafP1dzlReYXGzEpzFtE0XPHAO4Li4OpuQITh4gOg ZjWZMhDV+gaQ1PkSsvfmZI07n3OafOWUQyffxqh4tD5c5xPgApyC0C8QcS9N4nFOMrjZ fu7K2RldN/8o9FfRgx/EZ8XxoSzsCiMiAUi+70DQET5b12VmSScKI+HtnxSPJhetvcay vK0BQnMLtVRdAPLlqkDO7A2aF3uQrlM1AOMxJYpovg1P3UtABuYUzp39qYSZ2SOkY6F0 t5dHGXr83cZZwgTmP2xecCjeXsNv8Okzcvjj5l3efaUwpSVaDQK1JPB+qTcjVJTllgn+ Htng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KIGzTG6x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id 12-20020a170902c10c00b001c62e42ad8bsi289898pli.72.2023.10.19.05.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:54:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KIGzTG6x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 7190282E8759; Thu, 19 Oct 2023 05:54:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345927AbjJSMxe (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345649AbjJSMwk (ORCPT ); Thu, 19 Oct 2023 08:52:40 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C577E137; Thu, 19 Oct 2023 05:52:38 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 488816607335; Thu, 19 Oct 2023 13:52:37 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719957; bh=lpFYGDh7g/0FRgTondvosfvNWLuluJLuRgdJJzYs6SM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KIGzTG6xxoqu3f3jIUQN6LpZol4bD+5an8o2C85fF0sZtbCcizGpTCAFz60vLg1Pj b3la9LIJoJ6J3pRyBhxA57TXQV6O+pJ0hB4VOljLM8dspwg0kDOh6NB/vy3D7BOhb2 0ChWn89HBQxRJiFi6NEpwgnUV2kxYIB1Z2vUwA3hwx34Vq6/RgUA3xlAdCDEdG5+L/ 7rZ3RCIM7vzVlU14v9xjxigQ6yKwCHKzJDIs3oXxkfLrZz3N3uSrXU1bopGO2FbCb1 rrDVEAxiEoPhydPTofvKHKTaeKyL4fZx6t16ZUX8XSLUtoBm5Yechj+A1W5Zuv7NPJ JEJnGtOj4oL7w== 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 v13 13/56] media: mediatek: vcodec: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:39 +0200 Message-Id: <20231019125222.21370-14-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:54:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188509761677803 X-GMAIL-MSGID: 1780188509761677803 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Bin Liu CC: Matthias Brugger --- drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c index eb381fa6e7d1..181884e798fd 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c @@ -912,7 +912,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count) return 0; err_start_stream: - for (i = 0; i < q->num_buffers; ++i) { + for (i = 0; i < vb2_get_num_buffers(q); ++i) { struct vb2_buffer *buf = vb2_get_buffer(q, i); /* From patchwork Thu Oct 19 12:51:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360338vqb; Thu, 19 Oct 2023 05:56:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpqlPw5cXlOp4zmQv6E+Gk5A3BROx4AS2kK4Ex8zjZbSSh0DqB3Prb//6dV3i6w6rTsog4 X-Received: by 2002:a05:6a20:9190:b0:163:9f1d:b464 with SMTP id v16-20020a056a20919000b001639f1db464mr2365320pzd.5.1697720171707; Thu, 19 Oct 2023 05:56:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720171; cv=none; d=google.com; s=arc-20160816; b=M2GX98L4BECZ8+dO1zvM5h4EcnhFtK6niWPVpeTCSvQv0FVX6dovn+UuxCG5P+VOg6 U4VQQs1rvYVJ0yxka+0YnuVi/DBQ+6Culk10sbBEtQZB3rk/B9RBPcPFxvkD0C/t011A DG3foMMU8pr53SNIGW7/HaDnt+a7diDMibVIQYrVTJ9LPkbD66VPwXBYnoyAsaVe7r56 kxS/3/Pfiv4llE3eXCQJtgLuqjRGY0WN1O3vGSdKq/C3dlv6KbUIJj4q888cSQBpzdF/ CHtZARId2ZSRSdZhqHJMwbL5BEnCkKlIMPCUnzKgL3YRh1tLn3U2UZFDCD5V7Oc1dSZi PsrA== 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=mBxTItB071etk50rIr23nqJudD9UzSRGbWKDGHC1C/NMOC52Y/6G4mMdnCtX/HfooR cPVtAf3bztaPGr/9oFHdHiih54V1aem1wJYZyZiy4D4QL1pacAGyYuuHJXqOw3WxPl/b q73V6vhuehQ6xIAi+TaoqESbYTdHlXP3UZpPD4kwPoYAMnhD2PgttPocekBG9mkwheFs evE/OIjk/YWbyFxPwIpXQlA5ayR+jkCWeeV9cfwXGwtOTQAllYjJDB3hxS5gXqLaaHiL BFCxKoWNfr5QOFUyz6FY5AEBAHKF00Sy5jcdL+3c7b99G99Ggd6X0ui5Oq7P9kPojeiO aQtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="a/iBP9tI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id nn18-20020a17090b38d200b00274d3f62044si558097pjb.111.2023.10.19.05.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="a/iBP9tI"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 9E93F83762EF; Thu, 19 Oct 2023 05:55:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346025AbjJSMyh (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345780AbjJSMwp (ORCPT ); Thu, 19 Oct 2023 08:52:45 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C23C106; Thu, 19 Oct 2023 05:52:39 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 C283F6607351; Thu, 19 Oct 2023 13:52:37 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719958; bh=6OByUfiYmown+37pp4jYIRU8BDesYsod95qP0wK3edE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a/iBP9tI59PpwPQ9dsu1USfyNb+IVCYoCR90qa9XiqxLyHgD0yUIGidTF5m93xFk+ QwXu68MSX/tZOufr8Ia91h24G1wkP+3l/Xkz9KrFi91jjqOfrcHS83f8+3PC10ft5E TE++zp/l82sxexjgmNkeYAsRFTbnN4UcNUpbv+Q2BsvhZi6nDlSNPHBG/E3tomc/ag wzB4rK/+SeVQRrzRkQlE8jvrEHR34uq+6Jz3Wjsh02oJcS+VYc0Sl0GROv2xlyUVS+ 9VYfyu6jz7+tF4H2ZIUGxjjSYFwhvITG/517mbqZmaMWIsrH/9/Jzv2sLoMxjIz8s4 D7KWWiQDtfhcQ== 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 v13 14/56] media: sti: hva: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 19 Oct 2023 14:51:40 +0200 Message-Id: <20231019125222.21370-15-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188626837935852 X-GMAIL-MSGID: 1780188626837935852 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; } From patchwork Thu Oct 19 12:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360734vqb; Thu, 19 Oct 2023 05:56:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgB4AjSJGcPcYI84mSZrlQmNIq0HC9YR/pi9OJ59MwEVojVxg2VkeN4T/I9zxeasMTpD96 X-Received: by 2002:a05:6359:3015:b0:15a:ca3b:5fc with SMTP id rf21-20020a056359301500b0015aca3b05fcmr1746885rwb.27.1697720215795; Thu, 19 Oct 2023 05:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720215; cv=none; d=google.com; s=arc-20160816; b=kGq4gNwxkn8f+RsD9G07PmJ8PaN9vfIEeqkTPU1zfVAp05TLJUPl3W7RJtn6gdvvL6 SSksWVvgNNvbMyNWVtReaTnPPvIc2I/x5wY4MgS0YhyHY6iDHz9xz2u1vgPpZ+cCaF/b toH+MQ5MtJnDq8tLnLqGeELjqYXQkH3rtU6sk2/2Wtti/rFWa9aQmMKdIunNbcpYd0E0 M0Izx9GESxmt4iTit5nfVOzwP06y1PVWPoCxKjJTdeDULIH9oBq26Ga76ZklWr9GAaWE l2X4wT6jpyREWqtPkIfxy+fc9r14vat8ws18ruPzAFVzbajzJYnxMYx/1HcL2+4dwdus XG9Q== 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=NyJ7BF1AH0Xaf2XOQr0Ummtk6Obj50YB13wLLlG1vAk=; fh=R7B7Bon9pv+GFCDou9bQ9Fb3T633P/NGL4WG9w9NtOc=; b=UaRkcirvAwLqrgSiwAfEw890OzdQ5RPVDc08ByvY7Xsny31eKb5fafbH0HlrGqZiyD Y9kMUflRKG0V4xBBgIHwasJjhk2l8sI4aVNTEBVE4TscUw8SY8ckrdyn7PBeYSs/4xcm nDKxO7tRW5IRwTxT7XVb12ZjzhIbo9DmTZuYnrbm3qqonQIGOzNqFDquzVblLlCDnOBK RiP8ISQ5IgHruhUzdf8jpYoJWQQKUlFkQxoHE6y0mqK9z5flDtO497cxCbE8Xet9x9fK D+7ZwEPJyvFvTEyjyj9Sf+Bd5A5lQdryfzb4Ggc1xk70w5pyrpTClNDYKgeWLzqxCQRc 4Xog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JjdLclCP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id e10-20020a656bca000000b00578a56baebesi4475729pgw.674.2023.10.19.05.56.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JjdLclCP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 869AE807600C; Thu, 19 Oct 2023 05:55:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235319AbjJSMyc (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345784AbjJSMwp (ORCPT ); Thu, 19 Oct 2023 08:52:45 -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 D096411B; Thu, 19 Oct 2023 05:52:39 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 4C7E36607352; Thu, 19 Oct 2023 13:52:38 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719958; bh=b1HWvospKm41+ZR+lTHAwjFMrNIUi+qp4QEOx4PbCAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JjdLclCPhiIu7h9Loc+gRj84QPiQ0S7q7I6geT+3m/JHqRLoATk6ddtT7afJsn3dV igvqQ2BXlAzmG8++HlmmvxlYXxv8Monev0Urfau7bmsVa3Lj01Y+4Mz7t3Oi9CnEcc 5saCCcwl2HQjLolj6ZFswqO3se408sBv+T4px2MdkIBkEcjYPUP0pbD0NDcI+2Dfo+ LfgDCRuFR31xt3543oqp3TGuWz5s+09ciPDFjZNfnen5a1AUla7FCDUwcXtCA/4i5i 7Fmz1d0jW2P7KRoOU8q4jv/UHcqvYczu7NA/lMUjOlDATD0fQfEGF+Qh33O18JR51T C1sDZ/GOt4rkg== 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 , Daniel Almeida Subject: [PATCH v13 15/56] media: visl: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 19 Oct 2023 14:51:41 +0200 Message-Id: <20231019125222.21370-16-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188672978654880 X-GMAIL-MSGID: 1780188672978654880 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. Signed-off-by: Benjamin Gaignard CC: Daniel Almeida CC: Mauro Carvalho Chehab --- drivers/media/test-drivers/visl/visl-dec.c | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/media/test-drivers/visl/visl-dec.c b/drivers/media/test-drivers/visl/visl-dec.c index 318d675e5668..ba20ea998d19 100644 --- a/drivers/media/test-drivers/visl/visl-dec.c +++ b/drivers/media/test-drivers/visl/visl-dec.c @@ -290,13 +290,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) for (i = 0; i < out_q->num_buffers; i++) { char entry[] = "index: %u, state: %s, request_fd: %d, "; u32 old_len = len; - char *q_status = visl_get_vb2_state(out_q->bufs[i]->state); + struct vb2_buffer *vb2; + char *q_status; + + vb2 = vb2_get_buffer(out_q, i); + if (!vb2) + continue; + + q_status = visl_get_vb2_state(vb2->state); len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len, entry, i, q_status, - to_vb2_v4l2_buffer(out_q->bufs[i])->request_fd); + to_vb2_v4l2_buffer(vb2)->request_fd); - len += visl_fill_bytesused(to_vb2_v4l2_buffer(out_q->bufs[i]), + len += visl_fill_bytesused(to_vb2_v4l2_buffer(vb2), &buf[len], TPG_STR_BUF_SZ - len); @@ -342,13 +349,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) len = 0; for (i = 0; i < cap_q->num_buffers; i++) { u32 old_len = len; - char *q_status = visl_get_vb2_state(cap_q->bufs[i]->state); + struct vb2_buffer *vb2; + char *q_status; + + vb2 = vb2_get_buffer(cap_q, i); + if (!vb2) + continue; + + q_status = visl_get_vb2_state(vb2->state); len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len, "index: %u, status: %s, timestamp: %llu, is_held: %d", - cap_q->bufs[i]->index, q_status, - cap_q->bufs[i]->timestamp, - to_vb2_v4l2_buffer(cap_q->bufs[i])->is_held); + vb2->index, q_status, + vb2->timestamp, + to_vb2_v4l2_buffer(vb2)->is_held); tpg_gen_text(&ctx->tpg, basep, line++ * line_height, 16, &buf[old_len]); frame_dprintk(ctx->dev, run->dst->sequence, "%s", &buf[old_len]); From patchwork Thu Oct 19 12:51:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359822vqb; Thu, 19 Oct 2023 05:55:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLitFF90WAHF4jUpslCmao5u8gC/nv2GJ8/QKhNowWQ5GcGhdDIBwhP4dzib3WkliOXlrH X-Received: by 2002:a17:90b:4c:b0:27c:fbfa:e2d with SMTP id d12-20020a17090b004c00b0027cfbfa0e2dmr1937791pjt.45.1697720107933; Thu, 19 Oct 2023 05:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720107; cv=none; d=google.com; s=arc-20160816; b=PSKtfqruGAJ1NmJBAaGjX7Uca1BGoWdxUH0oLxenWGlsF9NCxpe6rkYJE+wipigQHW 39i2tl20oA3dMoYOxo8r5ShGkgR2Mrdfr4zBN9bYQcv9LGXqJQl+RR62Jr5cvHkUasD+ Zw3g0NcdrAdG4iARzRr4LVD2GmyWNlsTj9l2CuHtExcM/adUTpyFOqVhPy+zJv06vNcr nPQBZRdCXlxhpYXUjj6i+/MIIVwBqErTum6wyLRfx7SYm0xhlGQABBgJX8Zb8olynRp2 w9WfJZLwkjILSNdzaKJoiZSStR66LBV0aQ/Avw20uhlvDZUaaTFlS4HgH4b4eNZwkxwa ISRw== 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=VM4NzMJMGv79npf1U7MuzJpl4mPtUAdgVx8a3O8ahTM=; fh=O6aRB12iLfQPcoaBoN6ND3UiYcgSMHP3FYKR6EKS/0Q=; b=cXjlH75/84ucuvnaDNGzpuCNAGuybFpowkKz8CmPfMHs2jfekjnHnMPIGuMtyf3Odl xMqFS4CEj3Oh8X/Msxfh0wi0+YT1gusn/4FXaoB7Issq2Oq6F3UanQYMqgBtYz7A/PHM sMnUpz9bsDwJBiRtLitI63idlEGWakuqrbKC+Gt3GhHLiYC/CyN7d3/gpG2yncDmqV0o GQB517+xDOJMt71l8FvC115ZLz+HJccTYYR4m40vJwOCQC7fq4QhqjfyM4tr/iJyvsG7 nzmJE60bE3MZCIz3ZOJbBG0FlVF+1MvQkGer+NxA9K5E6QMc9/CfQBustMbq59bTtqV8 8dpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MMIH1oaz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id mg11-20020a17090b370b00b00277453e82fesi2005656pjb.87.2023.10.19.05.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MMIH1oaz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 8F3A0827D66E; Thu, 19 Oct 2023 05:54:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346013AbjJSMxy (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345789AbjJSMwq (ORCPT ); Thu, 19 Oct 2023 08:52:46 -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 6A0C213D; Thu, 19 Oct 2023 05:52:40 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 CA2E66607355; Thu, 19 Oct 2023 13:52:38 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719959; bh=NE9Dr0xaEnB6dw9lflcnBD1PZMhluEk9SDENx9Slyak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MMIH1oazqYayxx+w2kPp81TINqbJbDetnZ4OYCkCDUGogjR6PlJZf1V1z3rtPGmHp UIBHtxgjXelaAs7zg8kKzE2L/VmIRMe8AmfQHRQsnGiLYvRnPJWP2gGkYgEGbMP7QJ UYcblL6E57NhMPQyTKtSLqPXEXxnpAwvlMNRNJuI8jHiPBZq6H2tvVmDZt2L0tU73s 3cJPQyVqsqJ2BFe784EfEiMrqeb1s4JEfiKsSraB0Wo/e7/rOoX9SItokDdQ/yLfwR 18ANMkw+f+HfUb+4eJQ+/+PivwNFXzhbbeH4AMZjuLQ3T8kS4CmXov5QgfKsM43E65 S5qfCSXlN817w== 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 , Hans de Goede , Sakari Ailus Subject: [PATCH v13 16/56] media: atomisp: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 19 Oct 2023 14:51:42 +0200 Message-Id: <20231019125222.21370-17-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:54:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188559687689284 X-GMAIL-MSGID: 1780188559687689284 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. No need to check the result of vb2_get_buffer, vb2_ioctl_dqbuf() already checked that it is valid. Signed-off-by: Benjamin Gaignard Reviewed-by: Hans de Goede CC: Mauro Carvalho Chehab CC: Sakari Ailus --- drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index a8e4779d007f..a8a964b2f1a8 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -1059,7 +1059,7 @@ static int atomisp_dqbuf_wrapper(struct file *file, void *fh, struct v4l2_buffer if (ret) return ret; - vb = pipe->vb_queue.bufs[buf->index]; + vb = vb2_get_buffer(&pipe->vb_queue, buf->index); frame = vb_to_frame(vb); buf->reserved = asd->frame_status[buf->index]; From patchwork Thu Oct 19 12:51:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360752vqb; Thu, 19 Oct 2023 05:56:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4LdFD+n3Jx9Ap9viy8L+3tcbvFRmT3dc4pvpDC/57Z691rplIfgpLafvmWyWYBBbsRZEd X-Received: by 2002:a05:6a00:21c8:b0:6b8:69fa:a11 with SMTP id t8-20020a056a0021c800b006b869fa0a11mr1940828pfj.12.1697720218444; Thu, 19 Oct 2023 05:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720218; cv=none; d=google.com; s=arc-20160816; b=m9jbraa2JcM3cJTOaxentJQmFwXJtL2AUGL8onfp+7eu/dmkp6++PIqsGoQ16F9jzh mbh22Ega0FbfgSmqBGi4d2JwFKRrU4YUUANte0kRdi2yc4Zwzby6lNpfFhohYU5DoQOe IczKFMFe9MGAv6vizjOTUCgqsCgTYsETfuWNUH1rX0/YVrpSHqVJ3+phqbdWmXyi3BAR QZYkN2YeHf3AL3+6mBHPhMTjXyFPnlVK2eCXDmhC4bothw8/Sn/rDqkHYVxXh+OVweoC 6Q7h/ckVF7LdVRzh3Rp8ZuFiuXAt+EggkpOaG70C+rJ30gG7cirihkYOgN8vp6FnmvFh sXpQ== 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=Pvs4QKgjt42qnLRw2GurbkfXViAWQs5u2SUkVh4xhtc=; fh=O6aRB12iLfQPcoaBoN6ND3UiYcgSMHP3FYKR6EKS/0Q=; b=CIhpA3jLITOv02RLZsi+altXtZ4VbHrWI+ML7muu8kPFiGoLvCqg9jKV0Z12R9jR/j yoKMec3+Pe81MXdmRcSvywFLbFGtczw7bSQ+Bziywl1TPVn0bO8RV1ofCSWKBxpIhWto 8ZeFYf5vEuqGzBReljIItiGWxLjzmlz/hokRWCb4z+ablzRwgToo//4EFZjsYx+Gau07 v37dqjdIUmnM4DQ8gbaguqsoGlbflvesLZNbvvsa28VHs6ZSaq7kX4SSKaWN+hXQKMJL 9V5URKPur3y8CG3PBZpoUbv/zHte7EmnD8lx06Hvkg7PhZS9OGOsIL6GFYHIaU6BDetZ p2aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=TlSKxAPk; 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id by22-20020a056a02059600b00578a7f5a0afsi5055208pgb.357.2023.10.19.05.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:58 -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=TlSKxAPk; 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 7042C82990C3; Thu, 19 Oct 2023 05:55:18 -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 S1345867AbjJSMy1 (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345791AbjJSMwq (ORCPT ); Thu, 19 Oct 2023 08:52:46 -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 E7A79181; Thu, 19 Oct 2023 05:52:40 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 5B7276607356; Thu, 19 Oct 2023 13:52:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719959; bh=hEdAN5aNNO1/pDSIenHgJGapeD5q9IeR/wL5fN5tnvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TlSKxAPko5PHW8AQZyZLF37lazQijX8qrL4wdv7yqcG7ETlAjebi5pc+JZbLY+e87 Qns5e3CLsUj02JYPqhjkXlDdq0LAy9uBYEZ+dVvuJHiNHeB3IhpuIwsaT+HsbeqrTs 4qNobax9zLgLJOLsCn/LJ0Nj1kPp4aDW7+jSfFjeBu+AM4+1d5/psD6lwGNqODZzfB 3Db2r5LZqrXo2SKJklOxwTFt+HWLQeyzo2pAHdq0wEgOrjKsmyyL7qFw4+dKBfpdYF T5BJoEGX16baEzZmQ+mSAI5a91osD/6o6JbG2bgwhBhYF7WTMlEJZ6iSr/2WK/A+aU 2qLRpoXkERITA== 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 , Hans de Goede , Sakari Ailus Subject: [PATCH v13 17/56] media: atomisp: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:43 +0200 Message-Id: <20231019125222.21370-18-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:55:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188675860363407 X-GMAIL-MSGID: 1780188675860363407 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard Reviewed-by: Hans de Goede CC: Sakari Ailus --- drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index a8a964b2f1a8..09c0091b920f 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -1028,7 +1028,7 @@ static int atomisp_qbuf_wrapper(struct file *file, void *fh, struct v4l2_buffer struct atomisp_device *isp = video_get_drvdata(vdev); struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev); - if (buf->index >= vdev->queue->num_buffers) + if (buf->index >= vb2_get_num_buffers(vdev->queue)) return -EINVAL; if (buf->reserved2 & ATOMISP_BUFFER_HAS_PER_FRAME_SETTING) { From patchwork Thu Oct 19 12:51:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360337vqb; Thu, 19 Oct 2023 05:56:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9PxG+f7SWw6OpEO1AkYA2L/zKNsup78+vQQYW2Ef8fe4Ps0yv4lLXXjAmQ1VIK+dGO3r3 X-Received: by 2002:a05:6a20:a0a5:b0:15e:1486:1e08 with SMTP id r37-20020a056a20a0a500b0015e14861e08mr1517241pzj.19.1697720171720; Thu, 19 Oct 2023 05:56:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720171; cv=none; d=google.com; s=arc-20160816; b=OAwP16ivuJBUpEx3rEzTTrR5jhKqmDygkIzqz4os3ojmaeNzJLCgBMCSbCUOcXlZEo eLsGXY4H0k1pBoQNInGKocghb2toPOFPgBKSpw+xjSPEWeT42HAb73wgq+bUNpvMV6ya VrXL0bqc43Ag6csrPOsErUuUJhyDDGwFQPUl8qLL/W8i2i/G7CnwD11klyPR9ByMcKLI 6CiU6SDNkjqlTlZKUXyOk5lt09epBlO6hC9/SzfJu0EGZabAW732/2t0c/gQbnxUtKYD NMOrkrdy6mVpH+yXGB2aU50Cupj8lVB8t4E+yJlDyRy61oW9OmKApBGn6Td7q1QiSzSL qwyQ== 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=rssmHwRaLIgaYrDGGoiR2bvUGHmWTIHsQMhsS5T9D0o=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=Dq6MSYHjqbuFTof9MlPKAf9mHdnWfPsGlSG+Ko2JXHboZvg7/1Ds/CV31zTv0wZ2ys A6K3+kXYZFkAMwFTrWNyRhNjt8wmpFrJon6uCb0I2OBu4+fEj6/cI8I3Jun6u9epr1JH TwSbTOcmghjW0rYAaNQmpe7ab0aUD7Y2XVN6chKE7cHtQGT+ZZN6DvayVXW81dSdRQsC 5LkPWXTqEj7Ep+LH7eV3VIVEvrFq4nNDgk9/qntOU7yQdb/p/DPpteLBeMlNtGsE7ncG 4128PlytoU3XGa3DKRgXyZRFCYt/Vwm5ZksJWVsDFPYZqhb0z4MmGd768HUU7tgktU5g Ho9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nL0yETWi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id 195-20020a6301cc000000b005aa7f52fe5esi4454734pgb.111.2023.10.19.05.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=nL0yETWi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 35CE3805CDAF; Thu, 19 Oct 2023 05:55:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345997AbjJSMxs (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345793AbjJSMwq (ORCPT ); Thu, 19 Oct 2023 08:52:46 -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 72F64187; Thu, 19 Oct 2023 05:52:41 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 E6545660735F; Thu, 19 Oct 2023 13:52:39 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719960; bh=/R1pnW8jfIuOE9V1pOiXWbvwVFtKNqZCCdQZpnNVq6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nL0yETWiO024SU0YGHLbfamIJY5I86dPn+T+jJUM99H43AtnlxZRD+FomJWd5Hudl qzFnbA+PEk0/R4+u4AuesvF2r/waIBsr6a/zt0+Hn2KXbm/EDiby+N0CYrPnRcoiJj gHAwE2e9vlUKvVjLox/3TAfDirnXL7SvTGJx8QbtqNWCAeOflyI7PrLW1hxjGxFjMZ QzfilOTAAwEegLD0LysuJaalKwJoipQ6Skdvu8FZMat7OGxKaksT9qvQfeUbLOg0zh O8EnlA3a7vy12/janVh/lRwFxyUoU0QmMwFPcBuLp8qEXdrqE3PxftJwwnPquJqhJB XOm4MLE0dodDg== 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 v13 18/56] media: dvb-core: Use vb2_get_buffer() instead of directly access to buffers array Date: Thu, 19 Oct 2023 14:51:44 +0200 Message-Id: <20231019125222.21370-19-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188626788371265 X-GMAIL-MSGID: 1780188626788371265 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. Signed-off-by: Benjamin Gaignard --- drivers/media/dvb-core/dvb_vb2.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c index b322ef179f05..3a966fdf814c 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -355,12 +355,13 @@ int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req) int dvb_vb2_querybuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) { struct vb2_queue *q = &ctx->vb_q; + struct vb2_buffer *vb2 = vb2_get_buffer(q, b->index); - if (b->index >= q->num_buffers) { - dprintk(1, "[%s] buffer index out of range\n", ctx->name); + if (!vb2) { + dprintk(1, "[%s] invalid buffer index\n", ctx->name); return -EINVAL; } - vb2_core_querybuf(&ctx->vb_q, q->bufs[b->index], b); + vb2_core_querybuf(&ctx->vb_q, vb2, b); dprintk(3, "[%s] index=%d\n", ctx->name, b->index); return 0; } @@ -385,13 +386,14 @@ int dvb_vb2_expbuf(struct dvb_vb2_ctx *ctx, struct dmx_exportbuffer *exp) int dvb_vb2_qbuf(struct dvb_vb2_ctx *ctx, struct dmx_buffer *b) { struct vb2_queue *q = &ctx->vb_q; + struct vb2_buffer *vb2 = vb2_get_buffer(q, b->index); int ret; - if (b->index >= q->num_buffers) { - dprintk(1, "[%s] buffer index out of range\n", ctx->name); + if (!vb2) { + dprintk(1, "[%s] invalid buffer index\n", ctx->name); return -EINVAL; } - ret = vb2_core_qbuf(&ctx->vb_q, q->bufs[b->index], b, NULL); + ret = vb2_core_qbuf(&ctx->vb_q, vb2, b, NULL); if (ret) { dprintk(1, "[%s] index=%d errno=%d\n", ctx->name, b->index, ret); From patchwork Thu Oct 19 12:51:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359164vqb; Thu, 19 Oct 2023 05:53:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGw+0Y1AqjPLGrP1cATALybnjXldr8soeObKIPP+nGPmo2Nl0uyib3Da2Jx+u8RVxXHfYD+ X-Received: by 2002:a05:6a20:e124:b0:17b:830c:cb11 with SMTP id kr36-20020a056a20e12400b0017b830ccb11mr2488020pzb.14.1697720026855; Thu, 19 Oct 2023 05:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720026; cv=none; d=google.com; s=arc-20160816; b=uB/eqYipjEkM7i6OvWtIkL47EbRJIx3E9Se9PEr5LWjeF4Gq94Gc//Pv4QzHikYTZ3 8urytZHsk2nrLuwyXXr+wEudJPJzq0Ve7llr6coTCOybWV2r7Gr2CHmyaYx/zfhhbGP9 ob8XmcTgRZBNwPH0WVlrZLy5v6WaYTEY+XkVO7bc8VRoLc/ng8NwiC8HhCI7yWpHUg1E NI7qUzEnUdVmcSbBr1meREoKrPLowydwSXwyBgqkmRnTLYzDI6GNwtKkZ/LzVzsBLUcD XuCqWLnenT+2ru/5axDdYDK9ZViRPsfU+6NRFnhgCEagprjOJtA/UGFvHX49Jzz5pTK3 IcDA== 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=d+Zh7OhCiZiOOWKfbCvE9mpOVb6/vmByOpoeFDYFpv4=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=JisOZuxC55bK1m6swhsdvhuEN98VwbzG/yOnOCvWHzD/9CAXvKjJ0h1m+ZyWkZIXmh R51O6dy7gtd10hI61rK2H0kJON9vhGOV4XQiKadHi1F7Zfen7G/2hjXJzbdK9cfYn7Oh lIAUBNGkKx0Hs6scSV+DeiNNQWN2pJPh9hQ98/KaVRicSEbtfGURkaC6lsn2y90xJFXP ovBqQglWyiXS53BzChn4M9RhAR0vo75Pb0D325Lm7b//JLDJq2vHPWi6ck0VdKSAxV4Q tTmbkb6YpHR7P7aM4w7zvqzK2EGMIdICSZrspwt7fTQuVMvXUSvmB2ypwLirLgypEs0j 3jcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bl48PpE5; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ei10-20020a17090ae54a00b002719ad11d97si2028254pjb.137.2023.10.19.05.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:53:46 -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=bl48PpE5; 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 B6A31822D097; Thu, 19 Oct 2023 05:53:45 -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 S1345980AbjJSMxl (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345792AbjJSMwq (ORCPT ); Thu, 19 Oct 2023 08:52:46 -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 0AA4718B; Thu, 19 Oct 2023 05:52:42 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 71D976607346; Thu, 19 Oct 2023 13:52:40 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719960; bh=o2sVtoPPYvq8hM/qyihWIqN4hasDvFA4zhZmTyTxJEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bl48PpE5NDZebqIf4S8TN181nqE+MoISdGxTxyrqH1RiuOGtwArSPEyyH+Xb+wkgh w1NycJrH9LIvWMg7PwRGd9GihTSnfiRc4PGFWJry7LTscvqtZESaCGELig/kOVYcyj Nh6uUaR1cXwVjScIWvKp/i/OBCX5rF+7dBeoTdy5HMkXBe61Ot/xLNU8W7oTnraubb GalWOifBsDNJJpxStBs7qTlt2qSs9wDlzU8G405PjI3FihAUKzb0Mix4XW5VNb+KzM LcU2jIyW6Pe9/1wOs/Kvm8EUlnDuiGXwVpNlCdFnFHMuLJmWRGyjVtHM37GsZ1wnqI P0qnzfaUxjQjQ== 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 v13 19/56] media: dvb-core: Do not initialize twice queue num_buffer field Date: Thu, 19 Oct 2023 14:51:45 +0200 Message-Id: <20231019125222.21370-20-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, URIBL_BLOCKED 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, 19 Oct 2023 05:53:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188474751344628 X-GMAIL-MSGID: 1780188474751344628 The above memset already zeroed all the ctx fields, it is useless to do it here again. Signed-off-by: Benjamin Gaignard --- drivers/media/dvb-core/dvb_vb2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/dvb-core/dvb_vb2.c b/drivers/media/dvb-core/dvb_vb2.c index 3a966fdf814c..a731b755a0b9 100644 --- a/drivers/media/dvb-core/dvb_vb2.c +++ b/drivers/media/dvb-core/dvb_vb2.c @@ -177,7 +177,6 @@ int dvb_vb2_init(struct dvb_vb2_ctx *ctx, const char *name, int nonblocking) q->ops = &dvb_vb2_qops; q->mem_ops = &vb2_vmalloc_memops; q->buf_ops = &dvb_vb2_buf_ops; - q->num_buffers = 0; ret = vb2_core_queue_init(q); if (ret) { ctx->state = DVB_VB2_STATE_NONE; From patchwork Thu Oct 19 12:51:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155516 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359544vqb; Thu, 19 Oct 2023 05:54:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTtiDrzNPD1uZAl36y9oSKxp224WJKyH16NPhwPsoWwY1QW7RMtlbGe9Bv617eYxzaCW1Q X-Received: by 2002:a05:6358:ca6:b0:166:cda9:c1d5 with SMTP id o38-20020a0563580ca600b00166cda9c1d5mr2370886rwj.10.1697720072421; Thu, 19 Oct 2023 05:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720072; cv=none; d=google.com; s=arc-20160816; b=a8l1QtbO8q03YKRQOeBtuia4nyVfFuvmvWDMJDqrpdE4a/cc/9oT/PzowyGYpP2D/K JIBDYmWHFAFxqM7n4tLn21xAyEL4ZniAewsnLbZhddv5h0J68FhLp9BgKPz2z9Bqaax8 GEaBaTT9cgSLpd0fwgXwD+el3s1CEF8OaJpUvtTSE0PA9KrevoWpnY1o4wo83NOQ+sqV VYiMRnpyMnq/v2Bd+7HHjXaSXdYKPqwdHDQPFAYOKaqg/QxWlYGD7KDfe/2Mve09BaIQ knngpcEp1TlbAfZNj/SJR3e24H0xohHNEmx4wtEApV3DSm8JP3TC0KwFueIWIUbWCu93 j2ng== 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=BVc3Gw7um+ugtNMPbdIQp4POT0sbfp8d45vmiRVz7f4=; fh=p0AH8hgimiy85Lh1cXLIqpi5zFbeLa4s8fsQNMmUBzM=; b=Y1P7sVUFTXgVxjvG20DzAUf+reLsRflIWNPXrkWrQ4C8ATFq9dLtU05T3BQJODsb8w kVGvqJSj/t9nt8oZCeSzO5CkZbqH5xZTyqmf5gIr/tWxcEOQ8lzAe5KJP5C7T4CP14bx ruUpZcosLeOkFZFGIRkpCAn45GhPU9les1+O4Opa2TxZYMIWobgd7A42o4qIQVj0RSvt jRJwBpm3SdFqDJn5kbKrCpgsZqbK9+n1iVzqWkLtUuKnNuvawM+lxQuR/egx2Z20ejNg Gs8klgVguDZIFpWhNmGpjXoEC83UEWd0XdiNXjuukhtwU1+hZxrzayZgBzwnrOaNevIQ 3mdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=F7OrKzZi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y19-20020aa78f33000000b0069023e4bcb4si2444090pfr.114.2023.10.19.05.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:54:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=F7OrKzZi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 32F7380545B6; Thu, 19 Oct 2023 05:54:26 -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 S1346040AbjJSMx5 (ORCPT + 25 others); Thu, 19 Oct 2023 08:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345801AbjJSMwq (ORCPT ); Thu, 19 Oct 2023 08:52:46 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C354D18E; Thu, 19 Oct 2023 05:52:42 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 046946607362; Thu, 19 Oct 2023 13:52:41 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719961; bh=mNj/uXX2BkOwU+t/CAhw8+caswKl9nv73YeSkh4q3yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F7OrKzZi31bik6J5oErOk43NN6AyGkYnez089rZ/e855TZgWB4jhKZwFuXneyapEF hgZ8t8D46KeOryL3/HPBx4RfA493fZLsa2txNqgGOG+qxEpRpakohRF5WcyuahC4Tc 0MN/I0qWoc3uHJnVECASR9J9QWwzZmSpczirwfke+hQkJV/HvqgYOjASVVR6WCNLgL DGbjGmGnxOCGO4Efj2t3PgslsVBeuFHYtYsd0QHer7z2rzKznINq/lMCT3Ey1I4jGv ea0110yk879PbU+mNtWjc3ZPvpAl1MnCC8SOgtMBOPs0TWJ1WPioNqs2cQ2+P6HSxN Lg+gcJNf+VK9Q== 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 , Antti Palosaari Subject: [PATCH v13 20/56] media: dvb-frontends: rtl2832: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:46 +0200 Message-Id: <20231019125222.21370-21-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:54:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188522560500531 X-GMAIL-MSGID: 1780188522560500531 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Antti Palosaari --- drivers/media/dvb-frontends/rtl2832_sdr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c index 02c619e51641..023db6e793f8 100644 --- a/drivers/media/dvb-frontends/rtl2832_sdr.c +++ b/drivers/media/dvb-frontends/rtl2832_sdr.c @@ -439,12 +439,13 @@ static int rtl2832_sdr_queue_setup(struct vb2_queue *vq, { struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq); struct platform_device *pdev = dev->pdev; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); dev_dbg(&pdev->dev, "nbuffers=%d\n", *nbuffers); /* Need at least 8 buffers */ - if (vq->num_buffers + *nbuffers < 8) - *nbuffers = 8 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 8) + *nbuffers = 8 - q_num_bufs; *nplanes = 1; sizes[0] = PAGE_ALIGN(dev->buffersize); dev_dbg(&pdev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]); From patchwork Thu Oct 19 12:51:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360116vqb; Thu, 19 Oct 2023 05:55:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDwkQlrx6EAQwz8kWeOSgqemqP/Oxsrtq48wM6swIYGvNVneX5S5ugwO191TbIjzvX0F4x X-Received: by 2002:a05:6a20:4328:b0:126:42ce:bd44 with SMTP id h40-20020a056a20432800b0012642cebd44mr2637752pzk.17.1697720145890; Thu, 19 Oct 2023 05:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720145; cv=none; d=google.com; s=arc-20160816; b=dhAFWxblK0sOlVtp+6R5zFZKa16SIy8NEtiEvrs0Z9THBBJmv5Ex9TWoLUJ8q2rcPJ FFYCFtfct4yXCWbus7LjvIY5UgU+DQjdG5X5P2mrdOzBYclzZoP8I6sxhtmFyFeVpJwC I0bBnImP5am/2c7b3ZncCGLat4gcFLP3q7f2lfWRaczy6O/cHbiCLyYv73FD0NtBjRpI OccWlTAIa7Dxb+2eWR0rDWZuQu2q1m8FZApHMkOnSHwpabjM0Z7g5cNhUP47S2dS0CDi boQKwWgNWhHperA+Qs6SdDRT6j8jM/rK89x+TgCOxPVod/pCT0nB3PrKc5WPL6V9uDxJ Ux/g== 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=mxhqX9L/LTLjAo8r4FRZmw55ljZYm0j0MEPgb49dKlI=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=ygagWkTKSpxAwfpgy9CD7Z3vZwaRCO8lX7nULOKBqHJTvj0q703Rxb/Fz6ZAlf+wI1 rHhhQVETx/q4Nx1XNpRMIMtGkqTGMXc6wiPMPv0PEdEHRd9e7UWPkBqNTzbsVTTwHaZ+ QYKQH6zzF/0QvdCV3/VnOlVhlfVQD6FkEmHlc6emIBdcUCqqpTQB0kTj+kh9diu0GJPr Arip4oUREBWtSs8T7yip0ywgI6Uduql7TsShw+5hf9smdYYdKz8x1TDQb7Tp61IVTzbF suoJDOkYybDVCRyyjc8zAi64E+iniuUlQztzKeXXcXYRkdQq4wQ19tc8c3YdMfD4brAu nBmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="e9Q5c/XG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id d189-20020a6336c6000000b005b5c68e2c92si4363923pga.371.2023.10.19.05.55.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="e9Q5c/XG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 8803F819706E; Thu, 19 Oct 2023 05:55:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346111AbjJSMyD (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345807AbjJSMwq (ORCPT ); Thu, 19 Oct 2023 08:52:46 -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 1C256193; Thu, 19 Oct 2023 05:52:43 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 846A9660732E; Thu, 19 Oct 2023 13:52:41 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719961; bh=7OP/lnsbD5MzPZ4L/gceSmxIzda3Ng9eLtu0phjni7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e9Q5c/XGmoS4q5vNs27JgY/Cjoiran6iFcIpvsC9LeJbR4YLU/pJBA08Ipaf+8RxA xYJFq/edyFkoLyHWKDeV7GGGjkYX7lemUC7swD4Avp2Eu+MZb7k2eSzQQwGRJfR81R sD0BI95cAER5TkephbcbW051fRv8rJk7Ni3/LdylTvOKV6LyqlfFQ4bjvjapep+M0L dI6mQCk1uR0a5Qt0d5kLvBrIEOmbusOqffQKB9xlXFAsB6tEN5D9AD0f3NKk4I1+ne soPvpnnrfgpdG8SR6muomRK1e1jlZUOz2L7eJ4Tl6fBXICwAuEM0tSHSuUSR9wUwx2 w2DcSY2J9uF0g== 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 v13 21/56] media: pci: dt3155: Remove useless check Date: Thu, 19 Oct 2023 14:51:47 +0200 Message-Id: <20231019125222.21370-22-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188599693205586 X-GMAIL-MSGID: 1780188599693205586 min_buffers_needed is already set to 2 so remove this useless check. Signed-off-by: Benjamin Gaignard --- drivers/media/pci/dt3155/dt3155.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/media/pci/dt3155/dt3155.c b/drivers/media/pci/dt3155/dt3155.c index 548156b199cc..d09cde2f6ee4 100644 --- a/drivers/media/pci/dt3155/dt3155.c +++ b/drivers/media/pci/dt3155/dt3155.c @@ -128,8 +128,6 @@ dt3155_queue_setup(struct vb2_queue *vq, struct dt3155_priv *pd = vb2_get_drv_priv(vq); unsigned size = pd->width * pd->height; - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; if (*num_planes) return sizes[0] < size ? -EINVAL : 0; *num_planes = 1; From patchwork Thu Oct 19 12:51:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359696vqb; Thu, 19 Oct 2023 05:54:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFp1hWghPyadBJDAvD/VfEVCgPGsZIS/1jXG7NcUuk7xEXO+3J/AvW1RCL48q/gKH2Dlh85 X-Received: by 2002:a05:6a00:1817:b0:690:fa09:61d3 with SMTP id y23-20020a056a00181700b00690fa0961d3mr2225308pfa.15.1697720090866; Thu, 19 Oct 2023 05:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720090; cv=none; d=google.com; s=arc-20160816; b=NMgeMIyGLPhsiD0Mn339lyjz41yg+M3sUP8AQtQBW8BTIBdmGvOYwtiYc+P3EKRAzB XBe3LWc9oUEhgM+SuVBDk4waNF6jEQe15ASgeSeScqh1CNQjsMlO6PXVTkK/sX6ckv3u GTA6Irr1pshl3G1ZcUE1TgttZVHUyNXd4LpzEhikn3ofzOzV/Jh2gPAjCeHxemKHIlA5 rwVdWD5pKCvXq1edHO6IVfn55U+p+uHRsAf0SZQBDMQzs+uu2iiLShuytTvcsxGjpgIF obsZNJ/wbVj2j6WBJ03xguNFHpjaMV6GeNqsBnrIrKh3rJ+tvueGT1U2TkTPkxtukYiC TEhQ== 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=Ts99oHtPdgNsMvrVJzeWI3ReICZfm5oisnFd3nbTPcA=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=GhTS3QEtKxtJMz0D3caRPkMJlbp4P96ZxvVLvmJr2IiF3URR8CvWyRBna6TrOTc0u6 akhDkAG0ggRA6GS0Lhqky7+b+2CBEQnhqEPb0nnvEwINeHJY032Z9QMjrgXKrpBwSg06 QYe/N5j48VsAHc+xpQsZUNT9SiPBfI/2ZfMHKP49eL+1aU6EBncnX4pwm2vrsG1UV/B4 2qcBxShQaStb+e9To6BGQIKK17j9cJrP54+DLDvpV7fm3NiW4NiFREV+ax5M3jcNOjxQ kv4JDVwjw+mGZD6TASdEW2pW7reIwAPvr9NArDnISnWjg+yWVnRX+SyELlZfZTFCDre0 2+3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Nv4AwtLM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id q1-20020a056a00150100b006be2d9914eesi6606027pfu.118.2023.10.19.05.54.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:54:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Nv4AwtLM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 5F24782E8744; Thu, 19 Oct 2023 05:54:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345914AbjJSMyN (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345818AbjJSMwr (ORCPT ); Thu, 19 Oct 2023 08:52:47 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA215199; Thu, 19 Oct 2023 05:52:43 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 15AEA6607364; Thu, 19 Oct 2023 13:52:42 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719962; bh=E5t1fwehdK/+tA+H+9HRw8QC5ks/Zk2E0Mm8Cosvu64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nv4AwtLMo+ktvAsLvTwosXAV/XukDHsGhXGvIwQsqSuC8kLRfHhqFpKvx7wPdAYBz tk1j49lyLcZqz5BNX1+GHhj2Tiem2APSkgRkWW+ikaxm+onkGc8nIXCUW6Af5woU3F RRPtB0OADzbQFXMOIY8w4mpcLdbGuAdFGOqVMHJpwRdI0PqmAmKR4sT1IHLX8VPKIP QViC9ns/Lbv668XYXbbEJMUMI0fv9iJOuGPVonQHEjuIULSrgdWYpBmnK7gHYFxuxm NVxe2PHetu7HD2lgipemkoJAkiATJhgT2nx7PVhLCo7P2m/7IxMU+K37uVygqOxn93 T6QbQhqYIatzA== 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 v13 22/56] media: pci: tw686x: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:48 +0200 Message-Id: <20231019125222.21370-23-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:54:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188541906698400 X-GMAIL-MSGID: 1780188541906698400 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Ezequiel Garcia --- drivers/media/pci/tw686x/tw686x-video.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/tw686x/tw686x-video.c b/drivers/media/pci/tw686x/tw686x-video.c index 3ebf7a2c95f0..6bc6d143d18c 100644 --- a/drivers/media/pci/tw686x/tw686x-video.c +++ b/drivers/media/pci/tw686x/tw686x-video.c @@ -423,6 +423,7 @@ static int tw686x_queue_setup(struct vb2_queue *vq, unsigned int sizes[], struct device *alloc_devs[]) { struct tw686x_video_channel *vc = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); unsigned int szimage = (vc->width * vc->height * vc->format->depth) >> 3; @@ -430,8 +431,8 @@ static int tw686x_queue_setup(struct vb2_queue *vq, * Let's request at least three buffers: two for the * DMA engine and one for userspace. */ - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; if (*nplanes) { if (*nplanes != 1 || sizes[0] < szimage) From patchwork Thu Oct 19 12:51:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155521 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360014vqb; Thu, 19 Oct 2023 05:55:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/QA7lErZFWgVPg1i97QUj9uYoUpg+Ip3FIDhrAjo3iVuG91rl22ML3A9Nv6TpxK9mIMsY X-Received: by 2002:a05:6358:e816:b0:168:a8c7:632d with SMTP id gi22-20020a056358e81600b00168a8c7632dmr893398rwb.10.1697720133169; Thu, 19 Oct 2023 05:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720133; cv=none; d=google.com; s=arc-20160816; b=JJHA9qvetajXDyBYB53nQGunT51WdYpyAPq0+XWJhweODOcHJcnUw+2kffJj64kare FOVwm9WJ/WfVLAEZ+Ej0aACnFx2UfiRmd+bkEDCpn1YsljKdizIQudnXNLuhjjBzjVV5 smM2lnp+Y4XC5n3eXt6s/VJU3rKsvW+8IpCVRoHc36K8YlsCg/X0h3tU6/IuY+ospYce nGWLu9Zif6IYPB8XNGqa78J50SEIuAFMbVhmJFDIQoZhRjUeG4TQTvgfZy3N4P3wuC3a KoBiIGZgeSxNCIDIWXsWsX+dMPWoDmepUOZ9JhFd1fOSgTC/K1RfSynbwOB8EC2geQ2E nmBA== 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=0a1kRYp57H3SphvzPRCJ+4HpSpBRT10VyUNQ+iboP6E=; fh=kpy8hnP6Gews7/w8dNjLiYrKq2Pvrz/5/ZgUjYw+mFw=; b=C9Oz3LYh4JoS8GZCRaSlZH+sF6faVcymED0JgBMRY1DGLxoXInC5liAlhc3+YfOec0 UQuWnPixeliVWYx1aZh7GtSvpvkkvkhuUMIz25ijnKWaK62dgpOKafvlPN4EJbZAECwv ysHDmtK+TkHFfEeL4wD1TczwRBjV7SKKmArHzOltqsAe7Pnzl+VdtdLEqVPjYshpfS6K 1U+WMwwV5rQoRrR5r9Dl5N+dGj6xi1Id/v0gjafZVPVXqOsqaSuQNmoopM+7WkSsDYRY uXxEiWnBHIP8bzqyJVs/8g0SnX/p3VpOkZHxcYVcjPak/UaLm1W3M+BnKUWzcyAashet LWSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=mPTQB3Cn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id w63-20020a638242000000b005852a35aff4si4866161pgd.227.2023.10.19.05.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=mPTQB3Cn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 2FE7882E875B; Thu, 19 Oct 2023 05:55:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345945AbjJSMyY (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345374AbjJSMwr (ORCPT ); Thu, 19 Oct 2023 08:52:47 -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 324B119A; Thu, 19 Oct 2023 05:52:44 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 95CE16607332; Thu, 19 Oct 2023 13:52:42 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719963; bh=uLexcsAscd7+q7L/zlCLSkE5WS81tRYkOSdorkQDUyM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mPTQB3CnNDCl4Omkm2Av5e9XNa/KizUCbBDp3gDOA194OoGaFXlsLJ58YfE36qbgb PFWHp7DTE6e6t6hVqFzrqHG1IycsCitCECtpXA8zderS7bkl5lKSsoOb42MYyajE/R Cz1WCryShqoyMWKY6nk/NNqJQ/RTRsseYoPjFUbLG/XZ43qARXxibtRr79bJV8fD0N eIaW8JnYFlPKmc/RintxidgFHGVMY7Ocwng0AMo+DJSehY+w0e9a3cGGPI+T6NKrlV q8OouEZcwXbgv1cl3iV4/g/VEoOqcYGv8mcZEHcKk2P4IGOwZZVyvgEc7puMyKlefL 9ZPupyYvGaAlw== 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 , Sergey Kozlov , Abylay Ospan Subject: [PATCH v13 23/56] media: pci: cx18: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:49 +0200 Message-Id: <20231019125222.21370-24-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:17 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188586709975210 X-GMAIL-MSGID: 1780188586709975210 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Sergey Kozlov CC: Abylay Ospan --- drivers/media/pci/cx18/cx18-streams.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/cx18/cx18-streams.c b/drivers/media/pci/cx18/cx18-streams.c index 597472754c4c..cfbc4a907802 100644 --- a/drivers/media/pci/cx18/cx18-streams.c +++ b/drivers/media/pci/cx18/cx18-streams.c @@ -104,6 +104,7 @@ static int cx18_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[], struct device *alloc_devs[]) { + unsigned int q_num_bufs = vb2_get_num_buffers(vq); struct cx18_stream *s = vb2_get_drv_priv(vq); struct cx18 *cx = s->cx; unsigned int szimage; @@ -121,8 +122,8 @@ static int cx18_queue_setup(struct vb2_queue *vq, * Let's request at least three buffers: two for the * DMA engine and one for userspace. */ - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; if (*nplanes) { if (*nplanes != 1 || sizes[0] < szimage) From patchwork Thu Oct 19 12:51:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp359530vqb; Thu, 19 Oct 2023 05:54:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2s1MBopJFTidV7vIJGY/HiCN5VaYnQNuPJ8lQdzSTlW0W+4x8GC/Od7UFKh20KJtqkl8x X-Received: by 2002:a05:6359:3015:b0:166:dcf6:cd82 with SMTP id rf21-20020a056359301500b00166dcf6cd82mr1679750rwb.14.1697720071936; Thu, 19 Oct 2023 05:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720071; cv=none; d=google.com; s=arc-20160816; b=no8V4YvDGZ9gqZzNyhAxf8pAyDDX1FRfyYY4yDb5eGeSVaeCWi3plVQo0otKHK0iPR L04SFmdjzV0UcrM/80i6wFVsJ8A6zOxquUhdlaz1TSKzNNP1VsCKgwLnp5dJPPiHzXW6 gUmGN4UKMHZ8ZwtNT+h6u6YB2s30p0m/a5iD/Y28ATiOE8XMS/iVub/mt856dWzwsrPk swxzcBPAdBW6hbIQYyW0eUXRaknjkyMYQYEYlz5Z2ObpVrNzM85fQzA92wMgyUEhzCAQ tewFiPG7fNU2SoHYzdeb7JadzSCTusgUwlU/nt9SCwFj22jViMGSbFWUIVenWvw+YfEM WYFw== 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=Q+82y3HCRQe8p3qEO/CsxmOcUDerisIraRIWfK/NnGo=; fh=kpy8hnP6Gews7/w8dNjLiYrKq2Pvrz/5/ZgUjYw+mFw=; b=uJrk8EOsWd7z8zGARFfjyQIoeRJ8IFrsgMk97pLZ2xkXCPAWNsl6SBG2Y8tfW72iaJ fzdcqKTh/TnfRBhGgSaUMSHQ31AVEwScoviPh7hUpKVlbGaworc5CC/jIubTOqV/ZJIR efLpNeXmykoT65T4F/gAdaNzs13Ci+71Ds+XQ272oXprmHnPdRzPNMUYoLwlkV3dOMP7 tYdazLDIx1yBxMor9pGXd3CgGOilk7a5+YqnRj7YzqiSFhpJsMXimAoyzGDuZ9U0wzfE I1VHWG67whrLPVexnb3bZLrhAFk0825W+EBdAPokGYDTmQT5usItjtaCWhBn+r693e3X 5h2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="SQa5Y/Zd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id z1-20020aa78881000000b0068a54522bb0si6558297pfe.144.2023.10.19.05.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:54:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="SQa5Y/Zd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 903B882E8759; Thu, 19 Oct 2023 05:54:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345838AbjJSMyI (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345825AbjJSMwr (ORCPT ); Thu, 19 Oct 2023 08:52:47 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E086012A; Thu, 19 Oct 2023 05:52:44 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 250866607331; Thu, 19 Oct 2023 13:52:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719963; bh=i3ojvf+oJl6EVNen5vztp4m8lCDNcxv0WJBCUcNAQzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SQa5Y/Zdj/YGAb1jNO1cGYUkbreddzS949qWHwJVdMlcCMQxrMDKPnq+FFuX2vMhp EWqyQ3/pEoLJf4qG0tr/RIYMLgV5Pn93uOL4U84OxD0Tplp9Mu2ik0Qp4Mbeiu4LR/ 4Dtafv54fYMmUt0GTMHWcE7i7pSsdYWBsxQWVZii5tn2yl0d5uBCZ7+yMoeybB5JvO U76gb/9bAbUga8bMTUfOXgYd6FMShahw+pxbx/nW2ifRpLCYgVxuwV92IVy2TznTkn Pp2jkLuSHyWrWGLM5NzQ5fTzx2tMS8eFH5557PzOdlsyVABqFyE9pIcmdKZZ3Y9HHe +i6CtlmQg6Jzw== 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 , Sergey Kozlov , Abylay Ospan Subject: [PATCH v13 24/56] media: pci: netup_unidvb: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:50 +0200 Message-Id: <20231019125222.21370-25-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:54:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188522285867036 X-GMAIL-MSGID: 1780188522285867036 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Sergey Kozlov CC: Abylay Ospan --- drivers/media/pci/netup_unidvb/netup_unidvb_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/netup_unidvb/netup_unidvb_core.c b/drivers/media/pci/netup_unidvb/netup_unidvb_core.c index d85bfbb77a25..557985ba25db 100644 --- a/drivers/media/pci/netup_unidvb/netup_unidvb_core.c +++ b/drivers/media/pci/netup_unidvb/netup_unidvb_core.c @@ -293,12 +293,13 @@ static int netup_unidvb_queue_setup(struct vb2_queue *vq, struct device *alloc_devs[]) { struct netup_dma *dma = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); dev_dbg(&dma->ndev->pci_dev->dev, "%s()\n", __func__); *nplanes = 1; - if (vq->num_buffers + *nbuffers < VIDEO_MAX_FRAME) - *nbuffers = VIDEO_MAX_FRAME - vq->num_buffers; + if (q_num_bufs + *nbuffers < VIDEO_MAX_FRAME) + *nbuffers = VIDEO_MAX_FRAME - q_num_bufs; sizes[0] = PAGE_ALIGN(NETUP_DMA_PACKETS_COUNT * 188); dev_dbg(&dma->ndev->pci_dev->dev, "%s() nbuffers=%d sizes[0]=%d\n", __func__, *nbuffers, sizes[0]); From patchwork Thu Oct 19 12:51:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360372vqb; Thu, 19 Oct 2023 05:56:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRUXq9f04cERGhUMbkUySZ3/n2qYSP1MkwdLj9Oj89qxRmbqG7NwYvPrmU7C/yJ6OUklBW X-Received: by 2002:a17:90b:347:b0:27c:e062:c464 with SMTP id fh7-20020a17090b034700b0027ce062c464mr1974295pjb.37.1697720176787; Thu, 19 Oct 2023 05:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720176; cv=none; d=google.com; s=arc-20160816; b=cIapY+KybcDV+yArtqsKXtk///BJJNGY1jLPYpwj19X9lpwxFTg8si8pDXg3ko/GT3 CbR4qixKNkxVW7/SDHcnJBvwjZEo9WSFpnwET2k8LI8XHikqsx3H8u/zDyDDkHr2KXbW G6nlDoYE610GrEBwUMakBqzJOCQhFD2WNoV7jCyg8R4R+YsaeD20eV5bOyFtb9f6nVhB t4mySR/FDvvrTFJd04vBDgSWq/qsR6WlB1kaZ1FmN60oUeeqzWP8kFABg9+NsqLzW5Ia dn3biicuiUcbMLIqe0ubgLxSWiNmDe2ZCQES8xR6fFohvzwySf+T14idgPSpIQOZ49qF rGEA== 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=2rHvdHyFGT8YUTP5lBNMszn2pbzYaUtIyUsvYA8bYfQ=; fh=px7ZZE7zN+iLImfXStSrbDHf67f84nNBK9ImQdNvxt4=; b=oQm+TJ14ifXbwQn6NTgS9Qpo7RS4jX1AX+DyuGXIwOnA52OIMcI8S6A9Bxo1NNcNvv iwIMtwWixSoyquM4D3TaJ+2fpqIQkHzkvAu6Q/pQKDuMnHDpxABJQslWEQIney65rwD2 2N0ADw/3fKbE6tsrdkmSJ9Osin+7MqzwYVf6wHTJaHA96ebvS+xwAFGP6yleqpmHWytY f6hugZvRlJzXeGExBT1eVeVGXWUTRl922Hllcpqk8OdtPhkGs2fTlsea68VBliatcr9a 8KpmyU9PjKHaKiY+tA9F7WlAP5lEivQoDWaB34Pal8xYn6aCcp+fjPjEPUYMoAhFvvZ3 bBMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=eIcbAZEE; 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 h1-20020a17090ac38100b00274985b2fcdsi2065751pjt.138.2023.10.19.05.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:16 -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=eIcbAZEE; 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 073EC8232667; Thu, 19 Oct 2023 05:56:06 -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 S1345904AbjJSMyR (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345822AbjJSMwr (ORCPT ); Thu, 19 Oct 2023 08:52:47 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 720F719F; Thu, 19 Oct 2023 05:52:45 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 A87896607369; Thu, 19 Oct 2023 13:52:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719964; bh=ABio7Fn7k/+8wlqN/VSwa9bzp38ffNKUWzBFOmL8pwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eIcbAZEEyREsB/G8CujddavZeznK/65VXH6yM5u8eZGWBVW2qiiwbprBcu5YvxOhq lGBFC/hFq4ufPkEsOgR47R9WL+iKwFF+2kglqEYdMLUnRucTuNrO3znrUCq0LvtQJo 3+oxn6UX2nGpsZkxr2D34lq+BrBEGD9mOjaniK12flQIqrDPD7xApRJ+yKbMbM+HDC wlbJ7FdnngQsbFkwYpq560G2NsT5LdNukd2I5FqI0iRVB5sGZMbqS/NAG1gFCFopsc 48vBxCYdLC3Tsvzna0yg6cCIfYKWF1ybCv/uskTQ983scM0csm/iIETeoPodgAlx5M v6UKMjMsrHzaQ== 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 , Fabrizio Castro Subject: [PATCH v13 25/56] media: pci: tw68: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:51 +0200 Message-Id: <20231019125222.21370-26-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 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]); Thu, 19 Oct 2023 05:56:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188632165647138 X-GMAIL-MSGID: 1780188632165647138 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Fabrizio Castro --- drivers/media/pci/tw68/tw68-video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/tw68/tw68-video.c b/drivers/media/pci/tw68/tw68-video.c index 773a18702d36..35296c226019 100644 --- a/drivers/media/pci/tw68/tw68-video.c +++ b/drivers/media/pci/tw68/tw68-video.c @@ -360,13 +360,13 @@ static int tw68_queue_setup(struct vb2_queue *q, unsigned int sizes[], struct device *alloc_devs[]) { struct tw68_dev *dev = vb2_get_drv_priv(q); - unsigned tot_bufs = q->num_buffers + *num_buffers; + unsigned tot_bufs = vb2_get_num_buffers(q) + *num_buffers; unsigned size = (dev->fmt->depth * dev->width * dev->height) >> 3; if (tot_bufs < 2) tot_bufs = 2; tot_bufs = tw68_buffer_count(size, tot_bufs); - *num_buffers = tot_bufs - q->num_buffers; + *num_buffers = tot_bufs - vb2_get_num_buffers(q); /* * We allow create_bufs, but only if the sizeimage is >= as the * current sizeimage. The tw68_buffer_count calculation becomes quite From patchwork Thu Oct 19 12:51: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: 155528 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360374vqb; Thu, 19 Oct 2023 05:56:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfWprJpCm41+x860+rV9deq4NHNs7b6T1BN3WT7QaM2bfOF6S6rYOpM9dLS83Rt+RVbYDM X-Received: by 2002:a05:6808:280c:b0:3ac:a11a:4879 with SMTP id et12-20020a056808280c00b003aca11a4879mr1901470oib.39.1697720177003; Thu, 19 Oct 2023 05:56:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720176; cv=none; d=google.com; s=arc-20160816; b=FW08Z573kty/3rkfKKsIEzteMXLoGYN33wWIWj+8pPsruYV4Z2mGC5F8Sy6jrMS7dj nt5cgdj2gUcNXPvHgb7b2t3yezpIuLS5CNga5RvojUzV41wCdQfU4S7wEUS3xu9kRJGY oJezqd31IJHdfw7zGvZZQZcvEaeZQMQYDXmEk8sPqubFQbZ+PzBMCfrnY8dCN9/7PEEL TC+I/6M8JpFnKtCUpQbQLwtaBqk8n7nReSmsCosXfzVwaLbXsEgvizMSJfv7kLuF/fzH ysX8LOSO4dZDDVIiSffGzYd1F+H1hO5LA71aydLJPMxe3VsVPe8aJ2oAWC2QGDgUHrmy v+ZQ== 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=qi0nDE9bMNN/N9JtsneH7OSkITzRhDazbSs/TwPJl7k=; fh=nyy6kl3x7bvRns0O2iGfKgaQnRSGFqx2aqkUiW72Nok=; b=agWBmvNNqhvmnEnLckntU/ZDfDhvSeKGbLiv7AoBovytGthvC4uM6e//Y/hOdRQm+w xDf5RYrgE1DF6BP2NFvYBppqsFsB+jFDvs0SbdcRCPOHwP34V0OmfxdMBwxVBkhjZ/z0 FTpTSbUycXrh1CAf7ci96W3O05i7iDvHcfR5konikgrEqR9H17XmK9o+D4cv5CDTYp1G XFSjBsolyN8pRoc/peSghAntlu6aIFL70XIvlooPdP6odfPTPbflauHfzvJqeW6xJy9a C3pSswCBfVqsoGpDrfj8HzcIGsmbO234sFOgBQ5uriT/GgP8H3h/o1BqRWLonO6O/oec eroQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="nzQY/3yH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id n189-20020a6327c6000000b00565ec2a1e2asi4421476pgn.760.2023.10.19.05.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="nzQY/3yH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E796780F4E2A; Thu, 19 Oct 2023 05:56:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345891AbjJSMym (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345840AbjJSMws (ORCPT ); Thu, 19 Oct 2023 08:52:48 -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 E2E961A3; Thu, 19 Oct 2023 05:52:45 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 3099A660733B; Thu, 19 Oct 2023 13:52:44 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719964; bh=QC82AXVc6xizeIJsB4Zdjgq5ICrOlS6NNBj04+AQSGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nzQY/3yHzKSqzUJ/818B/ENYDwEWXb655pNJKShse15WkbIBah45tDltRimhXDOXF FFioq7uxFmA0d6hPu9kCRES+odyRSa5DYsBqZTgfx9Di8kv9CuQd7GHdDzWfpLv4r1 yBrxjpXxhTBtwv2ADBTWvM/zhsKq14hELbsLn9dQ+G8030syc88oa/huHOH8T3O7Eq 6B9ESm9mdABUvtWaNw0vZoitj56FLQBeR8R/i2JBNFCzOyEKAizyyl/1zNoItuLMEm aeZf/AIzspP8ZOuxl1UM/8ERHd3GpdpiYxReKsHVsELRgbSTrJty2EGggxtswHr+k3 cUMcw8VBxTscQ== 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 , Matt Ranostay Subject: [PATCH v13 26/56] media: i2c: video-i2c: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:52 +0200 Message-Id: <20231019125222.21370-27-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:56:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188632271273379 X-GMAIL-MSGID: 1780188632271273379 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Matt Ranostay --- drivers/media/i2c/video-i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c index 178bd06cc2ed..ebf2ac98a068 100644 --- a/drivers/media/i2c/video-i2c.c +++ b/drivers/media/i2c/video-i2c.c @@ -405,9 +405,10 @@ static int queue_setup(struct vb2_queue *vq, { struct video_i2c_data *data = vb2_get_drv_priv(vq); unsigned int size = data->chip->buffer_size; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2; + if (q_num_bufs + *nbuffers < 2) + *nbuffers = 2 - q_num_bufs; if (*nplanes) return sizes[0] < size ? -EINVAL : 0; From patchwork Thu Oct 19 12:51:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155522 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360055vqb; Thu, 19 Oct 2023 05:55:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5ZgD9pSZsCmr5R5IZizg/GAGhlz2Sq2QTj8kRZOMrKUmqgHVAzOG92vKQ3zfLy+bQxJ2p X-Received: by 2002:a17:902:ed01:b0:1ca:3d9c:a752 with SMTP id b1-20020a170902ed0100b001ca3d9ca752mr2370987pld.12.1697720137623; Thu, 19 Oct 2023 05:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720137; cv=none; d=google.com; s=arc-20160816; b=lo+TdULD5Ot+Q1RMB04e1w6Cdlh9AId5jep1KAUSM1jWBsk26wbCMtRrQpe2ePxJGM VVXUsRJHwla+N2kijU5EYvmjjHGeX+DjzdUghvfqwRA4Z/1HsExRaA/V6RZ5ASrBKK1c 1It0M4hVNwRhiidoAJPMPm7nVQbFvW4M18V3jx1AG+fjPSdJYWfRRmTzMUnr9iWBZLWI 00ExNb++7C7U3b10xMx/ncQvRwfmfcjbw2kx4IWJG1TGv7Bzgati48EP5gOuhQ4H4iRq ye33pEt5s7oHtsZPdJCRby/+EKQRb+31AYAqJpJjpUtwtvah65dCE9busIUURkAdT8SZ 3AJA== 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=am6t4n+2sQpuZbKeCUffkOwgvf3HTAP+movCgweBPJs=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=zlj9ABmr/yeBQcBDOIeO8od6YX9ADSL1EaAYuewtl6gyPJPnM1CfSeTurnP2Czb0BG NCcctXLvjyQ8sHhjnCFxC8yBxqhWoCG6GaamUf4/E9nTsgVQAG+QzoVjoHeziMbxngPi tm9SfbG8Q4bWHag8sTZ9CVmUnuEvw5xwS88snKEP8rl9o4MTyhy/uyO5sTpUrlTXML3q vfd52T/zM11aXia+LwWvjqS4F5vSXn4R/KqO4Tr9x/fo+P58HkFRug1TFHgCZH9cyen8 plABXarZed+1Zi78TWrPI0lXhcknt0mvQgxjndIvllPfvk92qWR2kwBC326gCa+zhijo p0ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=AHBDaI5B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u10-20020a170903124a00b001c9c9251e05si2163186plh.476.2023.10.19.05.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=AHBDaI5B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 8B8B0826EB95; Thu, 19 Oct 2023 05:55:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346162AbjJSMzA (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345846AbjJSMwt (ORCPT ); Thu, 19 Oct 2023 08:52:49 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 551D61A6; Thu, 19 Oct 2023 05:52:46 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 AE8B2660736D; Thu, 19 Oct 2023 13:52:44 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719965; bh=+To6mEq3JeR7oNn+VfFQcxDH9wOCwdTHlvSi0qsAVuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AHBDaI5BM8oK3di/U+Y7WiExMD7eXnrE2S3OEKUs2oFkYTdi8wURGr5eK+L4Azq0W aKfJCwJL4mrFCYzxtBn+ZlfSWLiNYvPXNALXLQajp2uQnFBCV+Hj61/+Sr9QNRp40u X2nNsEAPREP3maPP2FCjIdIeguaL376dJda2Wibxhww8mm0rYieYPySolnrav9aI/+ lnXZl1OeDKp73ge0Cf1UHCSdEWUI6xyo8YASxF9klDDGaZ4/EFQ3CxCdOBzapCSBF5 3kMwoHZ6/f7MOlY3vc9RnUdX+Cm+BnLbQNzzAl4IxWIDuq2M3ukF9VIFVHuUtpWd/j F7mfH6C5AfpUA== 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 v13 27/56] media: coda: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:53 +0200 Message-Id: <20231019125222.21370-28-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:29 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188590881769588 X-GMAIL-MSGID: 1780188590881769588 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Philipp Zabel --- drivers/media/platform/chips-media/coda-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/chips-media/coda-common.c b/drivers/media/platform/chips-media/coda-common.c index cc4892129aaf..f1d85758f6dd 100644 --- a/drivers/media/platform/chips-media/coda-common.c +++ b/drivers/media/platform/chips-media/coda-common.c @@ -794,7 +794,7 @@ static int coda_s_fmt(struct coda_ctx *ctx, struct v4l2_format *f, if (vb2_is_busy(vq)) { v4l2_err(&ctx->dev->v4l2_dev, "%s: %s queue busy: %d\n", - __func__, v4l2_type_names[f->type], vq->num_buffers); + __func__, v4l2_type_names[f->type], vb2_get_num_buffers(vq)); return -EBUSY; } From patchwork Thu Oct 19 12:51:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360763vqb; Thu, 19 Oct 2023 05:56:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMkkPqAKy17uT8XN0mZCeiJqH/ef/0+dUshGcPCgWAUNNj4iVFdxamx8EuPa4kGgwmIq7R X-Received: by 2002:a17:902:f68b:b0:1c8:7489:56e2 with SMTP id l11-20020a170902f68b00b001c8748956e2mr2418371plg.35.1697720219481; Thu, 19 Oct 2023 05:56:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720219; cv=none; d=google.com; s=arc-20160816; b=YVCCOfjd9cuj4EIUkJD6RKLj4IJjbfO/1if8onKFqIhxd6l4Oxy01pEFfRIGf46c1J hHBZZbxM9H6YSqRr91/KvqYyN8wJcpzVUZkvn3ULtiodBNP9/4lVo5FgaEceIlQlAxK1 +uqR8uK5O2zbbo6X5CKEljuNEPFtQktK2VCLR3B/dcTVe9LYNrUUu+8YB1jyJ+zNg5G0 4tJY6M6+yJ5U6aeD9ToI4AxLhMiprP+kR6R9tO17J9O2BANwHrr5YYHyswFw0dfpE8w1 2pDsGweQOlLw0hiUWnggnOrN8wARLI9f/fZUvNtM19HIBuSeLsH/NHGSyREJX5OAuCUQ pyPA== 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=fK24xR2X/J25Varz1gbRDc6OpGweyQO05x32Hb3s1QQ=; fh=CvL1xjq7cAmV80HKhOVeAebMHLceLC2GOvcrwdD6rg4=; b=SNsRhRX5VA+o95uqWCfN5XkiA9YQnD4ZDL4Bfn2IMd5WPhHB99G3J3aRsBiJkG0XD7 fJIvmKOrKiOvzMSoQvHwq8/GE3hAuVkktHarEPR2J9RpQxM4P+eEAvXMFKAhunQEbsC/ Jj7hiopHkAcozdXMtSaZJIFF9wdPWaZ7HKZejpDQpBWhiS5RNXOMRfB/ZD0IW03Sf8hH /HlgkrSPjK7Qus+IF+8SwVuqQaIIhpXwVdq190ZVO6rRx3AulEtUOdT9X0X3znE90jkq 7Lcfx0HEOiOWWU9ASLDxWNafODPKftifg7M2AgjN8d7kRx625bQkBgc61TiSoCxocW+v EzUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Css8WBln; 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bb8-20020a170902bc8800b001c9de48fc85si2016334plb.179.2023.10.19.05.56.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:59 -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=Css8WBln; 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 C10D6807EADB; Thu, 19 Oct 2023 05:55:21 -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 S1346144AbjJSMyu (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345852AbjJSMwt (ORCPT ); Thu, 19 Oct 2023 08:52:49 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDFED181; Thu, 19 Oct 2023 05:52:46 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 370B4660732D; Thu, 19 Oct 2023 13:52:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719965; bh=0si/CGsRIyBb9jphgz7l+oPg0Kqq5VWdQXJtmyKQgDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Css8WBlndr9EW1UXlIjURZ3Nu18CsJJeK+0Qcw2PB0yct03NFvq69+ABfbzohF1UT OE7vLtmM6NIfMaSJ5hgvGAo8nSJyl4ThkzuxI5HO/tZTfeDXKAwX7LorF0FgI9oGD9 vkNLI5FRdcLmjcldJTOotoSeMotLJhqcrALo5Yye7lUAeCiySPzMLV9zaTWRcbMm+K KBDT/CletrsX4TgA8htEjjUJnIAXMgbTe8QxdPqi3r0ePATTln9RP+OdF7Gd0l963t wM85YPlWqYp/66kNVIklMBiCALJbpxYE8yVVVRS8GSRjb4LSGyR/cfyZGES7ugJ8WK gQkv37fIw4Wbg== 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 , Rui Miguel Silva , Laurent Pinchart , Martin Kepplinger Subject: [PATCH v13 28/56] media: nxp: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:54 +0200 Message-Id: <20231019125222.21370-29-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:55:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188676755284588 X-GMAIL-MSGID: 1780188676755284588 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Rui Miguel Silva CC: Laurent Pinchart CC: Martin Kepplinger --- drivers/media/platform/nxp/imx7-media-csi.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c index 15049c6aab37..4c467fb82789 100644 --- a/drivers/media/platform/nxp/imx7-media-csi.c +++ b/drivers/media/platform/nxp/imx7-media-csi.c @@ -1245,6 +1245,7 @@ static int imx7_csi_video_queue_setup(struct vb2_queue *vq, struct device *alloc_devs[]) { struct imx7_csi *csi = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); struct v4l2_pix_format *pix = &csi->vdev_fmt; unsigned int count = *nbuffers; @@ -1254,14 +1255,14 @@ static int imx7_csi_video_queue_setup(struct vb2_queue *vq, if (*nplanes) { if (*nplanes != 1 || sizes[0] < pix->sizeimage) return -EINVAL; - count += vq->num_buffers; + count += q_num_bufs; } count = min_t(__u32, IMX7_CSI_VIDEO_MEM_LIMIT / pix->sizeimage, count); if (*nplanes) - *nbuffers = (count < vq->num_buffers) ? 0 : - count - vq->num_buffers; + *nbuffers = (count < q_num_bufs) ? 0 : + count - q_num_bufs; else *nbuffers = count; From patchwork Thu Oct 19 12:51:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360600vqb; Thu, 19 Oct 2023 05:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnOL7uNHrZ25Myd/n1f7g4IKYGE9GXS453Vkp6NORKnINCmUCMx5FHff63yG+qWwswK4TV X-Received: by 2002:a17:902:c409:b0:1c9:d0a0:ee73 with SMTP id k9-20020a170902c40900b001c9d0a0ee73mr2564015plk.5.1697720200300; Thu, 19 Oct 2023 05:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720200; cv=none; d=google.com; s=arc-20160816; b=vrzx3mTUlUkd90u377ei77GwGVG7GO8dqLZ4f4h6DV1eHKPD7akD/nnREdpTz+xFwq CSkOF6Bro+OBGTopgDSai8rIf4ydZ16e/omGG8A4+2QZwy/JoYdYVcPbuYRx0zs7G9mU ILqqsieWnwWJIXWmYBgNJW5tILzob2OW/G34HKWabB0Ih3dLG6o2z1cyUGCQWXF0zJNd sp9Y1U/QhFiaTvFtnnSW9FGfSUtVBCPFdVatmAXVGjxo4GFd+87iMP8Kv3nja3GA5s0S sRqG6gUyhLpjb1lmBihJ/D0Qv+jzc8vvuOGccpeAliXet90Cz5NJftP2SI7TbHwbI3Id Z91w== 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=atK/kDvG1BdB1Ql0lxnu55jjgzpi7DAGGZ/ctT2lERg=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=dmVDmilx6QPVv7Uz6Se40IDq6I+k1vtTe4u179GdqcZlpQO8fTC/ZIUkebZp1JoO7n 9e2kmImUEtgDCh3ERQHujutPmm3pLO2x50GFd4N95FRJBaHfNfmDpPYFST9CoUDu9GHD 1Os6IBvkw0gomd9Fn5O0FupOygmVtSfnN/8mHOylrLMSy5D9ow0AOX5QNlunBPCK72Iq z7SwXfXCb5dwD3Sqhc203rTXleX10101aN53DxrUHQR/xF4qMj8pib1AGU5RBWkxvZvh 7Kce7RBiVm9k+zqMJ6CzTcDoS/bK+mf1n7YJ4GddYLj2RCfyPJ02iMB0I/MhtxGo6ub+ fYAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HSmwO+lQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id h1-20020a170902704100b001bdc10170casi2107119plt.36.2023.10.19.05.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HSmwO+lQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 7B6EA809B08F; Thu, 19 Oct 2023 05:55:45 -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 S1346151AbjJSMyz (ORCPT + 25 others); Thu, 19 Oct 2023 08:54:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345854AbjJSMwt (ORCPT ); Thu, 19 Oct 2023 08:52:49 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9776918B; Thu, 19 Oct 2023 05:52:47 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 C130E6607353; Thu, 19 Oct 2023 13:52:45 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719966; bh=DdlxkRuWKO9j/krVAsdkWz62fUG/5l8klfwhgZtW1d4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSmwO+lQblPR8KDUbpqa2qygt/1zm3WgO1xef1xo2yYTUsW967sElVKGpKbn5g5x1 oXfYaO1Mk9497DNfiSIuXmBMbS+PcZx6Gynsr/EpzUC+eteAavgeT1tfiKeIrhITJI 3CUdvGb0cn6btxoeVELLs4j/LldSSq+/CAn2/wwVT3oWLgwsC1TH+aiIBvjmC3qd/u 1zfRXU/jFUXbmX2vms3TwjYXjSiIK+LMkILHmTtNJM7OpFfmutaNmZ1WyWURzNNl6K c1lniwJ/O2u3pSU9F3vkK7pPMT1JzZ+bKTg8JKu88u1vP3XxiS3nB0yxRxHj/TjzdT KJDhreR4wo/lA== 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 v13 29/56] media: verisilicon: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:55 +0200 Message-Id: <20231019125222.21370-30-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:45 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188656691018448 X-GMAIL-MSGID: 1780188656691018448 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Ezequiel Garcia --- drivers/media/platform/verisilicon/hantro_postproc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c index 64d6fb852ae9..8f8f17e671ce 100644 --- a/drivers/media/platform/verisilicon/hantro_postproc.c +++ b/drivers/media/platform/verisilicon/hantro_postproc.c @@ -195,7 +195,7 @@ int hantro_postproc_alloc(struct hantro_ctx *ctx) struct hantro_dev *vpu = ctx->dev; struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; struct vb2_queue *cap_queue = &m2m_ctx->cap_q_ctx.q; - unsigned int num_buffers = cap_queue->num_buffers; + unsigned int num_buffers = vb2_get_num_buffers(cap_queue); struct v4l2_pix_format_mplane pix_mp; const struct hantro_fmt *fmt; unsigned int i, buf_size; From patchwork Thu Oct 19 12:51:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155529 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360599vqb; Thu, 19 Oct 2023 05:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPVyma5kM9hmK8ulm+EyAoPnSDzaZw+dz77l076pndqNqpf5HJOQ5s2BiC8UpqYPkzfpSO X-Received: by 2002:a05:6a00:a26:b0:6be:559:d013 with SMTP id p38-20020a056a000a2600b006be0559d013mr1992390pfh.10.1697720200273; Thu, 19 Oct 2023 05:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720200; cv=none; d=google.com; s=arc-20160816; b=qoisA0SIv/cS3MZp2TNB6J/RO98JCUObWucZLG/y0S8YjmsLjAmFfdug7KOb3mzFwQ y8yX+cA7Hq6xi2xoEP3N9Xz/XGtNGfysSnrnqSnBrCl9NxjMSzMCxpQv5IsnuSvWszG9 5r+pDPM5afLi37XIdC88kK3YnV2oojgnO34LYRbJSQ79H/Lh4v9mu6aeyymdS900ouYp 3fCO8BmnkxPKiqZArIisxeAUivJb0+RV3U3wOz2QMyqWTC7szmnbWpAiMbt0v4fQ/dH2 h9BQYWp4UJAzLt9PmnoxJRBZJtAvgKi2Z5Bg1hmz9ZQ4Arhi1PiL6Y/PDBQfgVucXYMd icWg== 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=x/BZi6jAexYwrvs36rAttaRt0faTc90UjxSi//s/6JA=; fh=R7B7Bon9pv+GFCDou9bQ9Fb3T633P/NGL4WG9w9NtOc=; b=d+wxeU7+XrSPeGrUfbfLpkL/YwqNiYY/1CfO5E9sdmkXLYZQnkI6sYWzvmNUmuwZFP dbTZ1rTAA2osZ5Grb2yxlhdjYRIHD76W84xxjhcVbA+sZjJdjsShtLIVi/h3xkEzkJX5 5c6LGUVxvdHcV62J+kRzpRBXNShs1+Tj0lesjG+Kyql9eoQMlOJJgxDucn/yk6ejgK2x 3MMbD/i5hqpxUz/FhTQvA+whUlldnaRo/i3EUJuKaUBl/Jc5b1MidUgSdKD0vKjnkoRE y+G0YqvSU0WnRexmSaBX9EIWDB+5F1jtjXkjLmgePpa+Q6HBvcelyyr5xO1s/4SQ3nEK o3Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HeHPhvh5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id d4-20020a056a0010c400b00690fec2f3b6si3402223pfu.193.2023.10.19.05.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=HeHPhvh5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 940B68072F78; Thu, 19 Oct 2023 05:55:55 -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 S1346183AbjJSMzL (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345834AbjJSMxO (ORCPT ); Thu, 19 Oct 2023 08:53:14 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47B81195; Thu, 19 Oct 2023 05:52:48 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 46C8E6607341; Thu, 19 Oct 2023 13:52:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719966; bh=DN10seno4ctykt3zMW3u3yNedtr/M9AvxUqQB0rIcw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HeHPhvh5ZUE7Zhx3r2oMG3gepCd+rg9p8Hj+eCk09K7/as1OyyMjAgUls+TIS9Xbg uOVgKUYaF/QYWJl4EhbCiOtxmRG9rlOtePqkoES/CCQOsLRcgiyMVYx1/oqC8K79bt KDL7wk1OMyxEsgEuecwUMwCAa7J9VS2+d+CFBQLQpnXENMgF5dgP9T+6/va+difzvH FA528AKkC+o4s5CIYfv7GMMDuCcgKFZL4j8ftrT52+otEqDT3s4EE008PIPm6PuN1W 53McFKiYsDm8D6A3y0BGboZv8lPqjv79NlVbT1y7rh1CcrIZ4DORkPRXMOoAlZgbYu /0GcFqbMKR4ig== 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 , Daniel Almeida Subject: [PATCH v13 30/56] media: test-drivers: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:56 +0200 Message-Id: <20231019125222.21370-31-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188656905172475 X-GMAIL-MSGID: 1780188656905172475 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. If 'min_buffers_needed' is set remove useless checks in queue setup functions. Signed-off-by: Benjamin Gaignard CC: Daniel Almeida --- drivers/media/test-drivers/visl/visl-dec.c | 4 ++-- drivers/media/test-drivers/vivid/vivid-meta-cap.c | 3 --- drivers/media/test-drivers/vivid/vivid-meta-out.c | 5 +++-- drivers/media/test-drivers/vivid/vivid-touch-cap.c | 5 +++-- drivers/media/test-drivers/vivid/vivid-vbi-cap.c | 3 --- drivers/media/test-drivers/vivid/vivid-vbi-out.c | 3 --- drivers/media/test-drivers/vivid/vivid-vid-cap.c | 3 --- drivers/media/test-drivers/vivid/vivid-vid-out.c | 5 +---- 8 files changed, 9 insertions(+), 22 deletions(-) diff --git a/drivers/media/test-drivers/visl/visl-dec.c b/drivers/media/test-drivers/visl/visl-dec.c index ba20ea998d19..4672dc5e52bb 100644 --- a/drivers/media/test-drivers/visl/visl-dec.c +++ b/drivers/media/test-drivers/visl/visl-dec.c @@ -287,7 +287,7 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) frame_dprintk(ctx->dev, run->dst->sequence, "%s\n", buf); len = 0; - for (i = 0; i < out_q->num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(out_q); i++) { char entry[] = "index: %u, state: %s, request_fd: %d, "; u32 old_len = len; struct vb2_buffer *vb2; @@ -347,7 +347,7 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) frame_dprintk(ctx->dev, run->dst->sequence, "%s\n", buf); len = 0; - for (i = 0; i < cap_q->num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(cap_q); i++) { u32 old_len = len; struct vb2_buffer *vb2; char *q_status; diff --git a/drivers/media/test-drivers/vivid/vivid-meta-cap.c b/drivers/media/test-drivers/vivid/vivid-meta-cap.c index 780f96860a6d..0a718d037e59 100644 --- a/drivers/media/test-drivers/vivid/vivid-meta-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-meta-cap.c @@ -30,9 +30,6 @@ static int meta_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, sizes[0] = size; } - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; - *nplanes = 1; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-meta-out.c b/drivers/media/test-drivers/vivid/vivid-meta-out.c index 95835b52b58f..4a569a6e58be 100644 --- a/drivers/media/test-drivers/vivid/vivid-meta-out.c +++ b/drivers/media/test-drivers/vivid/vivid-meta-out.c @@ -18,6 +18,7 @@ static int meta_out_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); unsigned int size = sizeof(struct vivid_meta_out_buf); if (!vivid_is_webcam(dev)) @@ -30,8 +31,8 @@ static int meta_out_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, sizes[0] = size; } - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 2) + *nbuffers = 2 - q_num_bufs; *nplanes = 1; return 0; diff --git a/drivers/media/test-drivers/vivid/vivid-touch-cap.c b/drivers/media/test-drivers/vivid/vivid-touch-cap.c index c7f6e23df51e..4b3c6ea0afde 100644 --- a/drivers/media/test-drivers/vivid/vivid-touch-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-touch-cap.c @@ -13,6 +13,7 @@ static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); struct v4l2_pix_format *f = &dev->tch_format; unsigned int size = f->sizeimage; @@ -23,8 +24,8 @@ static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, sizes[0] = size; } - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 2) + *nbuffers = 2 - q_num_bufs; *nplanes = 1; return 0; diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c index b65b02eeeb97..3840b3a664ac 100644 --- a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c @@ -134,9 +134,6 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq, sizes[0] = size; - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; - *nplanes = 1; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-out.c b/drivers/media/test-drivers/vivid/vivid-vbi-out.c index cd56476902a2..434a10676417 100644 --- a/drivers/media/test-drivers/vivid/vivid-vbi-out.c +++ b/drivers/media/test-drivers/vivid/vivid-vbi-out.c @@ -30,9 +30,6 @@ static int vbi_out_queue_setup(struct vb2_queue *vq, sizes[0] = size; - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; - *nplanes = 1; return 0; } diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c index 3a06df35a2d7..2804975fe278 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c @@ -117,9 +117,6 @@ static int vid_cap_queue_setup(struct vb2_queue *vq, dev->fmt_cap->data_offset[p]; } - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; - *nplanes = buffers; dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers); diff --git a/drivers/media/test-drivers/vivid/vivid-vid-out.c b/drivers/media/test-drivers/vivid/vivid-vid-out.c index 184a6df2c29f..24c6dc896255 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-out.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-out.c @@ -73,12 +73,9 @@ static int vid_out_queue_setup(struct vb2_queue *vq, vfmt->data_offset[p] : size; } - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; - *nplanes = planes; - dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers); + dprintk(dev, 1, "%s: count=%u\n", __func__, vb2_get_num_buffers(vq)); for (p = 0; p < planes; p++) dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]); return 0; From patchwork Thu Oct 19 12:51:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360649vqb; Thu, 19 Oct 2023 05:56:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJ9XwRi1/6adcjbkhrWgU3eIKsscfSsSyJamCvgdU+f/vTjHACsPAuJhpFjbw1i+qPOWjx X-Received: by 2002:a05:6a20:144a:b0:15e:707c:904 with SMTP id a10-20020a056a20144a00b0015e707c0904mr2221247pzi.24.1697720205944; Thu, 19 Oct 2023 05:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720205; cv=none; d=google.com; s=arc-20160816; b=Eesp0ZvYV+m+OpoCMv3iA+P3DBn0CroK6zjV56ma/XtLFdMhYDH+5Fdg2MbGH6zPyr MEdI5RPVMe/Bvl3PbnGah0PR7o5ahDQ4s2fIFV0RMEBYRjYYbehkjR5gPzD0vz3rK8jn w5Ri51rzcCPRbBXbYJlkrz15HJOdNfdX9BKtFWQXcuQ/nlfGeE5LCeg/x2dZZ18sTtt6 ALfk3/9S0DCBaZ61innjIR2EXRvymhbOJ2mtARH2YHtFjuwhme6HTbPYPWfKMSUsgyo/ vqogOeO5HtzhjLjNZPCOfwR/FX32UIrGP8V7rS/RcEqqV16DVsUjQ3WRMvBgGIagBLaD fDMw== 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=Puy0NuCUoizD9tUXGoeztaPEYZUcHsDAGMF7ZhtLfh4=; fh=171ZbtLkqTQvfc21XcAM+Vd/toNFohdADskHHVOkNqQ=; b=tOFdUWK3tEAF8J9OOIwhwSntfrijEaYSvmYqQoAuJs80OIoxmWXwGrpq/YUUyz07lx 2lseMvAnz+Z1N0fU7jUKViXeCZkeE07hn8nf9FCXA4UBXN9TZ1beyIOtvuSzOeJCt0I7 /ykEwnaBUgVCnA35KTSaVR+tYvx9spBk4RhIU3EE6z0Yfz4mzoPJ+VLs0Oq3mzOMoicH sH5Um5FLE6lm8L+86z+rnrGsDrvDY1575JyF0dWN65vx2STAmO94GVHPibCV0IxKKMX3 hQkOLhYBmuHlGzxPw/ndkC4VINloWm2ORG+VMN6o6iOTbRqymMjds44/7dkCuUKiJqx1 H8Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NPOhtWUo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id cb15-20020a056a02070f00b0057b55b52870si593189pgb.170.2023.10.19.05.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NPOhtWUo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 3655480227E7; Thu, 19 Oct 2023 05:56:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345962AbjJSMzG (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345909AbjJSMxM (ORCPT ); Thu, 19 Oct 2023 08:53:12 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81874194; Thu, 19 Oct 2023 05:52:48 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 C69DD6607371; Thu, 19 Oct 2023 13:52:46 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719967; bh=5BKm2pXhsA2CwROeeB4gGq1coubFRjY0WIZn0P61OpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NPOhtWUo5OmgNJnQwpf3bAqRLTR7IuEHGa5ERSSJ6I53sOe+9Audkd0UcbpPcva2H ypdN7CzbBA1ZZVB4ZSoUsv9CECXeTUtc7DBBMRctM6NOImiFn9y3W4Ur4xwPQFGBRR G0KgHI78j2ZsLnKTKlzt9dxDqeBL2G997/7DeD9YW+eZS5cjWjdo4vL0FLUDOhvjQN e7gFB3KjHopMIc8aoDaP1vnQ3KGgrDPGLhAbbvTAhGXQjBNpcRaxZ2N5AFuIPJTPK+ o/Y8indILMxG7mWNqns38Z6252TSUPUzcThJFvXDmNK0aRcD/9Y1wuGYpCirAuP6zc qUv+TbgZQH8Sg== 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 , Steve Longerbeam Subject: [PATCH v13 31/56] media: imx: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:57 +0200 Message-Id: <20231019125222.21370-32-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:56:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188662843188433 X-GMAIL-MSGID: 1780188662843188433 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Steve Longerbeam CC: Philipp Zabel --- drivers/staging/media/imx/imx-media-capture.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index 4846078315ff..ce02199e7b1b 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -605,6 +605,7 @@ static int capture_queue_setup(struct vb2_queue *vq, { struct capture_priv *priv = vb2_get_drv_priv(vq); struct v4l2_pix_format *pix = &priv->vdev.fmt; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); unsigned int count = *nbuffers; if (vq->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) @@ -613,14 +614,14 @@ static int capture_queue_setup(struct vb2_queue *vq, if (*nplanes) { if (*nplanes != 1 || sizes[0] < pix->sizeimage) return -EINVAL; - count += vq->num_buffers; + count += q_num_bufs; } count = min_t(__u32, VID_MEM_LIMIT / pix->sizeimage, count); if (*nplanes) - *nbuffers = (count < vq->num_buffers) ? 0 : - count - vq->num_buffers; + *nbuffers = (count < q_num_bufs) ? 0 : + count - q_num_bufs; else *nbuffers = count; From patchwork Thu Oct 19 12:51:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360935vqb; Thu, 19 Oct 2023 05:57:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEiA/Q13FxXYpun8M515pim+Yw7eqVyIQrMXOIx8Y1F8DSR8GSdVz/qQn5OgDpxwBPGo49L X-Received: by 2002:a05:6a20:a10d:b0:17a:4871:63fd with SMTP id q13-20020a056a20a10d00b0017a487163fdmr2437863pzk.0.1697720241580; Thu, 19 Oct 2023 05:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720241; cv=none; d=google.com; s=arc-20160816; b=ef+zQfz2I9tHEookH7G6bX6fvCjT8Dtrag7IaVl4FUf6/ttXvkvx+a8nsa9cpmTZIg NIFJd6vR25dyymqOLhh1c/1fICJHUgcBZ/FZLDSYPC03vETP+BPTQw32icQ0S82vv3J3 ONwCQcYukYiPT/CkIgEt0dcDaRewle90muPaEF+b9xZWaN5MqU5fCgyrXxpLuG379/fd gjCPjKIURs/LMFisLz/09F0Un3rnu/D22r5BaCgEd64t2vBV1sH4NKoiWfwCcNeU29qY JisPjPL/eCh7cUgXN/8USTpr7ho+E2V+rVR+zDQQ2sgnhP2vvAFKagl6TDNKBR9XvfHI lO8w== 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=jjcU1EdUHaOuvWhjBZZmhLhG4kfrsiodV6MICT8E4Rk=; fh=htjdJE4hfcTI3Ydhhcx4l9rF1suJMuuEBK7FcgcRZDc=; b=kw3hKzQB5EYTGQqevMw+okMRYPhJIwQaeiDTNcCZ9J8sJ11bTKcPTAfELy/ShNp1TS lYcU3cm/R7w7NOBpbzgA++TsWOxuMc0uf7o8hkVOq5E4TYHtLhYcA0j6T93V1Sr9c657 Lvl+ptIetXpxNQWnm1V9apBo17zYnSLB8S0qLWuP/T1Y3BwJqSXqXiBSRLZ4Hy07k//L VkAiQB/39QtPd1w2wMpdA1ch6qXdxsANKh/ATiZFyErbrXwj3eRSOYN3ZzRqFnRZAZLs FnVX9McMpIYAZUKL6Z3V9C0K169JY2ZWjfSoQeVwx8v/LQ0rNO695x82NbbISyBMzcAx nHNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=T1BIXVy4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id i68-20020a639d47000000b005783367f97fsi4211169pgd.342.2023.10.19.05.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=T1BIXVy4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 8CE4E80615C8; Thu, 19 Oct 2023 05:57:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346197AbjJSMzQ (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345915AbjJSMxP (ORCPT ); Thu, 19 Oct 2023 08:53:15 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C9C712A; Thu, 19 Oct 2023 05:52:49 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 4F5F06607372; Thu, 19 Oct 2023 13:52:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719967; bh=YJA2RlY3um15cd7mOHDvbbcCRQ1eLCd2aFKgKqMHmxc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1BIXVy4triCVAt6pjZ/aC6yzjKJJpV0DffsN4QizS6e/PAeJMPLQq5HUJnJ3p+dj WfTmJXlL1D/M0SwDVuU4OheZpUBSgdLx99vxEQA1CoANiwdhAWAt9AKEFq+dzHfBDb ltan1oSRqDFwnGRWsV3fiHaODWhE6Aoj6sRQOZ7517tlmhq+ABMNT+/15KvtzBsaWI if0AVWEH49tgMiDSF7EdF56jcKxYpOT5s0KMKY9K7yLNQoTGsHEk5GFdkP6HO8U7HR dxaqcYdq7D3YTVJwcfcv0VxjTodzzoblUNgF4X5GwRUozhPGou+OtsLtIloS9wthaL BuaBDHYjHcIOg== 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 , Neil Armstrong Subject: [PATCH v13 32/56] media: meson: vdec: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:58 +0200 Message-Id: <20231019125222.21370-33-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188700114526738 X-GMAIL-MSGID: 1780188700114526738 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Neil Armstrong --- drivers/staging/media/meson/vdec/vdec.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c index 219185aaa588..1e2369f104c8 100644 --- a/drivers/staging/media/meson/vdec/vdec.c +++ b/drivers/staging/media/meson/vdec/vdec.c @@ -167,22 +167,23 @@ static void process_num_buffers(struct vb2_queue *q, bool is_reqbufs) { const struct amvdec_format *fmt_out = sess->fmt_out; - unsigned int buffers_total = q->num_buffers + *num_buffers; + unsigned int q_num_bufs = vb2_get_num_buffers(q); + unsigned int buffers_total = q_num_bufs + *num_buffers; u32 min_buf_capture = v4l2_ctrl_g_ctrl(sess->ctrl_min_buf_capture); - if (q->num_buffers + *num_buffers < min_buf_capture) - *num_buffers = min_buf_capture - q->num_buffers; + if (q_num_bufs + *num_buffers < min_buf_capture) + *num_buffers = min_buf_capture - q_num_bufs; if (is_reqbufs && buffers_total < fmt_out->min_buffers) - *num_buffers = fmt_out->min_buffers - q->num_buffers; + *num_buffers = fmt_out->min_buffers - q_num_bufs; if (buffers_total > fmt_out->max_buffers) - *num_buffers = fmt_out->max_buffers - q->num_buffers; + *num_buffers = fmt_out->max_buffers - q_num_bufs; /* We need to program the complete CAPTURE buffer list * in registers during start_streaming, and the firmwares * are free to choose any of them to write frames to. As such, * we need all of them to be queued into the driver */ - sess->num_dst_bufs = q->num_buffers + *num_buffers; + sess->num_dst_bufs = q_num_bufs + *num_buffers; q->min_buffers_needed = max(fmt_out->min_buffers, sess->num_dst_bufs); } From patchwork Thu Oct 19 12:51:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155524 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360254vqb; Thu, 19 Oct 2023 05:56:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTbIy0D5eY42Sb2aqAKFK04OiYMBQrwaFiqPnBhW8ExZye0fJXG0VWnwMiJBohybSh4R+5 X-Received: by 2002:a17:902:e54e:b0:1c9:fdbf:296a with SMTP id n14-20020a170902e54e00b001c9fdbf296amr2691500plf.8.1697720159822; Thu, 19 Oct 2023 05:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720159; cv=none; d=google.com; s=arc-20160816; b=lwEpgXkQdRELrPgft82gEIsjnaqpzPAuKEdLE5W2VODVBsiAwcc7i/ShCeKpNRl4Oc +QbPOeNTQ0C+dIkgz/ikH0Wfc0ZZ93PEEdHBdJULIOiNwrpHSx7bIlddQNkceLQGShkL xcu2C2pSnqU6hFHKkeQ+wrG/Fw0gu0Sf1TBFEW36dbPRQXRkdcpGwc2gbOpI4fJ05goG /edun2mH7w6uQuP3floSvIUMGLt+6pnMUCWyAjNuK8prGL90FKG333k4bPpl5pLLz+UQ JemJzawiLdxmBt9zw5kNUQS97uvfKHYBw2j0lDJDe/5SKqrUqbR7NNtnwcfEOCbb/df5 xV9w== 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=A8ph2qj3xtdztdYD/RMDg4TbsW9JnsQI8cJywFJ5HKQ=; fh=QEr6LkXZ0b5ECaCCGx2MOhsbOAaVsr2qEDjA2CECWis=; b=kEPsfrFKyiUA9A8Qn8fp8tRzjyAck1rtlMKUq6By4DW+hBSfBPrvvTCEyd3m1Pfxql dhMP7oiI3I4UWXjGLfoxERmpB5VVA9470PVyktbHxEnYmzr4PJkBgdELfN72ZQHr8vHj 5ABNB+7PqqXlDUTfXCPEVtuQndina2glZIZM94Ea2qX8X+TT7Ov1MKIA2ZbbX6vdMM0z fZVk+S6kz7vdxebdO/wXkVa3OA1OUvg8ILE/3vfRv5Qv2+kHUQLhVPn+gXZyD4qW32Xz /GJ3eHK0ldWSo91DBYeZVRd/Y9bAecQvSfmFVbXWXsVR7U/uCHPEPRt8JuQYzu/9/ckC dKuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VONUCUoq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id n1-20020a170902d2c100b001c5f37aeebdsi2188639plc.579.2023.10.19.05.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:55:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=VONUCUoq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 265E0828E840; Thu, 19 Oct 2023 05:55:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346204AbjJSMzU (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345837AbjJSMxP (ORCPT ); Thu, 19 Oct 2023 08:53:15 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7F441BE; Thu, 19 Oct 2023 05:52:49 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 CE7096607375; Thu, 19 Oct 2023 13:52:47 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719968; bh=k33G17zQJxCQXpWsnxb/MtZzvTjkhGFNRYE0Jo4tkpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VONUCUoqT/ATgu3IKaEjzelgQyb6F/NtglliTKAUxRA5tnN8IolF9z5ApEeRtdkq6 PTruK/vZXpFv9SYQcG4cNzScYL3+hjV4dXcidMUasl6Z93Wy5JQ5Q70Wl4H74HzFVj 2cBjRq8u99KiTniZSVjiv1BK7Md1L7FdJyeChzRx3bXPGKTi+gpWRJYk1W0RzUTPEd yYfECioEMGMoUjdqiIBnvlnYVd0YwT1pUoRUaOuvUa6BJ5CtwLjVXGPlqmKN32QMqb n8RJNTjsgUsSh4hrzbPdvsfkcm1Xi5kHfanJ4O0ixmulPqLhGkII6+Y5kucXUarwkr 5zKztEZyzFb7A== 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 , Dmitry Torokhov , Henrik Rydberg Subject: [PATCH v13 33/56] touchscreen: sur40: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:51:59 +0200 Message-Id: <20231019125222.21370-34-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:55:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188614348025862 X-GMAIL-MSGID: 1780188614348025862 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Dmitry Torokhov CC: Henrik Rydberg Acked-by: Dmitry Torokhov --- drivers/input/touchscreen/sur40.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/sur40.c b/drivers/input/touchscreen/sur40.c index 8ddb3f7d307a..e7d2a52169a0 100644 --- a/drivers/input/touchscreen/sur40.c +++ b/drivers/input/touchscreen/sur40.c @@ -847,9 +847,10 @@ static int sur40_queue_setup(struct vb2_queue *q, unsigned int sizes[], struct device *alloc_devs[]) { struct sur40_state *sur40 = vb2_get_drv_priv(q); + unsigned int q_num_bufs = vb2_get_num_buffers(q); - if (q->num_buffers + *nbuffers < 3) - *nbuffers = 3 - q->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; if (*nplanes) return sizes[0] < sur40->pix_fmt.sizeimage ? -EINVAL : 0; From patchwork Thu Oct 19 12:52:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360986vqb; Thu, 19 Oct 2023 05:57:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqNvWZd1DAAp2qhecZ0C/4ZHmjVU6CpkjSMprAnKrfr1+wrTN3LwH1o4BVEJVQf9gWT5LH X-Received: by 2002:a05:6a21:788b:b0:131:b3fa:eaaa with SMTP id bf11-20020a056a21788b00b00131b3faeaaamr2139548pzc.61.1697720246761; Thu, 19 Oct 2023 05:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720246; cv=none; d=google.com; s=arc-20160816; b=fFYXWt8JbKNxKCvZb0HzI2c7uu+mr4d9z4I5jylp8PiQ7QX/lFXfDtpgCnPlJRU/g/ TetLeRkJj6BqNsdbEz4PHG1xTCKf94xfWf14aQzmSaSPGeHGUGXlN2xX/p3doZaNx16B nJbaEsNaCVJ3X4aihf2wWQuf3DoPrgpX1+pquUpDglR/CiszEazt4y5oUc7kQ9B96Kwk +Qfa7GD4jsCfHG0ADvdjqQo+2QybO7ZkD9+5DH2IABUOs+opcfXirLC6Ap5UbIhM5hu9 4FoSJTdZW5tJLDUwNTqamKZJ570TNDFk/VUqHKN0thCZJREd2DzMpjjZW496O8kb4Aiy nsOw== 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=9mE4isXMY+sPvFFydzybto5CFyUf4D1YY7+c8Y3rQIY=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=hTmhFyODD3cpH3DlPQn1f2SP8Z3zPvq0z0aC238pK0X3gpIiHGXOtgLalkRpY7xICE JGwTX1FhmvPPgk984Q41x/b1uoZLQIn+57m2zRuhQOB+b7dKnfS7zzlPrEjXHIqnDOSo i3Tv3nFruxOa5wpS3dxAj5oY4S2NqRBoMa+KhHdg7xFrxg7Kum+ajsrIX5XPSi64d7pN irEDZsDCacYKuIAqByzZxbkG+DNnJ0DO6bRN0Oe/PsRu/IYaj9/IJMr9yCSYk/8zvFyV YmAVyIUoz7ZBozAzdSbasb+MM6E6eDyUCr4uopL5bLrjn2+o4PARKQ/xAUGnz+ZUCj1t EaeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NL2MRYBl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id k36-20020a634b64000000b0056f8fdb4430si4356004pgl.893.2023.10.19.05.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NL2MRYBl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 57E05819ADAC; Thu, 19 Oct 2023 05:57:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346213AbjJSMzZ (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345926AbjJSMxQ (ORCPT ); Thu, 19 Oct 2023 08:53:16 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53C62D40; Thu, 19 Oct 2023 05:52:50 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 60413660733E; Thu, 19 Oct 2023 13:52:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719968; bh=Cxne9UW1Rdv3DqE7yxtW6lkbxfpON9tV+mkocfttCkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NL2MRYBl+nTe3/yuVeqtXBB/6CVcreZqdbo3L+tLPGcBlDZB6OYHE+3xqMV8DlC1e zTv+q30S+xfeelVU5D4KSUByICt+JUWQav9A+YnN7vMaIhwgWOYG0un68LqziH/XNp /IRtI8FPolDLvWpwDxJdG90M9KHttFcCrFGsJRyHnbnO+M4iOXxa+IAsipJwNy9MPZ k3/S7LRAxPSQgmetrfCRpNFido7+zVtYmtoLQXrqQLy7XEKOIMePmKQvp6P579jSPd GF0/QLv0T7WM2JE+ikzPX/2wygOfFg0tZ+463eiP1CTHvoWEJ+YtKl56kW60tjyk9a SqdDJ9URQSncg== 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 v13 34/56] sample: v4l: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:00 +0200 Message-Id: <20231019125222.21370-35-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188705153393582 X-GMAIL-MSGID: 1780188705153393582 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard --- samples/v4l/v4l2-pci-skeleton.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/v4l/v4l2-pci-skeleton.c b/samples/v4l/v4l2-pci-skeleton.c index a61f94db18d9..a65aa9d1e9da 100644 --- a/samples/v4l/v4l2-pci-skeleton.c +++ b/samples/v4l/v4l2-pci-skeleton.c @@ -155,6 +155,7 @@ static int queue_setup(struct vb2_queue *vq, unsigned int sizes[], struct device *alloc_devs[]) { struct skeleton *skel = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); skel->field = skel->format.field; if (skel->field == V4L2_FIELD_ALTERNATE) { @@ -167,8 +168,8 @@ static int queue_setup(struct vb2_queue *vq, skel->field = V4L2_FIELD_TOP; } - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; if (*nplanes) return sizes[0] < skel->format.sizeimage ? -EINVAL : 0; From patchwork Thu Oct 19 12:52:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360867vqb; Thu, 19 Oct 2023 05:57:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkymRg91+fYGELxjZni5JV6h2econDglnB3KvN1Zjlc+HdUPvo8dgKpSOrvUtsDWd6uMUS X-Received: by 2002:a17:90a:bf09:b0:27c:fd8c:7d28 with SMTP id c9-20020a17090abf0900b0027cfd8c7d28mr1962604pjs.39.1697720231948; Thu, 19 Oct 2023 05:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720231; cv=none; d=google.com; s=arc-20160816; b=Glk/RvOokTYrgj8Sm3d3JUJbY0wC7jh7heQmmJhhPv/iel57aXRGJD0+CW1cCJiCsL jrV71GKQ9IIhn1foff8/yis8NKrBG5vGlXiTi1Vl19Uu3233gB/uktrX1ZjvwzjHnriU +9OciOB+kEYm7knbBk9EGQCWsRJgezguZxvLmOzZ3IlN/L6Wh9QcCQ78Mgs7UPs5T585 YIdtWkHoD0xAGPbJm64CaDemIVcvtOz2ahBAZHJNmcSMuHga7UfzsUKWtj7Zs5tzbPcZ 0AH+xrbLV717xKUOQqiTvK4Mc5zMzz34thFhp/r8xjBUkYR6kKlMdDduEpL8oJKEjMD+ m2IQ== 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=qa0gGpZNMAqHQmNMLRw2KJGOdZocq9+DqAJPNBVbPVs=; fh=aVUrqUP+Ljv+BSkNtX805Xk8KRvk/poCiUhiRUDoQMU=; b=OtGRxYQEtzByHACfmt3tXQqW/K23C9DhQydIDN5CVjyB6noC8PY8vW1K4tqoDSxHLc lIC6mC+FSJGZgmgCwZFhfhQm/6SoOZcxmuD8+mavPGhWvNjQxE/ZmEgo2yOaIDfFDIuQ 2p+/5CFd1fZh4A/MitM4oeaJa7/kFTBW8oM6eKKe0Q9KJaX86ux8WolRjeXxjNXWtkgX GITxvM/i1OPXQ6+X43cqWpPZf7dZcfqj7fugShbb9LrFvQMS4HVOYrg+wJwRzFVZv+QO i80U50t+zqC0UehnmT6okXwrjstNy4pwkZajbJoSORbJty/mCFQgkKbOJ0uIj3dR72FB HO5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XV5FLo+T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id lr7-20020a17090b4b8700b0027ce7a59589si2260605pjb.142.2023.10.19.05.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XV5FLo+T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 2304D8198C70; Thu, 19 Oct 2023 05:56:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346137AbjJSMz2 (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345930AbjJSMxQ (ORCPT ); Thu, 19 Oct 2023 08:53:16 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1FB6D45; Thu, 19 Oct 2023 05:52:50 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 DB9DC6607377; Thu, 19 Oct 2023 13:52:48 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719969; bh=+N2NXYHRMMiyUC0gb7VJb1oDXBrovxuB6Pt09SJAcIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XV5FLo+TUzvHfEOAgrj0IPsE6R7ebKhE3JzjZP4OY+sTIgxJTPxko5wOXx50hnXls NqugT+P4wtk1gmWU5nuLD0pLQnasBGBaYjg/FtdRiHoPRfFLYDSzySZGwBqduZBpc8 jY9jSlxqfpp2M8x73ZtB+UYLBGIbO+bXNuf3/WX7z89WE3LqhgB8Gpv4xAHdPUwz89 OTZeo2ZfhFQA13BoMs6gGoKxovJ4ruEaHX+u80ccL1EyWTPHJDgucdOQe806WMKfJR mWF3xVcx9IriP1g+Z8ikgWz+OgUol9SWOOJZSIrW8qa1AZ5766UELHR2yfAnu3CREm PsC6YgDIff9qw== 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 , Paul Kocialkowski , Maxime Ripard Subject: [PATCH v13 35/56] media: cedrus: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:01 +0200 Message-Id: <20231019125222.21370-36-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:56:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188689488611624 X-GMAIL-MSGID: 1780188689488611624 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard Acked-by: Paul Kocialkowski CC: Maxime Ripard --- drivers/staging/media/sunxi/cedrus/cedrus_h264.c | 9 +++++++-- drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c index dfb401df138a..3e2843ef6cce 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h264.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h264.c @@ -653,8 +653,13 @@ static void cedrus_h264_stop(struct cedrus_ctx *ctx) vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); - for (i = 0; i < vq->num_buffers; i++) { - buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i)); + for (i = 0; i < vb2_get_num_buffers(vq); i++) { + struct vb2_buffer *vb = vb2_get_buffer(vq, i); + + if (!vb) + continue; + + buf = vb2_to_cedrus_buffer(vb); if (buf->codec.h264.mv_col_buf_size > 0) { dma_free_attrs(dev->dev, diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index fc9297232456..52e94c8f2f01 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c @@ -869,8 +869,13 @@ static void cedrus_h265_stop(struct cedrus_ctx *ctx) vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE); - for (i = 0; i < vq->num_buffers; i++) { - buf = vb2_to_cedrus_buffer(vb2_get_buffer(vq, i)); + for (i = 0; i < vb2_get_num_buffers(vq); i++) { + struct vb2_buffer *vb = vb2_get_buffer(vq, i); + + if (!vb) + continue; + + buf = vb2_to_cedrus_buffer(vb); if (buf->codec.h265.mv_col_buf_size > 0) { dma_free_attrs(dev->dev, From patchwork Thu Oct 19 12:52:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360723vqb; Thu, 19 Oct 2023 05:56:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3260rq1ZconJ2CKauuxFIhXzyxPFHkOwFoa7s/NQdUQkVVSa0TjbJbmK7hwQcT4/Ty0Fu X-Received: by 2002:a05:6870:7ec2:b0:1cc:c744:d320 with SMTP id wz2-20020a0568707ec200b001ccc744d320mr2223191oab.53.1697720214774; Thu, 19 Oct 2023 05:56:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720214; cv=none; d=google.com; s=arc-20160816; b=0vWDeeDqxCn7NfY2tmvRquCe3fdYF16ulFRrFShdrnQgBCdVshW9wwJ1YApfzuMebs 6ad+NunKa3VVXRLjiGSsyRJIGzfVAI6jAJT4E3R30XarJqFAP4/9AuH+rbSjTFf6WVX3 CYPwtJIh2hUu+kvgvUl8v1l1sKCEyi1NU21h8hobcCUnkRnw9PAxbBzExFb3dm5TQ4bt D0yBfEvVvmhTT2NkBYjVFWTA78UR5Zzthbgwv8H4p21iXQbCo9gsU3sj00WfQIgmRwNT 98wV9QMWsPox/JL4FBI1/edtXjMBZvlgJ2VDz/+PNgZHZN5E6ey3i3PXMdPFe2n8hHhZ SSVw== 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=mTwTPUkgJc84qE1zYDOnI9698NsFnJ291akDZs3iUec=; fh=zA4Ea09BAmiDPPjR+uJVAnHTWLSizmgLd0oTzclis+o=; b=Ogv2ot660thTUs591rjhvClR4QLMuQlvs5LAO4Xuj8UmafatBewPwkKdu4JZgYQbfM cgexAAevWtTbRbC0rmg4Tcbi0zsqrqF6NIoPdxmBK6X87tMdOhH5Ku6O2mz8iz4VqUjr N37bYJZAfHDkpWOOvaXt7N/2TpVO0p0GxLSpl9RRL7k3d8hVYdcJeAhrzYND7PyaUpEp IrfyR+5eiQbB/svhF4e1PvSTC00CCoeN7fL4hZkCZnRV2I9zspy6JvNzeWVTDS9WmEqM 4QflAWzM6Hozf1gn607HT34eYFpADJQcZebF7vk6r4QkcOXU37JILlR7jdp+x4MZ+oDC uPGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=P0nLAvyh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x185-20020a6386c2000000b005859aec9cdcsi4464666pgd.539.2023.10.19.05.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:56:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=P0nLAvyh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 41039802B286; Thu, 19 Oct 2023 05:56:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346117AbjJSMzf (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345941AbjJSMxR (ORCPT ); Thu, 19 Oct 2023 08:53:17 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D352D4B; Thu, 19 Oct 2023 05:52:51 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 67473660737B; Thu, 19 Oct 2023 13:52:49 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719969; bh=fYtTvMYEVMZXzGkL+XEutCpKu5WEAYjMxFbMl5P4bZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0nLAvyh9h1vYJMnKnu7cbpE6kQXryHyDcm52/tXf19o39Vbry/bP37nL5Emov07W imU1ib+tPfRnIEfMK3lBahbJNV4O/sQSsum4+VFk7R26Nxkx2avq6ZVRn3LeBLFguV datRHGSMUs7zEygT+x1GeSBV2EyRDS3Ogzk+3XMBoeqowjmv78e6lW+intgDJFplWK H4aap6dgH3erip28CGRT7CW7CtU50sb9PXn6P0aWeMtjub+sWelVZncIskgXeGh5GD f9bSaGfBduoUzmFI2IBi/dgyBiOF5WwNGjI3Kb8HMXbm7GS1EtlpifOn3OwVjCx7TH lNMcOsasmWfMg== 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 , Joseph Liu , Marvin Lin Subject: [PATCH v13 36/56] media: nuvoton: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:02 +0200 Message-Id: <20231019125222.21370-37-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:56:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188672140777423 X-GMAIL-MSGID: 1780188672140777423 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Joseph Liu CC: Marvin Lin --- drivers/media/platform/nuvoton/npcm-video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/nuvoton/npcm-video.c b/drivers/media/platform/nuvoton/npcm-video.c index b9e6782f59b4..f9b4e36a5175 100644 --- a/drivers/media/platform/nuvoton/npcm-video.c +++ b/drivers/media/platform/nuvoton/npcm-video.c @@ -393,7 +393,7 @@ static void npcm_video_free_diff_table(struct npcm_video *video) struct rect_list *tmp; unsigned int i; - for (i = 0; i < video->queue.num_buffers; i++) { + for (i = 0; i < vb2_get_num_buffers(&video->queue); i++) { head = &video->list[i]; list_for_each_safe(pos, nx, head) { tmp = list_entry(pos, struct rect_list, list); From patchwork Thu Oct 19 12:52:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361275vqb; Thu, 19 Oct 2023 05:58:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERUoDOfgARTtJdzQUXtBIUcn0BAyucBRxlVygJH4gimxNuQFy/RTe3JETBXkH3NfUyflD0 X-Received: by 2002:a05:6830:2b12:b0:6be:fd1c:c228 with SMTP id l18-20020a0568302b1200b006befd1cc228mr2254162otv.1.1697720285451; Thu, 19 Oct 2023 05:58:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720285; cv=none; d=google.com; s=arc-20160816; b=dUfDunap2rD+AvSJBwmzBIWQx4mQ8sySEQvNdtM3GXw/5AbUWy5nn16CEZhdZ7Mij+ LVBbUAZU5a0EY56eE7bVzjbjHnim+ncsS2GQu4dG15goIDqXMvyoR5RdMOOTELmKxjgT 1pP1MKTYrKqcnwTjDjkGt51EfjMIbQdY9m9/pFbRYtPeMIfvej0iB9b6UnjrU8YQhTSo 8DCHZiuLV5/6fkojSTqpUXFYxbMFrNw/lItaEPkqTRnPzfAIEBRyMB4FvU/h/NoGGFC5 nPtYlw+Wut/d+VcXUt9IvtZ6eXyRKjRE3sacfyIPkjvx7h4EbW6jQXr47lP0ynUam6au a0uw== 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=pSy093gtu6sYylpAu1pxaiVT8mQtQI50EVpPlPpLNJ0=; fh=px7ZZE7zN+iLImfXStSrbDHf67f84nNBK9ImQdNvxt4=; b=gJ80uuz21/EmUSmiqLsiqqrA6YfrIBmSGSII/GQns85AAuIc50FnRlhFk+cX4s9ts+ DsZVN6OnQtF6osdlgBBc26kFlgrYx1vQ1jLCFQJPw50XVRdBAhMIItAOeezt+tOG296V sYewDxSLBPHgRgG3mminHKmVRXjNP7QZ34QSfebotDQhSxve26FJlB3dO7DI5oMalElf t5vdSQ3GOBndJmzrngBrQnap+A437lcC5LKSHFa7DfzPymOv82q5JdOz0mlCZvYXwkqV LUzCnX77U9FbiD1WugYtsZzRK1CrhV7UAOO8JJll4M5lyiXJoKYc3uAvcPdab5oe0AtB 6geQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IGQZ0uEQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id g16-20020a056a000b9000b0068ff659af62si6421069pfj.106.2023.10.19.05.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IGQZ0uEQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 93EB780732AD; Thu, 19 Oct 2023 05:57:49 -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 S1346125AbjJSMzj (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345940AbjJSMxR (ORCPT ); Thu, 19 Oct 2023 08:53:17 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B69C5D4F; Thu, 19 Oct 2023 05:52:51 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 E7F206607334; Thu, 19 Oct 2023 13:52:49 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719970; bh=I24/t0ZqSyeKvdZtsSJpVc7QnzmONAbV5k9WYLKmpuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IGQZ0uEQO3rs1XmURBUPRvA8nKSH1kdVUbI7Fn1LiGDupmgB1HYcYEpwrmhpvYHO8 UIbFbDr6MvkbhsNvpvqjGhOcA5paO6TVc+tnHjMOX9OrdO1YmIM9d/5IMPznEVYRjL 4fy+dBFLlCXNtARymxvhg0+cZgraUgyoqB/Vkt1x2/hIGLRPGgsnmFoYnMxdZCF1/l 3w4CVUQlSbAGjjANefzNmGWuPDPFeU4E7R/8EEt5RF3PLZv//XVI66Xdrm95YIdMNu RQiY97kfN+9ZvGU0sGWQkyBp8csYadlaECbKqyJjlLo8efmLH8335ICvO8i4o2d9nX l6DWtTUE2Pxwg== 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 , Fabrizio Castro Subject: [PATCH v13 37/56] media: renesas: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:03 +0200 Message-Id: <20231019125222.21370-38-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188745855428336 X-GMAIL-MSGID: 1780188745855428336 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Fabrizio Castro --- drivers/media/platform/renesas/rcar_drif.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/renesas/rcar_drif.c b/drivers/media/platform/renesas/rcar_drif.c index 292c5bf9e50c..f21d05054341 100644 --- a/drivers/media/platform/renesas/rcar_drif.c +++ b/drivers/media/platform/renesas/rcar_drif.c @@ -424,10 +424,11 @@ static int rcar_drif_queue_setup(struct vb2_queue *vq, unsigned int sizes[], struct device *alloc_devs[]) { struct rcar_drif_sdr *sdr = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); /* Need at least 16 buffers */ - if (vq->num_buffers + *num_buffers < 16) - *num_buffers = 16 - vq->num_buffers; + if (q_num_bufs + *num_buffers < 16) + *num_buffers = 16 - q_num_bufs; *num_planes = 1; sizes[0] = PAGE_ALIGN(sdr->fmt->buffersize); From patchwork Thu Oct 19 12:52:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360824vqb; Thu, 19 Oct 2023 05:57:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHr9n9wrE4yN4fRGLpm7Ekt/79oDGhoD1hTGa6I0Hg6PrKvxSlDTemY7LRnqszw7N4NAQqj X-Received: by 2002:a05:6359:1c02:b0:143:3179:1a67 with SMTP id us2-20020a0563591c0200b0014331791a67mr1716403rwb.29.1697720226045; Thu, 19 Oct 2023 05:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720226; cv=none; d=google.com; s=arc-20160816; b=lPI7izI3MDFsQvsFBQrDlOGtjtGn1DKJqRB/2x0DehlkjwM22TWb5VhoUbZjQoOfWg RMXU8IckXOF12DQwafn/q7Jm6y8U5/t8p5HzGa4md72mi09s8n+fSwiCrSNrMRSPr049 FH7BY2fR5/D7OqBw7Bn+Y3/hVHpUV9S2hEStnKOs/7EeZEPnK31zNoF798oSTMl0CfTk EVRdZGB/T02QKnifmrHDJJf8FEMCiW4zYQGzYNarrAJldp3iGlHbatu8pwgsMF/bUFBn lPKgcW9GVqciip0NzIflF9AIx/aDZzpAjZJu9RSYmpQaYkZI+b1ybZZX3/3dji7b3EC0 TTTQ== 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=Ao2LyBn2rnPSsSTXV0MzcLMfBZjF1jr+nzoTcvVyecU=; fh=N6ugtfNsynmfBJwExzB6j0reiQ5L5ldIIl+DJ0NYKOk=; b=Ex5Z4WdxtlfpW/cPQbotA+M2OtD3V/vTr/jdjs4Khh+1tC3mVJEsTejHnG59uV7i0f rZbJ1tm7dx/5QUVFZErJL3fQ+nk8m9jPZgftC1+37fRc1k7gtt99eP620UHKOMvP5h1d +jx/S9MdMyWmccAPhbSxtE71XYky1sqlHsBIxL/9AGMrpDC8KsXMuXCQqPTJ+EIaCOeT rzdpBIh4zr6A/Ox1qt/v02+lEfgj7/EqsZz9JGdfAmhCV2Rw7RrPKQcF1wZcXBY3f1GU Aqs84A/whnbsZlSwh6L/yCTPaDx68WtL09hxtFr6FuAap1sNPDr62qeuCgASE8Ii8Wd9 vnrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=iFwYFdfd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i191-20020a6387c8000000b005ab92870413si4717596pge.498.2023.10.19.05.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=iFwYFdfd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 3918580BEDE4; Thu, 19 Oct 2023 05:56:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346014AbjJSMzs (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346032AbjJSMx5 (ORCPT ); Thu, 19 Oct 2023 08:53: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 306D0D7B; Thu, 19 Oct 2023 05:52:55 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 74D306607381; Thu, 19 Oct 2023 13:52:50 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719970; bh=dzwa/jYB5Q8JSc9NA/K1ZmfJPhSPTZE1y6AwFUzPpGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iFwYFdfdorLwOroxjYpXwLTlBJe7ur0qb0NYAiZvUGLsYpQMVKvLr4IPP8jWMhnRE /OVaqbNLUMf6mg5Tmpy6JKI1IpZ0rRF0jhTAvRjVyfxmdm5etOUb9lorJEgOlgjAny /geajUH0uF34wdFYIYBS1k7oYJ+snXGEboYRheHposCwwWU6+W5CQPfS8JJxvjW4ZV cu59NKLfDw+KuyA75xvVMBYRMMTCxwuS/bBsuPMEe4DTiGv5JZEzOP3XQZcQAYLd1J t2xB1eZlI2BHFCFgwhoXD/HSa9OMSZPlYPrxp4ffdI+PNhgqDCiz/kivtPG/L1udKL a3gLiWXXExwqA== 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 , "Lad, Prabhakar" Subject: [PATCH v13 38/56] media: ti: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:04 +0200 Message-Id: <20231019125222.21370-39-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:56:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188683596686253 X-GMAIL-MSGID: 1780188683596686253 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: "Lad, Prabhakar" --- drivers/media/platform/ti/am437x/am437x-vpfe.c | 5 +++-- drivers/media/platform/ti/cal/cal-video.c | 5 +++-- drivers/media/platform/ti/davinci/vpif_capture.c | 5 +++-- drivers/media/platform/ti/davinci/vpif_display.c | 5 +++-- drivers/media/platform/ti/omap/omap_vout.c | 5 +++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/ti/am437x/am437x-vpfe.c b/drivers/media/platform/ti/am437x/am437x-vpfe.c index 5fa2ea9025d9..f18acf9286a2 100644 --- a/drivers/media/platform/ti/am437x/am437x-vpfe.c +++ b/drivers/media/platform/ti/am437x/am437x-vpfe.c @@ -1771,9 +1771,10 @@ static int vpfe_queue_setup(struct vb2_queue *vq, { struct vpfe_device *vpfe = vb2_get_drv_priv(vq); unsigned size = vpfe->fmt.fmt.pix.sizeimage; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; if (*nplanes) { if (sizes[0] < size) diff --git a/drivers/media/platform/ti/cal/cal-video.c b/drivers/media/platform/ti/cal/cal-video.c index a8abcd0fee17..94e67c057a20 100644 --- a/drivers/media/platform/ti/cal/cal-video.c +++ b/drivers/media/platform/ti/cal/cal-video.c @@ -603,9 +603,10 @@ static int cal_queue_setup(struct vb2_queue *vq, { struct cal_ctx *ctx = vb2_get_drv_priv(vq); unsigned int size = ctx->v_fmt.fmt.pix.sizeimage; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; if (*nplanes) { if (sizes[0] < size) diff --git a/drivers/media/platform/ti/davinci/vpif_capture.c b/drivers/media/platform/ti/davinci/vpif_capture.c index 99fae8830c41..fc42b4bc37e6 100644 --- a/drivers/media/platform/ti/davinci/vpif_capture.c +++ b/drivers/media/platform/ti/davinci/vpif_capture.c @@ -113,6 +113,7 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq, struct channel_obj *ch = vb2_get_drv_priv(vq); struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; unsigned size = common->fmt.fmt.pix.sizeimage; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); vpif_dbg(2, debug, "vpif_buffer_setup\n"); @@ -122,8 +123,8 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq, size = sizes[0]; } - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; *nplanes = 1; sizes[0] = size; diff --git a/drivers/media/platform/ti/davinci/vpif_display.c b/drivers/media/platform/ti/davinci/vpif_display.c index f8ec2991c667..9dbab1003c1d 100644 --- a/drivers/media/platform/ti/davinci/vpif_display.c +++ b/drivers/media/platform/ti/davinci/vpif_display.c @@ -115,6 +115,7 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq, struct channel_obj *ch = vb2_get_drv_priv(vq); struct common_obj *common = &ch->common[VPIF_VIDEO_INDEX]; unsigned size = common->fmt.fmt.pix.sizeimage; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); if (*nplanes) { if (sizes[0] < size) @@ -122,8 +123,8 @@ static int vpif_buffer_queue_setup(struct vb2_queue *vq, size = sizes[0]; } - if (vq->num_buffers + *nbuffers < 3) - *nbuffers = 3 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 3) + *nbuffers = 3 - q_num_bufs; *nplanes = 1; sizes[0] = size; diff --git a/drivers/media/platform/ti/omap/omap_vout.c b/drivers/media/platform/ti/omap/omap_vout.c index 4143274089c3..72ce903717d3 100644 --- a/drivers/media/platform/ti/omap/omap_vout.c +++ b/drivers/media/platform/ti/omap/omap_vout.c @@ -944,10 +944,11 @@ static int omap_vout_vb2_queue_setup(struct vb2_queue *vq, struct device *alloc_devs[]) { struct omap_vout_device *vout = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); int size = vout->pix.sizeimage; - if (is_rotation_enabled(vout) && vq->num_buffers + *nbufs > VRFB_NUM_BUFS) { - *nbufs = VRFB_NUM_BUFS - vq->num_buffers; + if (is_rotation_enabled(vout) && q_num_bufs + *nbufs > VRFB_NUM_BUFS) { + *nbufs = VRFB_NUM_BUFS - q_num_bufs; if (*nbufs == 0) return -EINVAL; } From patchwork Thu Oct 19 12:52:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360898vqb; Thu, 19 Oct 2023 05:57:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHp3+qasR5x85RWcwp+bsXHQ0rbb2SmFwywOyDWrecteOlY1wJiAz0YcXOxCrNPIAIqXSbf X-Received: by 2002:a17:90b:1b49:b0:27d:491d:2e40 with SMTP id nv9-20020a17090b1b4900b0027d491d2e40mr1761238pjb.22.1697720236980; Thu, 19 Oct 2023 05:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720236; cv=none; d=google.com; s=arc-20160816; b=xfBiR86/x2kAnpRn+sdaRZ8QI0NP5UDXzNpm1lhxHyI7RTY+GN6UCCnjQIHAz3EERD 08E429+o98xvsD+6ARJy1lPWE8uh5fBdmg67lYMJCZ4cLczBw0zhIOmUgcTPDmmDYmMb 0n6CvW+Qc1ntXB+L8Ikvtl4GDekdame17MjMu7c5uGRnpoW3mTscbN4RRnpkQYYjgmMX NDztR7GrawjzHlSb6JYcLFdd68qhWDJ85fWNldz/v/aa50KWJPjh7U8caHYEu6tngE0n I7jw6PSLNRkdMi9/BX2L3xUQEBYRhV1ezK0HgS/iMrNOP+ahhXpiMb55YPbY2XYLXOp+ N6Kw== 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=RNH8B9gPylxTtM01bKtOlQf9akbpmUzdDHvgh+kzWPw=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=EqlvMI+DbN2dPdWexOCe4HhO3iCjKTyuER1/MHdaUoivP2i2CR/C5I2t/iknaHCutj yRcffepvLEqyeQeEdIIljAXveZ1oNzzbrpCYk+NkwVMttx/7mGM4XLhquhrrVRrRo+0h TeAHa4HXftO5FnNqveC0F53krTP5XdZYVx1OVyyvWAfzV3LrAay2pQCrt15cRUJ6spLw u0LTUpGMeGY4M3JRmiC4uBq4NBXBYalDYTGd83NamE1DHPECaaV+XaTamOaBVUg/AVpG h6wA7TlJDyoZ8TWmrRF6G1CXD6Fi8r23aMhfVDen8MlxUUIA6G/+MeuJkcJXMvnbtyeG aAJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="kcvKob/9"; 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a3-20020a17090abe0300b0027cd01b6cb0si1919293pjs.125.2023.10.19.05.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:16 -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="kcvKob/9"; 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 AEE0A82990CC; Thu, 19 Oct 2023 05:57:06 -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 S1346234AbjJSMzc (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345956AbjJSMxS (ORCPT ); Thu, 19 Oct 2023 08:53:18 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CCCD61; Thu, 19 Oct 2023 05:52:53 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 014CE6607382; Thu, 19 Oct 2023 13:52:50 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719971; bh=KjApYJIBwjQar3zDS5eK/9rcHF3+Kx68u3lDScmGVYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcvKob/9JBRvVHTLOOOjKxOfUSntTeKcqSHyXPZc/HiO4dW78FIX29uqGvA0KmzQl LhsQBcSzP7OKzT/4x9Z7+av++aoeAbmheKpbgfKo3Kq20IW5cUED7axibzT94EqRnG OCwyhpvfpDNkJhKu5VdjBRfVoOIsJJXwaSEWPo+rZqaURnwb0yJrO128kZetbpPPb6 90dUMSdZ7rLE2kTIMjtEKXqyqCz0sQh13lMemFnrQefzrK4ZwUBtFLYso/WDZNKELL hFTAOOYEJfSEq1p/wThdz8vPKiVggYoZ7af8QOVs/iHHtt5aDndWw3NEHaHdLDPDQ6 YEIirX7J9hpaQ== 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 v13 39/56] media: usb: airspy: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:05 +0200 Message-Id: <20231019125222.21370-40-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:57:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188695133964498 X-GMAIL-MSGID: 1780188695133964498 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard --- drivers/media/usb/airspy/airspy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/airspy/airspy.c b/drivers/media/usb/airspy/airspy.c index 462eb8423506..e24e655fb1db 100644 --- a/drivers/media/usb/airspy/airspy.c +++ b/drivers/media/usb/airspy/airspy.c @@ -482,12 +482,13 @@ static int airspy_queue_setup(struct vb2_queue *vq, unsigned int *nplanes, unsigned int sizes[], struct device *alloc_devs[]) { struct airspy *s = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); dev_dbg(s->dev, "nbuffers=%d\n", *nbuffers); /* Need at least 8 buffers */ - if (vq->num_buffers + *nbuffers < 8) - *nbuffers = 8 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 8) + *nbuffers = 8 - q_num_bufs; *nplanes = 1; sizes[0] = PAGE_ALIGN(s->buffersize); From patchwork Thu Oct 19 12:52:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361499vqb; Thu, 19 Oct 2023 05:58:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGThOtmhFRLh72G4HIAunPiabq7p/CH/WXxa6cg0uZZ4Yw7N078nN/eD73Vq+vsqmCK4GFK X-Received: by 2002:a05:6830:18ca:b0:6bd:ba2c:fbbd with SMTP id v10-20020a05683018ca00b006bdba2cfbbdmr2528404ote.20.1697720308486; Thu, 19 Oct 2023 05:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720308; cv=none; d=google.com; s=arc-20160816; b=GpCk14B7Kmdpah1PlxGEZKANEOdksnKQrcX+Ch4nJTis4iS+txuBs4ZEe5sY40ibj4 uT+P5m3jb4ep5DsUo+ewkyesRvZyBxxxhFoShomfIWpwM+Kw6eXMEugBKx2zMrCa4f/2 cAMvFKASzQDaFww39yWOXH5uL4tj1hmeu6OBOZyHTjL4hAD0T4eVtyZ5zAjfNft4Y5JQ eWdAbdxvwxLjRckttRmFZUQC3TBK5kIPfBailm601Ue1eX+qmH6+B7nXdkbjnsj5OEtt SwmznNuo5ivI3TJ7/MnAGZcxOOwela9RTXCp39cp232zwBzVCOxM7kbNlTln9LitW444 MRow== 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=7TzFIwouZEcivlJJKig6vtNF+AeLrIsSqmaihWMI0/Y=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=oM2D5v39q4B7tUzJUHrb4hNgMhdkz1bssHxxlVim7YiuAvce1fOpJInDB6NUbrTCBR WUf7p075FlaOXpRuCQHVtTn1JF5vyb+sdzIrlTVUeijuxxjfb6c7ZvkiLePYbvdPcN72 2iXZRgeXAzV9g1ifXeUR33ySG/rn4ZUrcb1laSE4l2c7inNxFR0Em29Yn85CJkwQ0oyN gnJs+dXgY4AbhjIm0b24wbNsY+jlOpzR+ia6Q3BWNfZMUXhIwfufjtgiw5B3/rErEkuP MHDO7HU8OGHRnx7dKeqZFaMXOwxV2f8dM/kN6Q99DuueToAOoorJAMBRM1pwhGmNCEhI /zxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WgFF4qP6; 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 u14-20020a056a00158e00b006be322191e1si6582514pfk.254.2023.10.19.05.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:28 -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=WgFF4qP6; 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 EA9FD8229F38; Thu, 19 Oct 2023 05:58:13 -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 S1345977AbjJSMzy (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346008AbjJSMxw (ORCPT ); Thu, 19 Oct 2023 08:53: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 4B82410C3; Thu, 19 Oct 2023 05:52:56 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 79C176607383; Thu, 19 Oct 2023 13:52:51 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719971; bh=ctJwIFCoy8onwGJKVxQ8/AgSsQL3q8AbAm0x7jyK8jw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WgFF4qP6A1m1kW1mP90ZYzARSYhFCfcujQeYQFu7kypYHKTsoy08F7Bxud5fkvgcP X9VJkpyYHrMvH0pHNsF1Pv5wixUw3e5QK8T6qLZ1ME1Oa2lvAkHTGqgEnpTFEspAsj FhaKKeGrDFVq1YPbyEtGKJm99Yf0/TpVBbWez9oqWxMqmCVB89GPndujnT6DVymkNE ZNn3jGhLtrS7r6PIjka19CUqeuI906YZBE/UzB+fvK9Ab+vokgv1W0+mWmRf7y43CN 5VQK09wEvEi/J+sm4a0W+EOCqzmWkJrD2An+V0x9uQLykETwZBtFG6AHAuyRdf49UM Vn9wZlA68NXTQ== 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 v13 40/56] media: usb: cx231xx: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:06 +0200 Message-Id: <20231019125222.21370-41-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 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]); Thu, 19 Oct 2023 05:58:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188769931746460 X-GMAIL-MSGID: 1780188769931746460 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard --- drivers/media/usb/cx231xx/cx231xx-417.c | 5 +++-- drivers/media/usb/cx231xx/cx231xx-video.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/cx231xx/cx231xx-417.c b/drivers/media/usb/cx231xx/cx231xx-417.c index fe4410a5e128..45973fe690b2 100644 --- a/drivers/media/usb/cx231xx/cx231xx-417.c +++ b/drivers/media/usb/cx231xx/cx231xx-417.c @@ -1218,12 +1218,13 @@ static int queue_setup(struct vb2_queue *vq, { struct cx231xx *dev = vb2_get_drv_priv(vq); unsigned int size = mpeglinesize * mpeglines; + unsigned int q_num_bufs = vb2_get_num_buffers(vq); dev->ts1.ts_packet_size = mpeglinesize; dev->ts1.ts_packet_count = mpeglines; - if (vq->num_buffers + *nbuffers < CX231XX_MIN_BUF) - *nbuffers = CX231XX_MIN_BUF - vq->num_buffers; + if (q_num_bufs + *nbuffers < CX231XX_MIN_BUF) + *nbuffers = CX231XX_MIN_BUF - q_num_bufs; if (*nplanes) return sizes[0] < size ? -EINVAL : 0; diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c index e23b8ccd79d4..c8eb4222319d 100644 --- a/drivers/media/usb/cx231xx/cx231xx-video.c +++ b/drivers/media/usb/cx231xx/cx231xx-video.c @@ -714,11 +714,12 @@ static int queue_setup(struct vb2_queue *vq, unsigned int sizes[], struct device *alloc_devs[]) { struct cx231xx *dev = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); dev->size = (dev->width * dev->height * dev->format->depth + 7) >> 3; - if (vq->num_buffers + *nbuffers < CX231XX_MIN_BUF) - *nbuffers = CX231XX_MIN_BUF - vq->num_buffers; + if (q_num_bufs + *nbuffers < CX231XX_MIN_BUF) + *nbuffers = CX231XX_MIN_BUF - q_num_bufs; if (*nplanes) return sizes[0] < dev->size ? -EINVAL : 0; From patchwork Thu Oct 19 12:52:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361327vqb; Thu, 19 Oct 2023 05:58:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5h8BgKWrQ2nsO/G3gTJyFlNfQWf1OXZZHWi2BdH0W/Oxp4VQpmsRRs+AUbX2Z5ciZa9xE X-Received: by 2002:a05:6871:1c5:b0:1b3:8cfb:78c5 with SMTP id q5-20020a05687101c500b001b38cfb78c5mr2307225oad.34.1697720289761; Thu, 19 Oct 2023 05:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720289; cv=none; d=google.com; s=arc-20160816; b=scLiuyK7CrkcQ5bvfDdDMajHyFo8mYAmiD8j2ZkbqttzayAMUUR7YoJvUuPSbFpTAQ c7ILUkWV8cGg4JKzZfxSKV29srfIa2LYItcbQedVOzKLnB2fsM32od0sm4KcsMjSvs5P 0s/6FBVR4kAW6SVgi2HjEViL+90KOEPYTtymNE4djZvREHHDYgKXeqJR2OibpZ8LzbKg g3UqlJj0Zn3u7InqRgG57g5yMk0FA5pPQHMCz67pymM/4lH3yLZ6aMUIDnYVtYzx23Lv YwxmVfAdbg+mw4uzzHMDqbqEyKI5W/J7HUW2seTewFxbsiYAwBFXCMaGSUCqnM3PDKXO U8yA== 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=5Q7ZrRRCLUX7MQga/2Jp1mB9ALimtGx2XcWFCRhpmxI=; fh=p0AH8hgimiy85Lh1cXLIqpi5zFbeLa4s8fsQNMmUBzM=; b=v0lMiLrkVE35yZdqlNXxdfU3SMgZwttyHonI+2Jp1FEuIqiRtCbe6VRsZnv4664Byz woY8wLhv6rENAKADhWcDmZ1KltG0QWNiPQo208GCtuJSWxzRLZIga8ON9eWozdGGcxdZ WaO9bvG0heKFrkfHuBpQz/1vOn/OtEfD6hO8LW+iBjMglpISgv/yojpIeFy9xQGRk/Wy YdEytekWjn+lwKBfnHw7dWxRb+eFmw8LzSEaDBTSNLySA868ccr/H3crlK+gSdDYXora bd7Xjob8enGz7X5cWg4XRkSlybK1QJFk4rc1oOHkJO05aKAsP6WAeadKnymSxIBqQuDI BxqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=NdK5aBWy; 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 n8-20020a654508000000b005b34179728esi4432719pgq.237.2023.10.19.05.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:09 -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=NdK5aBWy; 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 D8E3C8122F0C; Thu, 19 Oct 2023 05:57:54 -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 S1345883AbjJSMzo (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345613AbjJSMxm (ORCPT ); Thu, 19 Oct 2023 08:53:42 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFBE2D6C; Thu, 19 Oct 2023 05:52:54 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 018E66607384; Thu, 19 Oct 2023 13:52:51 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719972; bh=nxe8x/V/1l6XolEQlUJAmFRKBPmiBgQL0drOV0CYbaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdK5aBWyfabr1RW/jjBwqQTxhdaELhBbiycWFPsGous3728mTSqIx/Kh+QUSaKSzV IyFmLQgPHSLU5DUGq6znakUf8WkESd4TLCYVayhHMTgSd6eI0zEGsmlo1SehDgHZ1z XFIg/8WQ6cXLjCdowQS+Q/2UcHAkbLUgu65RRGnvDdmOua2wuAv7pLH5c4Jfz+iMcH 2ZJfLecKts54kV81qruNRYiH6bGUasmwQXZs5rZt6lFxvlThx6usG5W3gwgCkpxNt8 vdbtaUtHiQnVpAk+PUjQs/uAFikNmL0Xx73nofVT7JaNel8Bj5DwQ82Vme1sbXjC/G TldwfP1mlOVVw== 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 , Antti Palosaari Subject: [PATCH v13 41/56] media: usb: hackrf: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:07 +0200 Message-Id: <20231019125222.21370-42-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 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]); Thu, 19 Oct 2023 05:57:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188750149838097 X-GMAIL-MSGID: 1780188750149838097 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard CC: Antti Palosaari --- drivers/media/usb/hackrf/hackrf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c index 3e535be2c520..9c0ecd5f056c 100644 --- a/drivers/media/usb/hackrf/hackrf.c +++ b/drivers/media/usb/hackrf/hackrf.c @@ -753,12 +753,13 @@ static int hackrf_queue_setup(struct vb2_queue *vq, unsigned int *nplanes, unsigned int sizes[], struct device *alloc_devs[]) { struct hackrf_dev *dev = vb2_get_drv_priv(vq); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); dev_dbg(dev->dev, "nbuffers=%d\n", *nbuffers); /* Need at least 8 buffers */ - if (vq->num_buffers + *nbuffers < 8) - *nbuffers = 8 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 8) + *nbuffers = 8 - q_num_bufs; *nplanes = 1; sizes[0] = PAGE_ALIGN(dev->buffersize); From patchwork Thu Oct 19 12:52:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361151vqb; Thu, 19 Oct 2023 05:57:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3bpXBymuSAu30O3cbaFOQvSssIxLTV+3JlrOXZhgBz6NBw64/l2YgBF7/lK9bEpEVlBRi X-Received: by 2002:a05:6a21:8196:b0:16b:f586:3c4 with SMTP id pd22-20020a056a21819600b0016bf58603c4mr1731928pzb.58.1697720270570; Thu, 19 Oct 2023 05:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720270; cv=none; d=google.com; s=arc-20160816; b=WbezxfxtsPKBlLHkfPuR3NAk6J1Qa34ML1Hi/5T6VPRh1IpuJIP3euIszqoD99orvS 3hk7MI8kIr9IXKbq980kFnDQQChiO21uk3b6fEA77FxYcfMCelQ81/dJymdQrzrKETAn OKwjwO8/oZ25weJlEXTbOgVxhDNmPm3wx4dUIxdid2FQ/zpIAfRV8YtG6X5LLDgitKCd AXuujgF1jOu2UgE0/V1CHe1FeluO8fUbpWkA6djwfIIUpw47u3BbtMnEmjfQBP+TRikM dO7czxz2/A0Q5sYzsx8OuQbhwcq978vQc3YZRGPAozWl5u35hMjdZzB4xMfaYK0ssZHx Jx0A== 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=cIauNEfyyc8ygY2CYOkqXtpUWGt5kjIwrFn6YVVwin8=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=c7xCos3+FwoxyywV9Hc/9YaWDiy8cQbpP7wsqkLkY8gDlI6uJ7oB4G0LnC/nI1IT64 tJTUIKZE+YpeaBJWpqFPgYmDVjSjn0hARVtL1NqgKxDgN3Le7LSYrogvp2oDd9C4i7qX rZ7zL1UByjAV+7P1azbFSdEey5L+r0iONqFn7kANccUb6OQKMR/WFKR9v809cPzavJzl OQ79Tk3uKz3UiLpQaFNBbSgW81p4BGmAa5xL0FHnaysCB7qkB/Z+ZIG9/gauRZgd4iAb /H+EJ14Pbje+D35s6xKyLYvdIpkVI+tuNHrsSn3V3kVIyo3HesTUqbTw+BQ5U20YLY8Z 4KUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WNb2jdJZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id e3-20020a17090301c300b001c5cf1c30cfsi2197604plh.435.2023.10.19.05.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=WNb2jdJZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 F21468053656; Thu, 19 Oct 2023 05:57:41 -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 S1345835AbjJSM4E (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346057AbjJSMx7 (ORCPT ); Thu, 19 Oct 2023 08:53:59 -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 8D3C310D2; Thu, 19 Oct 2023 05:52:56 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 825A66607387; Thu, 19 Oct 2023 13:52:52 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719972; bh=KPoxd/SvOk21SjAKuo9XuAAvSFR2sEuxtH4tG5ksUhg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WNb2jdJZv+aIVwQ2TG0qLbsO44v0MNz6zFaBmdmv3PzVoLr7OfAB+/Z/+VorUA0J8 LuqF3pyZViUGEsjYYnFMkksprTGNBEvcGEe6z3ghkM6UHN4aIWnH3dBBqHJrl1qOa8 W/pvthI71yevvtGdbyp/VQ7ajxAEEfneNG/tXg/nxE78Ad5AxTi0avalXcklq5wUUQ AIvhZCygpXVtvcmYQq3OrGwRbheJ1xKGnRrGBHTO1nOh5mm8rVvFPgItNBPvE3JHSC SPhrDksE+xGaoNjgO5kWOMqV3eoejokQVFSaCIx2pTs3Sw4Bhc/9nYEvcI6mGHbInY gf+zENHt0M00w== 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 v13 42/56] media: usb: usbtv: Stop direct calls to queue num_buffers field Date: Thu, 19 Oct 2023 14:52:08 +0200 Message-Id: <20231019125222.21370-43-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:57:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188730713600495 X-GMAIL-MSGID: 1780188730713600495 Use vb2_get_num_buffers() to avoid using queue num_buffers field directly. This allows us to change how the number of buffers is computed in the future. Signed-off-by: Benjamin Gaignard --- drivers/media/usb/usbtv/usbtv-video.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c index 1e30e05953dc..62a583040cd4 100644 --- a/drivers/media/usb/usbtv/usbtv-video.c +++ b/drivers/media/usb/usbtv/usbtv-video.c @@ -726,9 +726,10 @@ static int usbtv_queue_setup(struct vb2_queue *vq, { struct usbtv *usbtv = vb2_get_drv_priv(vq); unsigned size = USBTV_CHUNK * usbtv->n_chunks * 2 * sizeof(u32); + unsigned int q_num_bufs = vb2_get_num_buffers(vq); - if (vq->num_buffers + *nbuffers < 2) - *nbuffers = 2 - vq->num_buffers; + if (q_num_bufs + *nbuffers < 2) + *nbuffers = 2 - q_num_bufs; if (*nplanes) return sizes[0] < size ? -EINVAL : 0; *nplanes = 1; From patchwork Thu Oct 19 12:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361414vqb; Thu, 19 Oct 2023 05:58:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZVAu9G/s2YLp7HozDVBTJ9BoPPbTEtU8vRhhbhaCYydZ0maHBfYbQODRiP0WcAIN/Fvqe X-Received: by 2002:a17:90a:bc81:b0:27d:3fa4:9d9a with SMTP id x1-20020a17090abc8100b0027d3fa49d9amr1977350pjr.29.1697720298441; Thu, 19 Oct 2023 05:58:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720298; cv=none; d=google.com; s=arc-20160816; b=alKr5yge3sNBIvqqIdSQ/cZUZ/oK0Y8EvwMq9XW6Is2uG+8AMFXBpXwBJiEeZQLAPl 48Fr5CG/DtglWIeeSbtVE9/ISAZA8YlN7nndXZ/1pf/KmSTPGyi/KO0N61JnfX90mOH9 yT/5tATkj+unNZxDaTzyYWwW1WbqiMlGtckXQtOzZxpGt1L5ezF61s/b6mmUAFC97o/6 +gP4BpFO5SARfyJT5M1oGmCxb/3Yn+FZjw+R9TfRwrNp0zUl+yDJjvREPTcWi2LD4kxS H1hvy/UhRgZuN5TsEt1XNpfdOha2QlUJKvgxZwiAAoBtYUDxAEfTCpWCqxzJAoxE8mSH Xs7Q== 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=ijZwvx1lMdTOgEnHEazE2oOnj/dSF65KpoV68g0G+NY=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=s6/+CQ5wxP/6ffhVlcnIrbcolRVW4D9uYIqG22mBNUAg3NZGPaenqVtDmjmg1uMC+n HdqL2uoKjK1BPppIir2gLpQehuxIv0ofRQgFh36lc4ysd/lRSTLPExnhcDjcCQx0amzq BU44Tg64OEFdzS47ahE/Kl+ZXiyRqtbYfpTO1DWZLA0N9CWANYFZBZebaCSAQlJtY/bo UnLXsswNhDThkX9t/7ey/L/++BFa1sQEB17bwRXuToMfjrV0ViL9V4tDJCYu3H8/fOfd TuQIgaZFZ2EqQC36PG1LoSveOonO6OwjkSCFzqxjVMDk+GYJk6pOUBgvtJ+4UWfl0U3X rhng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XtlkQ0Kf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c8-20020a17090a8d0800b0027d1b1eb03esi1983319pjo.94.2023.10.19.05.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XtlkQ0Kf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 64BAF808985E; Thu, 19 Oct 2023 05:58:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346027AbjJSM4I (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346064AbjJSMyA (ORCPT ); Thu, 19 Oct 2023 08:54:00 -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 8EB5010DA; Thu, 19 Oct 2023 05:52:57 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 0A0016607388; Thu, 19 Oct 2023 13:52:53 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719973; bh=3YwRlaXqNfFfD+MkhjUYf3+OoF9vhFr7cj3UeTq3BQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XtlkQ0KfYZvwfnaPXA8i5VDU8QCBwypnEdjtXYf+XL0nK973U1h4RGazN8EcgqrIZ no+2LwUy58eyk8X2RfikyDg2jaMYT/Kl1lU1NbhcLD/1eFhGPm3oNLf8z2mp+t4kgF 9Z4U4AHveqoEkB9tKTmEQHC2IKPp9NunvgC2esT0w3gqgQIOza+uIkKdJWXbQFXLuV 49slGh3vZjTQhL7GuWfprsF/0TvM2wGsCpIWYBxTO3/D41mSECiQVeH/UaJhUxw9DK z5Q5P/MvxDlWhUJ8lUV8VbFizkS0e9k2/b8dchVZBgj1pC8l03VPupN9xL+SVpRrdN mf9a61OHhJINA== 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 v13 43/56] media: videobuf2: Be more flexible on the number of queue stored buffers Date: Thu, 19 Oct 2023 14:52:09 +0200 Message-Id: <20231019125222.21370-44-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:58:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188759700699298 X-GMAIL-MSGID: 1780188759700699298 Add 'max_num_buffers' field in vb2_queue struct to let drivers decide how many buffers could be stored in a queue. This require 'bufs' array to be allocated at queue init time and freed when releasing the queue. By default VB2_MAX_FRAME remains the limit. Signed-off-by: Benjamin Gaignard Signed-off-by: Hans Verkuil --- .../media/common/videobuf2/videobuf2-core.c | 41 +++++++++++++++---- .../media/common/videobuf2/videobuf2-v4l2.c | 6 +-- include/media/videobuf2-core.h | 10 ++++- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index c5c5ae4d213d..72ef7179d80a 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -416,7 +416,7 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) */ static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index) { - WARN_ON(index >= VB2_MAX_FRAME || q->bufs[index]); + WARN_ON(index >= q->max_num_buffers || q->bufs[index]); q->bufs[index] = vb; vb->index = index; @@ -449,9 +449,9 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, struct vb2_buffer *vb; int ret; - /* Ensure that q->num_buffers+num_buffers is below VB2_MAX_FRAME */ + /* Ensure that the number of already queue + num_buffers is below q->max_num_buffers */ num_buffers = min_t(unsigned int, num_buffers, - VB2_MAX_FRAME - q_num_buffers); + q->max_num_buffers - q_num_buffers); for (buffer = 0; buffer < num_buffers; ++buffer) { /* Allocate vb2 buffer structures */ @@ -813,7 +813,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; unsigned int i; - int ret; + int ret = 0; if (q->streaming) { dprintk(q, 1, "streaming active\n"); @@ -857,17 +857,22 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - WARN_ON(q->min_buffers_needed > VB2_MAX_FRAME); num_buffers = max_t(unsigned int, *count, q->min_buffers_needed); - num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); + num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); /* * Set this now to ensure that drivers see the correct q->memory value * in the queue_setup op. */ mutex_lock(&q->mmap_lock); + if (!q->bufs) + q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); + if (!q->bufs) + ret = -ENOMEM; q->memory = memory; mutex_unlock(&q->mmap_lock); + if (ret) + return ret; set_queue_coherency(q, non_coherent_mem); /* @@ -976,7 +981,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, bool no_previous_buffers = !q_num_bufs; int ret = 0; - if (q_num_bufs == VB2_MAX_FRAME) { + if (q->num_buffers == q->max_num_buffers) { dprintk(q, 1, "maximum number of buffers already allocated\n"); return -ENOBUFS; } @@ -993,7 +998,13 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, */ mutex_lock(&q->mmap_lock); q->memory = memory; + if (!q->bufs) + q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); + if (!q->bufs) + ret = -ENOMEM; mutex_unlock(&q->mmap_lock); + if (ret) + return ret; q->waiting_for_buffers = !q->is_output; set_queue_coherency(q, non_coherent_mem); } else { @@ -1005,7 +1016,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return -EINVAL; } - num_buffers = min(*count, VB2_MAX_FRAME - q_num_bufs); + num_buffers = min(*count, q->max_num_buffers - q_num_bufs); if (requested_planes && requested_sizes) { num_planes = requested_planes; @@ -2465,6 +2476,12 @@ int vb2_core_queue_init(struct vb2_queue *q) /* * Sanity check */ + if (!q->max_num_buffers) + q->max_num_buffers = VB2_MAX_FRAME; + + /* The maximum is limited by offset cookie encoding pattern */ + q->max_num_buffers = min_t(unsigned int, q->max_num_buffers, MAX_BUFFER_INDEX); + if (WARN_ON(!q) || WARN_ON(!q->ops) || WARN_ON(!q->mem_ops) || @@ -2474,6 +2491,10 @@ int vb2_core_queue_init(struct vb2_queue *q) WARN_ON(!q->ops->buf_queue)) return -EINVAL; + if (WARN_ON(q->max_num_buffers > MAX_BUFFER_INDEX) || + WARN_ON(q->min_buffers_needed > q->max_num_buffers)) + return -EINVAL; + if (WARN_ON(q->requires_requests && !q->supports_requests)) return -EINVAL; @@ -2519,7 +2540,9 @@ 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, vb2_get_num_buffers(q)); + __vb2_queue_free(q, q->max_num_buffers); + kfree(q->bufs); + q->bufs = NULL; q->num_buffers = 0; mutex_unlock(&q->mmap_lock); } diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 7d798fb15c0b..f3cf4b235c1f 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -627,7 +627,7 @@ struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp) * This loop doesn't scale if there is a really large number of buffers. * Maybe something more efficient will be needed in this case. */ - for (i = 0; i < vb2_get_num_buffers(q); i++) { + for (i = 0; i < q->max_num_buffers; i++) { vb2 = vb2_get_buffer(q, i); if (!vb2) @@ -1142,7 +1142,7 @@ int _vb2_fop_release(struct file *file, struct mutex *lock) if (lock) mutex_lock(lock); - if (file->private_data == vdev->queue->owner) { + if (!vdev->queue->owner || file->private_data == vdev->queue->owner) { vb2_queue_release(vdev->queue); vdev->queue->owner = NULL; } @@ -1270,7 +1270,7 @@ void vb2_video_unregister_device(struct video_device *vdev) */ get_device(&vdev->dev); video_unregister_device(vdev); - if (vdev->queue && vdev->queue->owner) { + if (vdev->queue) { struct mutex *lock = vdev->queue->lock ? vdev->queue->lock : vdev->lock; diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 8f9d9e4af5b1..e77a397195f2 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -558,6 +558,7 @@ struct vb2_buf_ops { * @dma_dir: DMA mapping direction. * @bufs: videobuf2 buffer structures * @num_buffers: number of allocated/used buffers + * @max_num_buffers: upper limit of number of allocated/used buffers * @queued_list: list of buffers currently queued from userspace * @queued_count: number of buffers queued and ready for streaming. * @owned_by_drv_count: number of buffers owned by the driver @@ -619,8 +620,9 @@ struct vb2_queue { struct mutex mmap_lock; unsigned int memory; enum dma_data_direction dma_dir; - struct vb2_buffer *bufs[VB2_MAX_FRAME]; + struct vb2_buffer **bufs; unsigned int num_buffers; + unsigned int max_num_buffers; struct list_head queued_list; unsigned int queued_count; @@ -1248,6 +1250,12 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q) static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, unsigned int index) { + if (!q->bufs) + return NULL; + + if (index >= q->max_num_buffers) + return NULL; + if (index < q->num_buffers) return q->bufs[index]; return NULL; From patchwork Thu Oct 19 12:52:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361445vqb; Thu, 19 Oct 2023 05:58:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeYICqCCJ6OKKobsRTVYQMUK5iwm+XV20U5Kwv+ywiKwYIA4leH4br6lsdJkQOaHPWnzu5 X-Received: by 2002:a05:6a21:18e:b0:159:cf93:9b50 with SMTP id le14-20020a056a21018e00b00159cf939b50mr2532187pzb.46.1697720301515; Thu, 19 Oct 2023 05:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720301; cv=none; d=google.com; s=arc-20160816; b=ln3LkhWPDkahJ9MavNldQQngKZLAu2NwY/u4t5ZKNzpU5Z+QkAzt7RcDajquFm6ug+ eASjP9WY6ipOkp2YAhBjKdwdVIhZ0qhYDDP347KygRe0+gJ1bZQaictD8J12E235jXGS gToW5YKZ3r+yS1HzZZ80DWu8/KE7B7jM/JuE5Y1472VaemMXEa58tXbnXa9TG3Xol8pH yzpYAgSTOFk/6eNr9SJLu6wjN2JhYuFjGXqegDNvXLp6PaVSqUrBlRIWQ5I1Dqqnmi78 Mpwl0vhXYK/0Ah5qrELF0JDa52mru8SYBASbDq9EoQq51UjeeT1S3MUWktGrGxJifG3s rLew== 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=D+v7ZuNGnQ24B7OnkVwAaKkIQcrJnzwSEWFpsdSWHIU=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=1C7lMVwr+yxniRPyQEi7xUsQTsNS7bmxOkWF7hM+aEOghimifXu9VCB4iIX2Zpklpb UYudpXlQczKU+H7ZnuUccxZn5AR5bFRBsUoL2b4QIW/DSc21RcbI5MJHoskgb0PIkhb2 3tJBEB9rzHh6/GaQEmv3y+pproxe7yTt1JCIQU+syK6cYQo0jxeGSlYSHrluhjn7QrJ1 dbqUoASmIv/hbo429aOd+yNqFziyywsKUQRBFgBy72lX/DG/bzS0tCJZFI7bqerH/mDm L1FvnOzQdmaX8RNhk3MnhcSd3ZoZwo1jF0FnzOyWLBeW+jb1LHRiJt09u38Z+nEBW13c Jggg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=l4mBQmNU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q6-20020a63cc46000000b005ab1f1ef721si4102102pgi.888.2023.10.19.05.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=l4mBQmNU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 DF4E681ADCF9; Thu, 19 Oct 2023 05:58:08 -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 S1346002AbjJSMzv (ORCPT + 25 others); Thu, 19 Oct 2023 08:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346042AbjJSMx5 (ORCPT ); Thu, 19 Oct 2023 08:53:57 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30779D7C; Thu, 19 Oct 2023 05:52:55 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 84302660738B; Thu, 19 Oct 2023 13:52:53 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719973; bh=XSDQo9OCo2ZP1hI11u5UCcW4nwnvTW2khdQbpXxmYvM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l4mBQmNUu+zfstY6x5b+83LTIR3bVCAJKgd8WpNg/++NwUE3PYhJhD/c4ailVCV+p hFIdZI8GIBzT745cAwzuT9d3vJj7gkYSdra3gyvquJ6g34h4oJW+/mY1qUzUookojH zG1cMQqca9um1l2E0xBFc7Fyj4VK0jqcGt3E5NSFfUZaaOgbVMbliK2ThidmGRY+bj ee9jaDct9riM2Xb5PcW2XrqMVnPzv7HCUMpTtDS8AnyHfD2fTSYtvgrLOUzUY7piGs kiN6jV0zI9T0eXjbLe5shzRi+sqZ+/GPQYG5Aipv8l7RfpMZKfvw0AjwfY6BvgD8N9 S5O3BgDWV3FxA== 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 v13 44/56] media: core: Report the maximum possible number of buffers for the queue Date: Thu, 19 Oct 2023 14:52:10 +0200 Message-Id: <20231019125222.21370-45-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:58:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188762613781311 X-GMAIL-MSGID: 1780188762613781311 Use one of the struct v4l2_create_buffers reserved bytes to report the maximum possible number of buffers for the queue. V4l2 framework set V4L2_BUF_CAP_SUPPORTS_SET_MAX_BUFS flags in queue capabilities so userland can know when the field is valid. Signed-off-by: Benjamin Gaignard --- .../userspace-api/media/v4l/vidioc-create-bufs.rst | 8 ++++++-- Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst | 1 + drivers/media/common/videobuf2/videobuf2-v4l2.c | 2 ++ drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++-- include/uapi/linux/videodev2.h | 7 ++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst b/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst index a048a9f6b7b6..49232c9006c2 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst @@ -116,9 +116,13 @@ than the number requested. - ``flags`` - Specifies additional buffer management attributes. See :ref:`memory-flags`. - * - __u32 - - ``reserved``\ [6] + - ``max_num_buffers`` + - If the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set + this field indicates the maximum possible number of buffers + for this queue. + * - __u32 + - ``reserved``\ [5] - A place holder for future extensions. Drivers and applications must set the array to zero. diff --git a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst index 099fa6695167..0b3a41a45d05 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst @@ -120,6 +120,7 @@ aborting or finishing any DMA in progress, an implicit .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS: .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: +.. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS: .. raw:: latex diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index f3cf4b235c1f..bdfc3a253c65 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -762,6 +762,8 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) fill_buf_caps(q, &create->capabilities); validate_memory_flags(q, create->memory, &create->flags); create->index = vb2_get_num_buffers(q); + create->max_num_buffers = q->max_num_buffers; + create->capabilities |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS; if (create->count == 0) return ret != -EBUSY ? ret : 0; diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 9b1de54ce379..628b013ca0c4 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -483,9 +483,9 @@ static void v4l_print_create_buffers(const void *arg, bool write_only) { const struct v4l2_create_buffers *p = arg; - pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, ", + pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, max buffers=%u", p->index, p->count, prt_names(p->memory, v4l2_memory_names), - p->capabilities); + p->capabilities, p->max_num_buffers); v4l_print_format(&p->format, write_only); } diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index c3d4e490ce7c..13ddb5abf584 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1035,6 +1035,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4) #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) +#define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) /** * struct v4l2_plane - plane info for multi-planar buffers @@ -2605,6 +2606,9 @@ struct v4l2_dbg_chip_info { * @flags: additional buffer management attributes (ignored unless the * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability * and configured for MMAP streaming I/O). + * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set + * this field indicate the maximum possible number of buffers + * for this queue. * @reserved: future extensions */ struct v4l2_create_buffers { @@ -2614,7 +2618,8 @@ struct v4l2_create_buffers { struct v4l2_format format; __u32 capabilities; __u32 flags; - __u32 reserved[6]; + __u32 max_num_buffers; + __u32 reserved[5]; }; /* From patchwork Thu Oct 19 12:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361015vqb; Thu, 19 Oct 2023 05:57:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhrxaSg8UhKDKk/2G6RU+4EjDF+9vOa8+n8jjdP5rBF5WFBhPlpRTmrDQi9TJKKmbAHkZ9 X-Received: by 2002:a17:902:e807:b0:1ca:bce4:fdd4 with SMTP id u7-20020a170902e80700b001cabce4fdd4mr1157403plg.26.1697720251630; Thu, 19 Oct 2023 05:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720251; cv=none; d=google.com; s=arc-20160816; b=fUay0Hb8dLW2nwuB+tW5yfeEE1Siml8+IpafUUYBB2JTu7e8Nu1wwjK+ZQ8Y2Z2Clc PtpHymVuWDdT39ugP1bdWsetn8kEHouQPPDycQpZzgdvAJK14bFd56YfzcjLXMyXV7pG tAU3PuwA07qRWs7XYRMmLAQ3t3H1z6z327XUqXKagsdYmMQhjCFVqY7QohqB8IdLx91B FTSRgPRjV1QkfbF2jAF7eBEtOZIubKpJZ1AIYaTxTJ3XJ2quj41Aw1+l6iYPEESy74Mb Ct4oI1VpsfuqpMkUEA9D7ltWEYBWIarXcvUJqCHDmdN8WIHzUHfXDc0U4BPFtU55W7pY /sUA== 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=MItFHTI4Se0Okjdyeb5n9vVVB1fx43fYR5gei7a9yCQ=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=KA+NMNLSyMS6qchGjxZvN37zrAppN+PL8woMkhVlkApDI9qTZiYjv2pMTcIwKNTTGA qqlNNhEEZW5ltMkjFVl/R8y0DmgjpCndGmi0WfwziNz4HRAu3DnoyS7jtNkuH4Y1yPS0 jUqAZEGwUWV5nlSSQQ8g14sNX624BZN8WPOvkpOOlRXm6WG69dN0knit+l71jjRRiDQK 7gKErPZrdTwy5NHBsBEhUXbf++gzfkZc8NuTDbBgl072Xp1c/mdgyQuY6odw9XlYGKos Kck3bkIM3fi891nZkGN3dfL3MncMRXu7mvQ5hc4C2glWHmI79wIbscIrDds7t+LMf3fS lkKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="YWd8Ieh/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id p17-20020a170902ead100b001c370dc4445si2112539pld.210.2023.10.19.05.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="YWd8Ieh/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id DBC0F819BB40; Thu, 19 Oct 2023 05:57:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345780AbjJSM4L (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346077AbjJSMyB (ORCPT ); Thu, 19 Oct 2023 08:54:01 -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 A9D1E10E0; Thu, 19 Oct 2023 05:52:57 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 0B6B56607340; Thu, 19 Oct 2023 13:52:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719974; bh=E3AWNXfqW3zClMdST89v07/d3n0L7Gb4S89ZZv8t3hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWd8Ieh/PoU2vj6Z21u8Z7NJkcVvlaN2gp5mBFW8vjdxGMCgdCuOPIPGEQ9tE1mTn CdRLX9dLap0lDcUnK9ShLK/FXHgNS0PGPwAk+632eH+/SEKFWwg+57CZHEDzQy8UiE qW/swYZdnLcWsRjJIcNqv38iHmMqBXdt9xlSy88T7qBQzaqTuaKCd+5HCxixLTiBBR iHIGZmQrFya6v2O8IDZHALPB6nul06U01Q7UblqHw7LGKApteMbKtyQPDuCuoorUO+ 3h0il+Owp3W//jrwBbIIIAgm2SplrjDjrLH4oIFXK5wDqui+j1xEyMLnlxgnkIekrS /jcTzbfkIZpFQ== 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 v13 45/56] media: test-drivers: vivid: Increase max supported buffers for capture queues Date: Thu, 19 Oct 2023 14:52:11 +0200 Message-Id: <20231019125222.21370-46-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188710323682005 X-GMAIL-MSGID: 1780188710323682005 Change the maximum number of buffers of some capture queues in order to test max_num_buffers field. Allow to allocate up to: - 64 buffers for video capture queue. - 1024 buffers for sdr capture queue. - 32768 buffers for vbi capture queue. Signed-off-by: Benjamin Gaignard --- drivers/media/test-drivers/vivid/vivid-core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index 394c9f81ea72..353f035fcd19 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -876,6 +876,20 @@ static int vivid_create_queue(struct vivid_dev *dev, q->type = buf_type; q->io_modes = VB2_MMAP | VB2_DMABUF; q->io_modes |= V4L2_TYPE_IS_OUTPUT(buf_type) ? VB2_WRITE : VB2_READ; + + /* + * The maximum number of buffers is 32768 if PAGE_SHIFT == 12, + * see also MAX_BUFFER_INDEX in videobuf2-core.c. It will be less if + * PAGE_SHIFT > 12, but then max_num_buffers will be clamped by + * videobuf2-core.c to MAX_BUFFER_INDEX. + */ + if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + q->max_num_buffers = 64; + if (buf_type == V4L2_BUF_TYPE_SDR_CAPTURE) + q->max_num_buffers = 1024; + if (buf_type == V4L2_BUF_TYPE_VBI_CAPTURE) + q->max_num_buffers = 32768; + if (allocators[dev->inst] != 1) q->io_modes |= VB2_USERPTR; q->drv_priv = dev; From patchwork Thu Oct 19 12:52:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360877vqb; Thu, 19 Oct 2023 05:57:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZsJfJixbgrcz+CuUQMY+VbZxbaPyhQn8a3l4k2Ri7jD3n0O+tSC427NZSUW7Ubz734RXQ X-Received: by 2002:a17:902:db11:b0:1ca:2caa:aca5 with SMTP id m17-20020a170902db1100b001ca2caaaca5mr2500440plx.1.1697720233231; Thu, 19 Oct 2023 05:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720233; cv=none; d=google.com; s=arc-20160816; b=scndWOx8BshPWzNLd29fO5rauQ6UNNWcU6xagZe5buspyRghHs99LSUAwfUO0CKqsl umWOkaDsxvG1E5uoi/q/izxGWtpR+eibgVraW5agDAeKTT1WYZ+8jrDup2DpHbRxO1bw 2W9K2r89JZtTv2j8ddTc9RaF9IrHT0Aja0eMF9Lvh86To0G6FXyiLaaWWDY5moSNuAdr c95Le25QNosNQz6nX88lkoVBBMR6UF+GiD1LYCFPDmSuWN/Xhv7s0FHrydze8QV+kTHj UcFWRHbYHNtvKy+itjDFtf2NjSlAps3olnaI620HUXXoc3Xep1IIDFV3pyEEJSRjJo1S Cyvw== 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=cUa/TY+Am8ySB21RfaC1a0J9/53VTglM2vrOBadwXyE=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=bX8ui6eRlhwgDhLFpoz4VBxx+P61eeq7RivopkaVQKxkuaMbIx9QrwiwcbHuK1w+yQ c3Jq+lT6U3z0TnMOGR1gvgVyKFkrYXo0mzzUvl+9jHCBX03exFNZW09Y1kGKjveD0gAf Csh3yUYF0Qwaa/n2Gqpl51z18I20JNUFki7Hb4/YySz02cvV/nwpvoheYjOY/2PSpvdn UQfD6CBN3E4/ZWMbwZZcoc/dYnjkypo1xlOW6xXhTXN7eOfNsya4mewUR29cOQ48Wi+I Nco1FehFs7VCbGdrUM4ms8DhEqV4bAESPfEk4e+or5LJL3p7Nv0a20ho0AcLFX94PfoR 4etA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=mIR2tZXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id d13-20020a170902c18d00b001ca67f26f5esi1984353pld.283.2023.10.19.05.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=mIR2tZXl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 82F258198C61; Thu, 19 Oct 2023 05:56:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346005AbjJSM4A (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346069AbjJSMyA (ORCPT ); Thu, 19 Oct 2023 08:54:00 -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 A9E2710E2; Thu, 19 Oct 2023 05:52:57 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 86370660738D; Thu, 19 Oct 2023 13:52:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719974; bh=/rw+5kiG9NH9F1WJEwdp/d4z1jjMgH/1J5yw8ccESj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIR2tZXl8DmrL/2bk+DGVUYWluO9TTzxDFzzsmbrHtctGCWmNklellAYVGoQCkOnK yAknNJCWhuZZxH1YViOjD8NMqB01ZMzBZz/Qm/xZzCluovUY3iQN240dL/ETnH1XbY I41PIJ0t2gX1EbdTsIr3KAjIx1DA6226/8w7shEAc19BkWo5JRQ/bWCYQ6hL+iZog6 hMDvE1L7x5LhfPFMy3QL3KbhRxQOJ0az1tv2FG4zYaO9d1wCGJH1D7HnyX5sH8Cqtu dkIguE2D/ilQXuZ+DqjAjkpldgVzw9zHM9VN1ofmdsugr9Y72RJxZI5XhQKUzFXCu8 j2yocHxQSBY2w== 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 v13 46/56] media: test-drivers: vicodec: Increase max supported capture queue buffers Date: Thu, 19 Oct 2023 14:52:12 +0200 Message-Id: <20231019125222.21370-47-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:56:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188691072777156 X-GMAIL-MSGID: 1780188691072777156 Allow to allocated up to 64 buffers on capture queue. Signed-off-by: Benjamin Gaignard --- drivers/media/test-drivers/vicodec/vicodec-core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c index 6f0e20df74e9..69cbe2c094e1 100644 --- a/drivers/media/test-drivers/vicodec/vicodec-core.c +++ b/drivers/media/test-drivers/vicodec/vicodec-core.c @@ -1718,6 +1718,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE : V4L2_BUF_TYPE_VIDEO_CAPTURE); dst_vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; + dst_vq->max_num_buffers = 64; dst_vq->drv_priv = ctx; dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); dst_vq->ops = &vicodec_qops; From patchwork Thu Oct 19 12:52:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361102vqb; Thu, 19 Oct 2023 05:57:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3/PlN0C6ZCB53jlVOo4bk05aWXzzFmFFX5JxjAgmVvWRUVe9SoW2WXOj4F63qJcAox2LW X-Received: by 2002:a17:902:f945:b0:1c9:d908:d60c with SMTP id kx5-20020a170902f94500b001c9d908d60cmr2219951plb.63.1697720263932; Thu, 19 Oct 2023 05:57:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720263; cv=none; d=google.com; s=arc-20160816; b=MGsEE/iu8evBbtWcH+Ss58cUQJAdk+K2hBSfrkkhrPd7c2sj71dcYBuvvhX0tiEgUe FG3OB/zw41Kv3BCh9s4j8nawkQe6VspyveK8/GAxJig86n9L3UcHHAhxnyrw1XRbsbaz sgOtdfb/vkJy6jpj1vZDdKwMbGn1vogQ35cWAVMmLLvMF078mUjEM2CdlIfHfGKmhbuJ G5I/QOfwx5NZJc8np/ZMoxqQ416PJQWw5OOR97VAn/eFuZWnaNIs0iux79ZB/+jt1GhY q02UMFSNBkKrGPwXCcDaPceiSnC+ODUCPP8772chMgDkuD48z9VxJ+0G3h13mHZGhvlK gRRw== 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=rDZ5S4QbwaTBx24HSBQddHus2mJryWMzPAdt5ItaHrI=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=Z8SbYgQA34jHscsbb/8Mrdc/pyeBFGzK/Cu36yL1O6XGGpgKt1bYsb9yXUUcQVj/gj rQ6iD0DCgwGYQpIA5BJ248oJoQ9R5BO+cWyHSNBUd5xOvz9rlr6gPReynqFHNBnFVydQ 5YToiBSbNNA/gJQ9sfIRCxEYMD2f99ocgi4EETZSHEhPbjqrSKCAzoA8hKVyr5Mkk/f2 eM7iloQAJCf5c8l9bimO+uTvSY0YlVP8st/Zwpbl/i9Kr8ulaE6OlT9P+LEHOVPBZhpy cr3enCLyn1wgqw7BoUWjMf9v6w57R03Sycw2iFV/2zRan4dawsVV1SqpyhqQom6Opg0k TNGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Om1yrOKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id c15-20020a170903234f00b001bb8a57d518si2262042plh.379.2023.10.19.05.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Om1yrOKn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 2514A802B286; Thu, 19 Oct 2023 05:57:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346152AbjJSM4a (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346084AbjJSMyB (ORCPT ); Thu, 19 Oct 2023 08:54:01 -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 1508A10E7; Thu, 19 Oct 2023 05:52:58 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 131FF6607390; Thu, 19 Oct 2023 13:52:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719975; bh=Io9Tjb5cn8uE3Kz5+BqDVsKX8mjkDcVIhuocPLDRTU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Om1yrOKnRERhQsTNdyiP4XVZHA8qez3FrmxJcATlkZ+vR72GYp0K0mgfGMSpJOLtZ Vt4D0HXYJep12Tsd6BydQNRACi1bvnCLSYI9aYy4loIdo7BjQrD1UI+TMH9LoX1xRq 2DY7gAKV1RFlosxmDkiaZF9PF1xf5QyWdEwc71n56RNiSKD1DHsnkgzRaK/a48KdRV 8/NwxMLwQEyHHWmj0ftMjw6M2AktXmRYJ0YL/v0wBVFWmqHm2Sqytsie0Wk8SI5M/1 ES5s7JMpXsruyX/OTuVXaOWRcxkM6kj96UDTRNb2MgaZZHR6KLB+LbIPJ1zRDMturi X6dNSXWo5AIvQ== 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 v13 47/56] media: verisilicon: Refactor postprocessor to store more buffers Date: Thu, 19 Oct 2023 14:52:13 +0200 Message-Id: <20231019125222.21370-48-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188723232347604 X-GMAIL-MSGID: 1780188723232347604 Since vb2 queue can store more than VB2_MAX_FRAME buffers, the postprocessor buffer storage must be capable to store more buffers too. Change static dec_q array to allocated array to be capable to store up to queue 'max_num_buffers'. Keep allocating queue 'num_buffers' at queue setup time but also allows to allocate postprocessors buffers on the fly. Signed-off-by: Benjamin Gaignard CC: Ezequiel Garcia CC: Philipp Zabel --- drivers/media/platform/verisilicon/hantro.h | 7 +- .../media/platform/verisilicon/hantro_drv.c | 4 +- .../media/platform/verisilicon/hantro_hw.h | 4 +- .../platform/verisilicon/hantro_postproc.c | 93 +++++++++++++++---- .../media/platform/verisilicon/hantro_v4l2.c | 2 +- 5 files changed, 85 insertions(+), 25 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h index 77aee9489516..0948b04a9f8d 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -469,11 +469,14 @@ hantro_get_dst_buf(struct hantro_ctx *ctx) bool hantro_needs_postproc(const struct hantro_ctx *ctx, const struct hantro_fmt *fmt); +dma_addr_t +hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index); + static inline dma_addr_t hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb) { if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt)) - return ctx->postproc.dec_q[vb->index].dma; + return hantro_postproc_get_dec_buf_addr(ctx, vb->index); return vb2_dma_contig_plane_dma_addr(vb, 0); } @@ -485,8 +488,8 @@ vb2_to_hantro_decoded_buf(struct vb2_buffer *buf) void hantro_postproc_disable(struct hantro_ctx *ctx); void hantro_postproc_enable(struct hantro_ctx *ctx); +int hantro_postproc_init(struct hantro_ctx *ctx); void hantro_postproc_free(struct hantro_ctx *ctx); -int hantro_postproc_alloc(struct hantro_ctx *ctx); int hanto_postproc_enum_framesizes(struct hantro_ctx *ctx, struct v4l2_frmsizeenum *fsize); diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index a9fa05ac56a9..7f5b82eb6649 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -235,8 +235,10 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) * The Kernel needs access to the JPEG destination buffer for the * JPEG encoder to fill in the JPEG headers. */ - if (!ctx->is_encoder) + if (!ctx->is_encoder) { dst_vq->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING; + dst_vq->max_num_buffers = MAX_POSTPROC_BUFFERS; + } dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; dst_vq->io_modes = VB2_MMAP | VB2_DMABUF; diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h index 7f33f7b07ce4..292a76ef643e 100644 --- a/drivers/media/platform/verisilicon/hantro_hw.h +++ b/drivers/media/platform/verisilicon/hantro_hw.h @@ -40,6 +40,8 @@ #define AV1_MAX_FRAME_BUF_COUNT (V4L2_AV1_TOTAL_REFS_PER_FRAME + 1) +#define MAX_POSTPROC_BUFFERS 64 + struct hantro_dev; struct hantro_ctx; struct hantro_buf; @@ -336,7 +338,7 @@ struct hantro_av1_dec_hw_ctx { * @dec_q: References buffers, in decoder format. */ struct hantro_postproc_ctx { - struct hantro_aux_buf dec_q[VB2_MAX_FRAME]; + struct hantro_aux_buf dec_q[MAX_POSTPROC_BUFFERS]; }; /** diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c index 8f8f17e671ce..41e93176300b 100644 --- a/drivers/media/platform/verisilicon/hantro_postproc.c +++ b/drivers/media/platform/verisilicon/hantro_postproc.c @@ -177,9 +177,11 @@ static int hantro_postproc_g2_enum_framesizes(struct hantro_ctx *ctx, void hantro_postproc_free(struct hantro_ctx *ctx) { struct hantro_dev *vpu = ctx->dev; + struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; + struct vb2_queue *queue = &m2m_ctx->cap_q_ctx.q; unsigned int i; - for (i = 0; i < VB2_MAX_FRAME; ++i) { + for (i = 0; i < queue->max_num_buffers; ++i) { struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i]; if (priv->cpu) { @@ -190,20 +192,17 @@ void hantro_postproc_free(struct hantro_ctx *ctx) } } -int hantro_postproc_alloc(struct hantro_ctx *ctx) +static unsigned int hantro_postproc_buffer_size(struct hantro_ctx *ctx) { - struct hantro_dev *vpu = ctx->dev; - struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; - struct vb2_queue *cap_queue = &m2m_ctx->cap_q_ctx.q; - unsigned int num_buffers = vb2_get_num_buffers(cap_queue); struct v4l2_pix_format_mplane pix_mp; const struct hantro_fmt *fmt; - unsigned int i, buf_size; + unsigned int buf_size; /* this should always pick native format */ fmt = hantro_get_default_fmt(ctx, false, ctx->bit_depth, HANTRO_AUTO_POSTPROC); if (!fmt) - return -EINVAL; + return 0; + v4l2_fill_pixfmt_mp(&pix_mp, fmt->fourcc, ctx->src_fmt.width, ctx->src_fmt.height); @@ -221,23 +220,77 @@ int hantro_postproc_alloc(struct hantro_ctx *ctx) buf_size += hantro_av1_mv_size(pix_mp.width, pix_mp.height); - for (i = 0; i < num_buffers; ++i) { - struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i]; + return buf_size; +} + +static int hantro_postproc_alloc(struct hantro_ctx *ctx, int index) +{ + struct hantro_dev *vpu = ctx->dev; + struct hantro_aux_buf *priv = &ctx->postproc.dec_q[index]; + unsigned int buf_size = hantro_postproc_buffer_size(ctx); + + if (!buf_size) + return -EINVAL; + + /* + * The buffers on this queue are meant as intermediate + * buffers for the decoder, so no mapping is needed. + */ + priv->attrs = DMA_ATTR_NO_KERNEL_MAPPING; + priv->cpu = dma_alloc_attrs(vpu->dev, buf_size, &priv->dma, + GFP_KERNEL, priv->attrs); + if (!priv->cpu) + return -ENOMEM; + priv->size = buf_size; + + return 0; +} - /* - * The buffers on this queue are meant as intermediate - * buffers for the decoder, so no mapping is needed. - */ - priv->attrs = DMA_ATTR_NO_KERNEL_MAPPING; - priv->cpu = dma_alloc_attrs(vpu->dev, buf_size, &priv->dma, - GFP_KERNEL, priv->attrs); - if (!priv->cpu) - return -ENOMEM; - priv->size = buf_size; +int hantro_postproc_init(struct hantro_ctx *ctx) +{ + struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; + struct vb2_queue *cap_queue = &m2m_ctx->cap_q_ctx.q; + unsigned int num_buffers = vb2_get_num_buffers(cap_queue); + unsigned int i; + int ret; + + for (i = 0; i < num_buffers; i++) { + ret = hantro_postproc_alloc(ctx, i); + if (ret) + return ret; } + return 0; } +dma_addr_t +hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index) +{ + struct hantro_aux_buf *priv = &ctx->postproc.dec_q[index]; + unsigned int buf_size = hantro_postproc_buffer_size(ctx); + struct hantro_dev *vpu = ctx->dev; + int ret; + + if (priv->size < buf_size && priv->cpu) { + /* buffer is too small, release it */ + dma_free_attrs(vpu->dev, priv->size, priv->cpu, + priv->dma, priv->attrs); + priv->cpu = NULL; + } + + if (!priv->cpu) { + /* buffer not already allocated, try getting a new one */ + ret = hantro_postproc_alloc(ctx, index); + if (ret) + return 0; + } + + if (!priv->cpu) + return 0; + + return priv->dma; +} + static void hantro_postproc_g1_disable(struct hantro_ctx *ctx) { struct hantro_dev *vpu = ctx->dev; diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index b3ae037a50f6..f0d8b165abcd 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -933,7 +933,7 @@ static int hantro_start_streaming(struct vb2_queue *q, unsigned int count) } if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt)) { - ret = hantro_postproc_alloc(ctx); + ret = hantro_postproc_init(ctx); if (ret) goto err_codec_exit; } From patchwork Thu Oct 19 12:52:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361343vqb; Thu, 19 Oct 2023 05:58:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEygRLeSkmPZXqE9Q+mysNaZP3EfIUXIbB6UJBBov/oU5QJdaoGxBryg2VX8tunKyCdwuio X-Received: by 2002:a17:90b:124e:b0:274:dd15:87bf with SMTP id gx14-20020a17090b124e00b00274dd1587bfmr2568371pjb.20.1697720291853; Thu, 19 Oct 2023 05:58:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720291; cv=none; d=google.com; s=arc-20160816; b=d2obknnnGm7uK0FodAfwzT2hJt2Wn2qlFcf0zuklMLMFC0TcHxbfxUcrNKqjGAYdlR PYgPkjejwNcApvTSTv29dqzdfMOYyWt896DrowEW/+Zt/EUCFydlMCoopPaWum+5SQ3H lD528ssAEmZ8y1gjh8EPlILbI6Zs+6v/nrYRSB5931q8piGBYgm8zEUw223h4MqU+zmM O5mr07tDvSHgyDqL0/zQW7xs4dmexJHy5q58hE6LcQFpefoEJ759bzUxexVyJRmRRmGt +wq6HAvGhXEs2rXD9WRQaR5jHqNNL05PlqP+6flyKyFFevFLfts7AETEreNf/xnj8ROX Uj+g== 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=hQaDgVchBvfZHzmenfrSC7XPkayVYBFGO4QaGIVF8jA=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=oepUll2QvIXfUnw+PYNrRdKqqt7tNpNZPuevS/XsLdrF7G/68szR32GX73PgS2Zv+u K5q0eu5wgVnJnIfcO5+gweDzDsGUV6Od9KP6iPtNAOU+pl1FU6bAn6BvAch7j0TUP29f tx4p4n5A0ZdcGrCrStT0wC6dAoPtmQJFJIPMI31nCRhIh9qkC+JSqjdiqN1brgB5qxHl XpBRtu2QFSQ8QdFiM61ItbFD7qDOTTkDAJTnboRk7brHrhUxzMSUsE+ygO2BD7vaB90S 2rab0q+Sv1xGnX0hG1jbE+nMIxVIoC0GMQiXVlK4NAsTHTIH+OUGDym/jUKJ3WkKj0CI hDTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=EvrffUoI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ls9-20020a17090b350900b0027740192bc9si2279028pjb.152.2023.10.19.05.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=EvrffUoI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 39A8A8071582; Thu, 19 Oct 2023 05:57:59 -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 S1346253AbjJSM4X (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346082AbjJSMyB (ORCPT ); Thu, 19 Oct 2023 08:54:01 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EA1F10D9; Thu, 19 Oct 2023 05:52:57 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 8CC4A6607391; Thu, 19 Oct 2023 13:52:55 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719975; bh=deJM8nlQ4g4jiYxn4KEycstS3ftyfWcamvuNgnfVl08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EvrffUoI01RYdJHzNLCguXEBGGj4pP9Fs4geT4/zcN8soO2bSsRNBkBLMXQV3O+CC RKouck8D1ABQnz5NzZIpgEXB6Xyb/ungbtPKKX32k/WckSKJCx+bsgXq7fLnnI+WfA 31okyDUoFQxkktDZe79AjpcRED/Jl5qkeNgF1H2sqCYlC86F4TGvX8vMISmES2+Fxa hV5jQC3y95PHPDc0ijgPIDTRGEL8NUMsOAYgOWYh8wPUBat6Zia2+TtJjEje3rGTPf Gnx9ItM/M1Wk2CicDuRPRcVGkVPlZ2HkZoeHhieqEg6mHX82nTzg94QsVmE8q37tdb 6y7voaflsj6wg== 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 v13 48/56] media: verisilicon: Store chroma and motion vectors offset Date: Thu, 19 Oct 2023 14:52:14 +0200 Message-Id: <20231019125222.21370-49-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188752613126442 X-GMAIL-MSGID: 1780188752613126442 Store computed values of chroma and motion vectors offset because they depends on width and height values which change if the resolution change. Signed-off-by: Benjamin Gaignard CC: Ezequiel Garcia CC: Philipp Zabel --- drivers/media/platform/verisilicon/hantro.h | 2 ++ drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h index 0948b04a9f8d..6f5eb975d0e3 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -328,6 +328,8 @@ struct hantro_vp9_decoded_buffer_info { /* Info needed when the decoded frame serves as a reference frame. */ unsigned short width; unsigned short height; + size_t chroma_offset; + size_t mv_offset; u32 bit_depth : 4; }; diff --git a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c index 6fc4b555517f..6db1c32fce4d 100644 --- a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c +++ b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c @@ -158,9 +158,11 @@ static void config_output(struct hantro_ctx *ctx, chroma_addr = luma_addr + chroma_offset(ctx, dec_params); hantro_write_addr(ctx->dev, G2_OUT_CHROMA_ADDR, chroma_addr); + dst->vp9.chroma_offset = chroma_offset(ctx, dec_params); mv_addr = luma_addr + mv_offset(ctx, dec_params); hantro_write_addr(ctx->dev, G2_OUT_MV_ADDR, mv_addr); + dst->vp9.mv_offset = mv_offset(ctx, dec_params); } struct hantro_vp9_ref_reg { @@ -195,7 +197,7 @@ static void config_ref(struct hantro_ctx *ctx, luma_addr = hantro_get_dec_buf_addr(ctx, &buf->base.vb.vb2_buf); hantro_write_addr(ctx->dev, ref_reg->y_base, luma_addr); - chroma_addr = luma_addr + chroma_offset(ctx, dec_params); + chroma_addr = luma_addr + buf->vp9.chroma_offset; hantro_write_addr(ctx->dev, ref_reg->c_base, chroma_addr); } @@ -238,7 +240,7 @@ static void config_ref_registers(struct hantro_ctx *ctx, config_ref(ctx, dst, &ref_regs[2], dec_params, dec_params->alt_frame_ts); mv_addr = hantro_get_dec_buf_addr(ctx, &mv_ref->base.vb.vb2_buf) + - mv_offset(ctx, dec_params); + mv_ref->vp9.mv_offset; hantro_write_addr(ctx->dev, G2_REF_MV_ADDR(0), mv_addr); hantro_reg_write(ctx->dev, &vp9_last_sign_bias, From patchwork Thu Oct 19 12:52:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361065vqb; Thu, 19 Oct 2023 05:57:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFRUvcKZZ2vRBbuwpuwARbKYk2iOEOehTvIaDqvfX6WeumTXEmke2AXOLXUM2VHahCCCu9 X-Received: by 2002:a92:c684:0:b0:34f:c9b4:5f9c with SMTP id o4-20020a92c684000000b0034fc9b45f9cmr2166904ilg.31.1697720259365; Thu, 19 Oct 2023 05:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720259; cv=none; d=google.com; s=arc-20160816; b=kxOP71R/Ngd1xKRIuGMr1xnFbGFpZmYCY9Ni7rqr9ywfMNuyf10RqHns+yZ8lv/Ly6 9WzItCHOZ0bXQzGHTPAu/QhOcasCslX+/cGsms3HIQWJaAex560TQ+wPwLXAIO09Qb7/ A3nx7/7TgySfgkr0yDSRVfQk7paKIJziieBKbsGlDjv0bUnvnfHip9HIOiAK2NVq9XsK 2lDXr+oxIdaXmXFBnPM1dyJ3m80VSwqpt/G1Oby8uh8EPY6uqFxbHtvJPuKblmgKhr/y ekDj8eXK7BpmufgPQVsKekh6ouStzj3gKTeYzbclZBb9wdz2n70j18m6uiXTRMAOsFAY SxQA== 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=y6XiV9IcupkbgxABj43VzUXcORfiij1euWrpAY1T0M0=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=rVehboO/PUvbjIY24cBAAa9WcbVmpwOz5kY868xXUJ6m3t8E1GDCI6Xb0ASkmvsrb4 oAVo2sxCxV62kZS9+r4uVnYt4B2vXjEsKWONAg3MpJEuJhGMrBvHFwFocuAB8DQEl3tY xmylBOsqLzAX2FaKSzeaXikADvR8SNMXB2sm743I+nA8ht0A26bGUSL6lJ1gcHo/9oEi q1xceAnkblQuKUczAnhlxZCT7tEGM17d2q6gYGIvSIQ+z2uiY2fAJTJ8VBawMm8yjkc4 hnnUoAvqthdX58LM2vOUTY/WJ0Rnmq5lzqhLDhBB/+pR5R28+sxHDR9hvxztAFXyQHeU rGHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=eea5vYxk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id j187-20020a638bc4000000b00565f182839asi3857702pge.28.2023.10.19.05.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=eea5vYxk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 32BF9802092B; Thu, 19 Oct 2023 05:57:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346149AbjJSM4T (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346080AbjJSMyB (ORCPT ); Thu, 19 Oct 2023 08:54:01 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E16AD10E6; Thu, 19 Oct 2023 05:52:57 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 124BB6607394; Thu, 19 Oct 2023 13:52:56 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719976; bh=rwdI4N/UpNcGmk6GGlucekYnkxJHQ/tXy5HmEK+3+oI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eea5vYxkxQmNtRJcSGNJLoyZQY5Y/WewHzyHe9IBNA5T39ZY7Ai38nN8jMHuwNjBK 54h5r59Wtv93O+fBSdPynvfhDE5x+WyXTpTngd0scTzza6C6OW6JdEr9HGH8OQQePK z3teBshSO+iX+/+eWnGkBnl69KDDIlvBEHWP3cY/zey48WTF/vbJw0R0zACKW6chhk oRoet2B1DOgY3Y0hV934P6evu7lHbFjJ2U95m7ART2kzLfdSmwYfsMQ2Q52Sls2kJ5 ZGzUXeBdwkILvO4BQnUjZMc4u3mHtYzAzH26XenovKgBdwxioN3zg8TSt2M4M7+vUU M2Ocs8HqhyS9w== 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 v13 49/56] media: verisilicon: g2: Use common helpers to compute chroma and mv offsets Date: Thu, 19 Oct 2023 14:52:15 +0200 Message-Id: <20231019125222.21370-50-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188718699849369 X-GMAIL-MSGID: 1780188718699849369 HEVC and VP9 are running on the same hardware and share the same chroma and motion vectors offset constraint. Create common helpers functions for these computation. Source and destination buffer height may not be the same because alignment constraint are different so use destination height to compute chroma offset because we target this buffer as hardware output. To be able to use the helpers in both VP9 HEVC code remove dec_params and use context->bit_depth instead. Signed-off-by: Benjamin Gaignard CC: Ezequiel Garcia CC: Philipp Zabel --- .../media/platform/verisilicon/hantro_g2.c | 14 ++++++++++ .../platform/verisilicon/hantro_g2_hevc_dec.c | 18 ++----------- .../platform/verisilicon/hantro_g2_vp9_dec.c | 26 +++---------------- .../media/platform/verisilicon/hantro_hw.h | 3 +++ 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_g2.c b/drivers/media/platform/verisilicon/hantro_g2.c index ee5f14c5f8f2..b880a6849d58 100644 --- a/drivers/media/platform/verisilicon/hantro_g2.c +++ b/drivers/media/platform/verisilicon/hantro_g2.c @@ -8,6 +8,8 @@ #include "hantro_hw.h" #include "hantro_g2_regs.h" +#define G2_ALIGN 16 + void hantro_g2_check_idle(struct hantro_dev *vpu) { int i; @@ -42,3 +44,15 @@ irqreturn_t hantro_g2_irq(int irq, void *dev_id) return IRQ_HANDLED; } + +size_t hantro_g2_chroma_offset(struct hantro_ctx *ctx) +{ + return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8; +} + +size_t hantro_g2_motion_vectors_offset(struct hantro_ctx *ctx) +{ + size_t cr_offset = hantro_g2_chroma_offset(ctx); + + return ALIGN((cr_offset * 3) / 2, G2_ALIGN); +} diff --git a/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c b/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c index a9d4ac84a8d8..d3f8c33eb16c 100644 --- a/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c +++ b/drivers/media/platform/verisilicon/hantro_g2_hevc_dec.c @@ -8,20 +8,6 @@ #include "hantro_hw.h" #include "hantro_g2_regs.h" -#define G2_ALIGN 16 - -static size_t hantro_hevc_chroma_offset(struct hantro_ctx *ctx) -{ - return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8; -} - -static size_t hantro_hevc_motion_vectors_offset(struct hantro_ctx *ctx) -{ - size_t cr_offset = hantro_hevc_chroma_offset(ctx); - - return ALIGN((cr_offset * 3) / 2, G2_ALIGN); -} - static void prepare_tile_info_buffer(struct hantro_ctx *ctx) { struct hantro_dev *vpu = ctx->dev; @@ -384,8 +370,8 @@ static int set_ref(struct hantro_ctx *ctx) struct hantro_dev *vpu = ctx->dev; struct vb2_v4l2_buffer *vb2_dst; struct hantro_decoded_buffer *dst; - size_t cr_offset = hantro_hevc_chroma_offset(ctx); - size_t mv_offset = hantro_hevc_motion_vectors_offset(ctx); + size_t cr_offset = hantro_g2_chroma_offset(ctx); + size_t mv_offset = hantro_g2_motion_vectors_offset(ctx); u32 max_ref_frames; u16 dpb_longterm_e; static const struct hantro_reg cur_poc[] = { diff --git a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c index 6db1c32fce4d..342e543dee4c 100644 --- a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c +++ b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c @@ -16,8 +16,6 @@ #include "hantro_vp9.h" #include "hantro_g2_regs.h" -#define G2_ALIGN 16 - enum hantro_ref_frames { INTRA_FRAME = 0, LAST_FRAME = 1, @@ -90,22 +88,6 @@ static int start_prepare_run(struct hantro_ctx *ctx, const struct v4l2_ctrl_vp9_ return 0; } -static size_t chroma_offset(const struct hantro_ctx *ctx, - const struct v4l2_ctrl_vp9_frame *dec_params) -{ - int bytes_per_pixel = dec_params->bit_depth == 8 ? 1 : 2; - - return ctx->src_fmt.width * ctx->src_fmt.height * bytes_per_pixel; -} - -static size_t mv_offset(const struct hantro_ctx *ctx, - const struct v4l2_ctrl_vp9_frame *dec_params) -{ - size_t cr_offset = chroma_offset(ctx, dec_params); - - return ALIGN((cr_offset * 3) / 2, G2_ALIGN); -} - static struct hantro_decoded_buffer * get_ref_buf(struct hantro_ctx *ctx, struct vb2_v4l2_buffer *dst, u64 timestamp) { @@ -156,13 +138,13 @@ static void config_output(struct hantro_ctx *ctx, luma_addr = hantro_get_dec_buf_addr(ctx, &dst->base.vb.vb2_buf); hantro_write_addr(ctx->dev, G2_OUT_LUMA_ADDR, luma_addr); - chroma_addr = luma_addr + chroma_offset(ctx, dec_params); + chroma_addr = luma_addr + hantro_g2_chroma_offset(ctx); hantro_write_addr(ctx->dev, G2_OUT_CHROMA_ADDR, chroma_addr); - dst->vp9.chroma_offset = chroma_offset(ctx, dec_params); + dst->vp9.chroma_offset = hantro_g2_chroma_offset(ctx); - mv_addr = luma_addr + mv_offset(ctx, dec_params); + mv_addr = luma_addr + hantro_g2_motion_vectors_offset(ctx); hantro_write_addr(ctx->dev, G2_OUT_MV_ADDR, mv_addr); - dst->vp9.mv_offset = mv_offset(ctx, dec_params); + dst->vp9.mv_offset = hantro_g2_motion_vectors_offset(ctx); } struct hantro_vp9_ref_reg { diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h index 292a76ef643e..9aec8a79acdc 100644 --- a/drivers/media/platform/verisilicon/hantro_hw.h +++ b/drivers/media/platform/verisilicon/hantro_hw.h @@ -521,6 +521,9 @@ hantro_av1_mv_size(unsigned int width, unsigned int height) return ALIGN(num_sbs * 384, 16) * 2 + 512; } +size_t hantro_g2_chroma_offset(struct hantro_ctx *ctx); +size_t hantro_g2_motion_vectors_offset(struct hantro_ctx *ctx); + int hantro_g1_mpeg2_dec_run(struct hantro_ctx *ctx); int rockchip_vpu2_mpeg2_dec_run(struct hantro_ctx *ctx); void hantro_mpeg2_dec_copy_qtable(u8 *qtable, From patchwork Thu Oct 19 12:52:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361005vqb; Thu, 19 Oct 2023 05:57:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFlsx/FjhYwB2Gi7kiivDLAG+9O0e9EauiLh+SWdRoPyNLT71HpjsvrW7vPUftq4iE6/T8 X-Received: by 2002:a05:6a21:184:b0:13a:6bca:7a84 with SMTP id le4-20020a056a21018400b0013a6bca7a84mr2186927pzb.44.1697720248580; Thu, 19 Oct 2023 05:57:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720248; cv=none; d=google.com; s=arc-20160816; b=Qc4XsQ/2vX635Wmqsitk0/enRRIai8LCtj5EqZfqG7OvyPv4nXnERTpTLcHfbP11dn QpStYcYoUKKC6FftlkLpo/+OzEggkZueEsbFJ2P/GlEl2zPypPT8xAbBInPPvz2vW8+L xmDfGVWoEKibsYIvUGUnvCsDAe1lyB39vMDXmHSIKPj292oCV85qlvLQz7A7ZEv1VGQz 1SwjM3EODmFwT1zeWcraMaVz0bsL3izLbHPEt6YPYX4kmEsywLtDSQEZ+VOzz38H7ATm 16kSsfxHICG5LN4WlvR4fJnY3muV+VLJ2vMSSM+WvsRWnRF6Y6x2+IPNxlLAA0b7tx3c fkJA== 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=nr1KYax36VZZBnabbjIyUGPTkvQFXV8YfPxk2A654tA=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=Si6FdzJz8nz19hOa8tV/9r2cYTHsoe5HaHxA8hsiZjMF0ZXW8k0UrA1uyXheRJgmtg +4WlrW865HeMSD7S7FlhnzWvq+Xi+4w1oJzMusxZ0lFkJB1reXb9SrkADj3tsXfQOtCs pX/KZ9G0zRgnzgGK/72Y7ookAzoWIctVU42QFrBsqRg873UXAT9IfY5wNKb2zspY21Lm 4Fxqv7RswjSfzt6co4T8dtrePCbnoDGM55+cjKscKM6CfgOC2c7rehyZsFlU2hqC/Ig7 l0iJtpVOOBDsCFLRCw3XEfpeRTkLSI1+sc9Omz/wFTYT2hIywf5z5PhVKD7C9aIkW6kv ELSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LwMxv261; 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 c27-20020a631c1b000000b0058555ea0a21si4415188pgc.571.2023.10.19.05.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:28 -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=LwMxv261; 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 BDCD5822B2F3; Thu, 19 Oct 2023 05:57:13 -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 S1346058AbjJSM4P (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346081AbjJSMyB (ORCPT ); Thu, 19 Oct 2023 08:54:01 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1611810E9; Thu, 19 Oct 2023 05:52:58 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 9264E6607395; Thu, 19 Oct 2023 13:52:56 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719976; bh=dg5TyqcXTbK8D5lR679m2t1zA3rG8sR+3z3V0ZimwSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LwMxv261skuXKGrk46mty6jtYAGdVkkK9qNt6P7OqH45eUQKmmO2uk5Wjc73Pgui0 KtMOBHfcif1Wf6IKijuaYLVrhnvRLAnbljr3pUJtg9seYdGMFzFOMEME+pyeMPAZPB fyRIrWH8qV1bfM/GjDsSAJn+RDhqQms7eAjW8jMki1vPoZ4kVqPAQchFiROYLvqClF aNsO+4qZOPgVUzK/VIW5DUzq/ehn4LFCgdJSLXPJshuD+xD+qvxF5gK1Sr9ov7pKUH t4/CUVniy1r2fz7tb76mIXV1fLO86kEl5X+OrzV+eznw51/JNAZy+axPxZ6+y8d7Fd ZS7AzeDiX1ujg== 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 v13 50/56] media: verisilicon: vp9: Allow to change resolution while streaming Date: Thu, 19 Oct 2023 14:52:16 +0200 Message-Id: <20231019125222.21370-51-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 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]); Thu, 19 Oct 2023 05:57:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188707175478597 X-GMAIL-MSGID: 1780188707175478597 Remove all checks that prohibit to set a new format while streaming. This allow to change dynamically the resolution if the pixel format remains the same. Signed-off-by: Benjamin Gaignard CC: Ezequiel Garcia CC: Philipp Zabel --- .../media/platform/verisilicon/hantro_v4l2.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index f0d8b165abcd..27a1e77cca38 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -514,25 +514,14 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, return ret; if (!ctx->is_encoder) { - struct vb2_queue *peer_vq; - /* * In order to support dynamic resolution change, * the decoder admits a resolution change, as long - * as the pixelformat remains. Can't be done if streaming. - */ - if (vb2_is_streaming(vq) || (vb2_is_busy(vq) && - pix_mp->pixelformat != ctx->src_fmt.pixelformat)) - return -EBUSY; - /* - * Since format change on the OUTPUT queue will reset - * the CAPTURE queue, we can't allow doing so - * when the CAPTURE queue has buffers allocated. + * as the pixelformat remains. */ - peer_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, - V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); - if (vb2_is_busy(peer_vq)) + if (vb2_is_streaming(vq) && pix_mp->pixelformat != ctx->src_fmt.pixelformat) { return -EBUSY; + } } else { /* * The encoder doesn't admit a format change if @@ -577,15 +566,8 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, static int hantro_set_fmt_cap(struct hantro_ctx *ctx, struct v4l2_pix_format_mplane *pix_mp) { - struct vb2_queue *vq; int ret; - /* Change not allowed if queue is busy. */ - vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, - V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); - if (vb2_is_busy(vq)) - return -EBUSY; - if (ctx->is_encoder) { struct vb2_queue *peer_vq; From patchwork Thu Oct 19 12:52:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360907vqb; Thu, 19 Oct 2023 05:57:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBJHSaJaK16x93e7mGNKG0QaSMvTaQ5M3ioQu+qut7J1DJMRRcTnPAUobDpQN0Ko+ONZZx X-Received: by 2002:a05:6a20:e126:b0:149:f82a:2640 with SMTP id kr38-20020a056a20e12600b00149f82a2640mr2444214pzb.30.1697720238500; Thu, 19 Oct 2023 05:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720238; cv=none; d=google.com; s=arc-20160816; b=iYWw5XI8Layf1qP1M6SaAzLyLLycOW2o0/6urg2bjtOoY1s+WAIX/cO9LbdOVK+DHo VXQBZtrb4lvwk+lAaQqhHQjnt/dEj4xBtRO1EoZJULFFNAHfMxn/Rrk9C/JfxYEFLbHO oxGPkHOKAdB5BnHLSCJomXWD+xZG4DThqVM4fye6YRtWcEEy6dxzr7zc0WlhAiELVoW2 cuO28MKDp4e61j4nYq4fp9oGxoSZRTbjaoOxdolqs9mYpbvFK78+DwJ6dKYsUj6fUgki 46oH4fir3RJE7tl9/oSwEjmsoJSw8dSdtoxjIkgWuIWNPwfMPd9o8fiD2CutlijWIfS8 wGVg== 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=uXd4l4Pl6p2u86yQdaRkv4bDOJFZxKbIe4Sw9HIEWm4=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=FrudXfJ5ns/3mLzs24dQqNiotbCg1SMMr+e2RnMxQo+tqNVxlIkrTlmEFHUZHAwwyj /JQm7xNCmEfx6qDq7EXWvQzSuwKAvU8therjeH5pxq4ftsyCiQ9eLste7Bi3mBLX+0jA neTI6zMbtXjUWRaV68MXEK4KAY76hWnF7PbXtq0V4Y0IsasB/9CQuZ8M3xVKS4aAJKyQ wAP+QojycCyPTrhregccnI8CmV3U7vma5JkX44Lchtqrar7xB9yGrDN3xFxYZ+vVHvmC KYx0RrMqkANq3L0Y+ugp+crEed+d3YUuJm9YfNOQ7NWZx1R16MUt3iD7KytQOhbBc9yt 3WuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="nmZ/okqU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h4-20020a17090aa88400b002774985e8b7si2153282pjq.168.2023.10.19.05.57.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="nmZ/okqU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 86B33822D028; Thu, 19 Oct 2023 05:57:13 -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 S1346259AbjJSM41 (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346083AbjJSMyB (ORCPT ); Thu, 19 Oct 2023 08:54:01 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2233F10EB; Thu, 19 Oct 2023 05:52:58 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 0E1096607397; Thu, 19 Oct 2023 13:52:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719977; bh=MnEpAX6paYYqEEhaTQi4aP3SQzg49BXA5RiIYY/VWXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nmZ/okqU0DGfibsynmYKnGC/WK4Qm85BL6KXRB6RpN6BTnGVJSRTyCAcURs3k87uK f5YKa551uxSxuzNWoD/gc9RiLpzHcHhBsuS74pURwluo6TsF232xgfCt9SobIWRmLR LVJChj1PG1VIAsBptJMVyY3YT5OD9f3HAj0zhJAcrXK/NtgZTxserl7M8uHo9neZ8q lcFPF0xl0kjUsUFOF7gQWbk8rP/pkfJLI6WfPTtZsH2mL4K7SGyjAQYV8yQQmugCni fYH30INWKz9+YUzOXWlLGgy9UloQaL3ZTSyVVzMP9qgqPhr52fQV26z6ewt4Sb0qnm UG7G8nogMTyQw== 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 v13 51/56] media: core: Rework how create_buf index returned value is computed Date: Thu, 19 Oct 2023 14:52:17 +0200 Message-Id: <20231019125222.21370-52-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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, 19 Oct 2023 05:57:13 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188696872382937 X-GMAIL-MSGID: 1780188696872382937 When DELETE_BUFS will be introduced holes could created in bufs array. To be able to reuse these unused indices reworking how create->index is set is mandatory. Let __vb2_queue_alloc() decide which first index is correct and forward this to the caller. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 22 ++++++++++++------- .../media/common/videobuf2/videobuf2-v4l2.c | 20 +++++++++++------ include/media/videobuf2-core.h | 5 ++++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 72ef7179d80a..2c8cf479a962 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -442,16 +442,21 @@ static void vb2_queue_remove_buffer(struct vb2_buffer *vb) */ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, unsigned int num_buffers, unsigned int num_planes, - const unsigned plane_sizes[VB2_MAX_PLANES]) + const unsigned plane_sizes[VB2_MAX_PLANES], + unsigned int *first_index) { - unsigned int q_num_buffers = vb2_get_num_buffers(q); unsigned int buffer, plane; struct vb2_buffer *vb; + unsigned long index; int ret; /* Ensure that the number of already queue + num_buffers is below q->max_num_buffers */ num_buffers = min_t(unsigned int, num_buffers, - q->max_num_buffers - q_num_buffers); + q->max_num_buffers - vb2_get_num_buffers(q)); + + index = vb2_get_num_buffers(q); + + *first_index = index; for (buffer = 0; buffer < num_buffers; ++buffer) { /* Allocate vb2 buffer structures */ @@ -471,7 +476,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, vb->planes[plane].min_length = plane_sizes[plane]; } - vb2_queue_add_buffer(q, vb, q_num_buffers + buffer); + vb2_queue_add_buffer(q, vb, index++); call_void_bufop(q, init_buffer, vb); /* Allocate video buffer memory for the MMAP type */ @@ -812,7 +817,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int q_num_bufs = vb2_get_num_buffers(q); unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; - unsigned int i; + unsigned int i, first_index; int ret = 0; if (q->streaming) { @@ -898,7 +903,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* Finally, allocate buffers and video memory */ allocated_buffers = - __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes); + __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes, &first_index); if (allocated_buffers == 0) { dprintk(q, 1, "memory allocation failed\n"); ret = -ENOMEM; @@ -972,7 +977,8 @@ EXPORT_SYMBOL_GPL(vb2_core_reqbufs); int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count, unsigned int requested_planes, - const unsigned int requested_sizes[]) + const unsigned int requested_sizes[], + unsigned int *first_index) { unsigned int num_planes = 0, num_buffers, allocated_buffers; unsigned plane_sizes[VB2_MAX_PLANES] = { }; @@ -1034,7 +1040,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, /* Finally, allocate buffers and video memory */ allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers, - num_planes, plane_sizes); + num_planes, plane_sizes, first_index); if (allocated_buffers == 0) { dprintk(q, 1, "memory allocation failed\n"); ret = -ENOMEM; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index bdfc3a253c65..56daf3b5b2ba 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -805,11 +805,16 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) for (i = 0; i < requested_planes; i++) if (requested_sizes[i] == 0) return -EINVAL; - return ret ? ret : vb2_core_create_bufs(q, create->memory, - create->flags, - &create->count, - requested_planes, - requested_sizes); + if (ret) + return ret; + + ret = vb2_core_create_bufs(q, create->memory, + create->flags, + &create->count, + requested_planes, + requested_sizes, + &create->index); + return ret; } EXPORT_SYMBOL_GPL(vb2_create_bufs); @@ -1037,15 +1042,16 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv, int res = vb2_verify_memory_type(vdev->queue, p->memory, p->format.type); - p->index = vdev->queue->num_buffers; fill_buf_caps(vdev->queue, &p->capabilities); validate_memory_flags(vdev->queue, p->memory, &p->flags); /* * If count == 0, then just check if memory and type are valid. * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0. */ - if (p->count == 0) + if (p->count == 0) { + p->index = vb2_get_num_buffers(vdev->queue); return res != -EBUSY ? res : 0; + } if (res) return res; if (vb2_queue_is_busy(vdev->queue, file)) diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index e77a397195f2..6986ff4b77cd 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -803,6 +803,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * @count: requested buffer count. * @requested_planes: number of planes requested. * @requested_sizes: array with the size of the planes. + * @first_index: index of the first created buffer, all allocated buffers have + * indices in the range [first..first+count] * * Videobuf2 core helper to implement VIDIOC_CREATE_BUFS() operation. It is * called internally by VB2 by an API-specific handler, like @@ -819,7 +821,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count, unsigned int requested_planes, - const unsigned int requested_sizes[]); + const unsigned int requested_sizes[], + unsigned int *first_index); /** * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace From patchwork Thu Oct 19 12:52:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361854vqb; Thu, 19 Oct 2023 05:59:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE3Qy1TWUaevY+Akl1mGSCtUUTv1tGpz6sqPf2d8olN2kFLL9fehRAoxPqB9R67FweZHAfE X-Received: by 2002:a17:902:e841:b0:1b9:e913:b585 with SMTP id t1-20020a170902e84100b001b9e913b585mr2459468plg.13.1697720356715; Thu, 19 Oct 2023 05:59:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720356; cv=none; d=google.com; s=arc-20160816; b=AtSWaq1E3W5j9j8tWGhR7+PS82Rit0Inn4bXRn4j1lrfb8r1oXWEVsacAcIdsrw+NT hK4XwN5OhuWB76yokaZ6/Ukx0REGIHmktTfsUns4oxBu3PaRvGhKRWYdx3mdldRmpGRr mslYljOvi/bchv+3t59W4LL49EzLAAI9SjoPWsjbKKcg1+EHHM4k71fZyO9SzcTJ6JnZ 1JRfIhGVwy97LcNxSs/9C2InZ5BHtyKJ7YopJdutQ3yC2l0T5oXCbZjQ74F6mOUZ967z nkVHrsmtiNfKgdiZYDW+rOExCsgiGm3nsvKpPsqhd10bDRxmhtbbSmKCM/YFeYc36Nwo Vhsw== 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=eCePPCjQglISWJ8e2J07nT0sMEaACefdvzp9l+FQ9+E=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=i7coJkNtfq3PyqF2LZbiEEiflGsRYGB5JIkf7XWJZFCrPENRxjD3UbGk8ZGDAmZQhW GlUdYFRiW1bGFGvXs8JQEG1yp2IP0VVGU6vpeS276JCCtp1kgeUVKdAjZdWTqc/qnIQg yYu5u0qARFUPfrv3K57qCTK2DJAyTypt6+3i2rLapW/eVKZ72lszMHOwHa6I0STQpee9 6f1mm9gAtfIVYRyGiN8zkRb3H4kC9rEMhKDUtsYg7nZFmgPaxhrk1vriVNGxn3RKlrDs AtGlQPTdC8vMMt0n+aiGLDZA3Cg/9m/Cn3IX1Wy0AyXAl7nefQPIK1/9TGMZ7yFonty7 LyqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JwjJEHaF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id m3-20020a170902c44300b001b8039317cesi1924333plm.301.2023.10.19.05.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:59:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JwjJEHaF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id B0422806820E; Thu, 19 Oct 2023 05:59:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346268AbjJSM4h (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346097AbjJSMyC (ORCPT ); Thu, 19 Oct 2023 08:54:02 -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 EF1AE10FB; Thu, 19 Oct 2023 05:53:00 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 83682660734C; Thu, 19 Oct 2023 13:52:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719977; bh=oj1c3lOtNZD9WKVM3HjUaAmnUw1gzcNQvZo6oWpLItQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwjJEHaFNfJc/duuRMWLXRRpnE2GkJfXSQ9eil+u4RAXzEIxKvoWmRQdG8PlMitNQ iSpxTIFR0S6Ukte5GbL5I+DBGqarWLwyOSX6458syafJelfrACidSoTQkGgdQXdFvv PYgSGkxTS1fmc4MHss7XOTTPDwrUVIJWhPPw7EP3C/5RDQJXto+7bnawE3ELheMeF+ jaUVB8pOyHaKQwyOeD3h6kp3xGjkVYB0SPGzOL0WhDJuNWw7DLa/aEuQJMQT7FDklW 8POLfoKI4RDQmqokIfcqT+ZpdCrs4llEeExL5wH5NSKQteMnocICerEP/CKXkz9KhB AwepGPJlAOmoQ== 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 v13 52/56] media: core: Add bitmap manage bufs array entries Date: Thu, 19 Oct 2023 14:52:18 +0200 Message-Id: <20231019125222.21370-53-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:59:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188820755369774 X-GMAIL-MSGID: 1780188820755369774 Add a bitmap field to know which of bufs array entries are used or not. Remove no more used num_buffers field from queue structure. Use bitmap_find_next_zero_area() to find the first possible range when creating new buffers to fill the gaps. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 42 +++++++++++++++---- include/media/videobuf2-core.h | 15 ++++--- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 2c8cf479a962..6e88406fcae9 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -416,11 +416,12 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) */ static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index) { - WARN_ON(index >= q->max_num_buffers || q->bufs[index]); + WARN_ON(index >= q->max_num_buffers || test_bit(index, q->bufs_bitmap)); q->bufs[index] = vb; vb->index = index; vb->vb2_queue = q; + set_bit(index, q->bufs_bitmap); } /** @@ -429,6 +430,7 @@ static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, uns */ static void vb2_queue_remove_buffer(struct vb2_buffer *vb) { + clear_bit(vb->index, vb->vb2_queue->bufs_bitmap); vb->vb2_queue->bufs[vb->index] = NULL; vb->vb2_queue = NULL; } @@ -450,11 +452,12 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, unsigned long index; int ret; - /* Ensure that the number of already queue + num_buffers is below q->max_num_buffers */ + /* Ensure that vb2_get_num_buffers(q) + num_buffers is no more than q->max_num_buffers */ num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers - vb2_get_num_buffers(q)); - index = vb2_get_num_buffers(q); + index = bitmap_find_next_zero_area(q->bufs_bitmap, q->max_num_buffers, + 0, num_buffers, 0); *first_index = index; @@ -656,7 +659,6 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) kfree(vb); } - q->num_buffers -= buffers; if (!vb2_get_num_buffers(q)) { q->memory = VB2_MEMORY_UNKNOWN; INIT_LIST_HEAD(&q->queued_list); @@ -874,6 +876,14 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); if (!q->bufs) ret = -ENOMEM; + + if (!q->bufs_bitmap) + q->bufs_bitmap = bitmap_zalloc(q->max_num_buffers, GFP_KERNEL); + if (!q->bufs_bitmap) { + ret = -ENOMEM; + kfree(q->bufs); + q->bufs = NULL; + } q->memory = memory; mutex_unlock(&q->mmap_lock); if (ret) @@ -943,7 +953,6 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, } mutex_lock(&q->mmap_lock); - q->num_buffers = allocated_buffers; if (ret < 0) { /* @@ -970,6 +979,10 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, mutex_lock(&q->mmap_lock); q->memory = VB2_MEMORY_UNKNOWN; mutex_unlock(&q->mmap_lock); + kfree(q->bufs); + q->bufs = NULL; + bitmap_free(q->bufs_bitmap); + q->bufs_bitmap = NULL; return ret; } EXPORT_SYMBOL_GPL(vb2_core_reqbufs); @@ -1006,9 +1019,19 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, q->memory = memory; if (!q->bufs) q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); - if (!q->bufs) + if (!q->bufs) { ret = -ENOMEM; + goto unlock; + } + if (!q->bufs_bitmap) + q->bufs_bitmap = bitmap_zalloc(q->max_num_buffers, GFP_KERNEL); + if (!q->bufs_bitmap) { + ret = -ENOMEM; + kfree(q->bufs); + q->bufs = NULL; + } mutex_unlock(&q->mmap_lock); +unlock: if (ret) return ret; q->waiting_for_buffers = !q->is_output; @@ -1070,7 +1093,6 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, } mutex_lock(&q->mmap_lock); - q->num_buffers += allocated_buffers; if (ret < 0) { /* @@ -2549,7 +2571,9 @@ void vb2_core_queue_release(struct vb2_queue *q) __vb2_queue_free(q, q->max_num_buffers); kfree(q->bufs); q->bufs = NULL; - q->num_buffers = 0; + bitmap_free(q->bufs_bitmap); + q->bufs_bitmap = NULL; + mutex_unlock(&q->mmap_lock); } EXPORT_SYMBOL_GPL(vb2_core_queue_release); @@ -2904,7 +2928,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ * Check if we need to dequeue the buffer. */ index = fileio->cur_index; - if (index >= q->num_buffers) { + if (!test_bit(index, q->bufs_bitmap)) { struct vb2_buffer *b; /* diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 6986ff4b77cd..288477075a0e 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -346,7 +346,7 @@ struct vb2_buffer { * describes the requested number of planes and sizes\[\] * contains the requested plane sizes. In this case * \*num_buffers are being allocated additionally to - * q->num_buffers. If either \*num_planes or the requested + * queue buffers. If either \*num_planes or the requested * sizes are invalid callback must return %-EINVAL. * @wait_prepare: release any locks taken while calling vb2 functions; * it is called before an ioctl needs to wait for a new @@ -557,7 +557,7 @@ struct vb2_buf_ops { * @memory: current memory type used * @dma_dir: DMA mapping direction. * @bufs: videobuf2 buffer structures - * @num_buffers: number of allocated/used buffers + * @bufs_bitmap: bitmap to manage bufs entries. * @max_num_buffers: upper limit of number of allocated/used buffers * @queued_list: list of buffers currently queued from userspace * @queued_count: number of buffers queued and ready for streaming. @@ -621,7 +621,7 @@ struct vb2_queue { unsigned int memory; enum dma_data_direction dma_dir; struct vb2_buffer **bufs; - unsigned int num_buffers; + unsigned long *bufs_bitmap; unsigned int max_num_buffers; struct list_head queued_list; @@ -1150,7 +1150,10 @@ static inline bool vb2_fileio_is_active(struct vb2_queue *q) */ static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q) { - return q->num_buffers; + if (!q->bufs_bitmap) + return 0; + + return bitmap_weight(q->bufs_bitmap, q->max_num_buffers); } /** @@ -1253,13 +1256,13 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q) static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, unsigned int index) { - if (!q->bufs) + if (!q->bufs_bitmap) return NULL; if (index >= q->max_num_buffers) return NULL; - if (index < q->num_buffers) + if (test_bit(index, q->bufs_bitmap)) return q->bufs[index]; return NULL; } From patchwork Thu Oct 19 12:52:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361497vqb; Thu, 19 Oct 2023 05:58:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFktXiOV3gDtXI75Gu4SGwIkZ1YjFah9M6fHYTV/5YaMF89rxyK3WPXlYATO7WxXyWpmQ04 X-Received: by 2002:a05:6830:3d03:b0:6b8:7880:de9 with SMTP id eu3-20020a0568303d0300b006b878800de9mr2087917otb.19.1697720308326; Thu, 19 Oct 2023 05:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720308; cv=none; d=google.com; s=arc-20160816; b=OQz8wEmwo3NRMnQgciZ68U58C0Q9yJGEseca1lStf0NkVHeC9/1dP+mJiaFBLHaYiO 0PTVWMnroWmFx2E8CHt6CWM6MmcY7yoATlErvKzotQZiMo7naAiz+rPxDHYSBRJsWXiv 6/SKVgc8DXgDz+/j7RduuWWmifyLHS7ene0j2uDXGao9MRAvKLwBiLppFgJUeShvAWS7 kzUZj7ze1FceXwyS4NE9aGiKtOg3hzobI1w0J5WP5IGWUAe4lUAgL7CboKMOlfQMuB5t qxSXW45pWEBLI3QA3m/tHCUF2avSSvGx/gThcCdkMJHeO6uJ4DwNSJ94Ba5xCcGZLZ0q tagA== 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=K1zS+RIwol4Ylpy0w92Fc/eB3Nha5HmfVtn5A1AXcqo=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=ETY7Dvn8VUToTTVvLCYiKDpcbXpeBZsr1G7c2GlTVkR+A9LSs92SybjLW4KCaCxU4R ZOuXSyug0qDB3B1waDJzW0vLMYrnUakGRQn69tgOhoQ8bzdlJ8SSYZK4bnFHWMDdlPGG GrxTH4pBih8IgguP80F7dPblAs1up7sjdto/82aXe5s8Ky+zCJZUlWRW05zOWs06EjsH XXTouhSYgdXVQRxWNP2IWbSPoyvksp7WhevsdXaeEabaTr0Y+mJtMgMea95r/d2ybxFW x3b4IMKniaHFZVJ/PjDk+h1SrhX9+q/cOevxNaV+HaGaTNMgiQfsKsHnudwgaeZ2CUTr 3wcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="a4EFl/ZS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x3-20020a634a03000000b005a99db7489bsi4313401pga.248.2023.10.19.05.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="a4EFl/ZS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 7B6F9808D6A8; Thu, 19 Oct 2023 05:58:20 -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 S1346274AbjJSM4j (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346096AbjJSMyC (ORCPT ); Thu, 19 Oct 2023 08:54:02 -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 15B4910FE; Thu, 19 Oct 2023 05:53:00 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 0E6496607398; Thu, 19 Oct 2023 13:52:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719978; bh=u0Q5LhMlMmzDnDRMmnfWjZ04KVEnwRGQKtzWOZE3C0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a4EFl/ZScsZ1tgRMBSEXHdwQTB+9Eq6SIiml1p7uNEgjK8eB4h4/XMW9RU0uJiAu2 OrIKd31eUFhKb+Y8oKf38XSBBuFkTlSXb/9DsfcuM3XcvCtDa6DAoX50W1FqS7JQil tQRgGOUQkikBRgmKNzRAqTKwWDMkIBkEjXeP7sj6prJVE2rEPlLFyTyN7CFXvi1A3P RLknuIVKnhtI8puYiZO8OSvL8/SY/4ffxmTwQARM3TlhEZCR7RUXUtgpU6pXL51w/5 ROdxwaQUCjp/0Bn4rCK5zfmbKVOuNIT29WlWra9WKREHG2VLO01Je5KD9OsCqhjsob 7hAzGjeSpvfPg== 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 v13 53/56] media: core: Free range of buffers Date: Thu, 19 Oct 2023 14:52:19 +0200 Message-Id: <20231019125222.21370-54-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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, 19 Oct 2023 05:58:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188770146874820 X-GMAIL-MSGID: 1780188770146874820 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 | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 6e88406fcae9..010a8bca0240 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -519,15 +519,13 @@ 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; + unsigned int i; struct vb2_buffer *vb; - unsigned int q_num_buffers = vb2_get_num_buffers(q); - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; - ++buffer) { - vb = vb2_get_buffer(q, buffer); + for (i = start; i < q->max_num_buffers && i < start + count; i++) { + vb = vb2_get_buffer(q, i); if (!vb) continue; @@ -542,35 +540,35 @@ 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; - unsigned int q_num_buffers = vb2_get_num_buffers(q); + unsigned int i; lockdep_assert_held(&q->mmap_lock); /* Call driver-provided cleanup function for each buffer, if provided */ - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; - ++buffer) { - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + for (i = start; i < q->max_num_buffers && i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); - if (vb && vb->planes[0].mem_priv) + if (!vb) + continue; + if (vb->planes[0].mem_priv) call_void_vb_qop(vb, buf_cleanup, vb); } /* Release video buffer memory */ - __vb2_free_mem(q, buffers); + __vb2_free_mem(q, start, count); #ifdef CONFIG_VIDEO_ADV_DEBUG /* * Check that all the calls were balanced during the life-time of this * queue. If not then dump the counters to the kernel log. */ - if (q_num_buffers) { + if (vb2_get_num_buffers(q)) { bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || q->cnt_prepare_streaming != q->cnt_unprepare_streaming || q->cnt_wait_prepare != q->cnt_wait_finish; @@ -596,8 +594,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) q->cnt_stop_streaming = 0; q->cnt_unprepare_streaming = 0; } - for (buffer = 0; buffer < vb2_get_num_buffers(q); buffer++) { - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + for (i = start; i < q->max_num_buffers && i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); bool unbalanced; if (!vb) @@ -614,7 +612,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) if (unbalanced) { pr_info("unbalanced counters for queue %p, buffer %d:\n", - q, buffer); + q, i); if (vb->cnt_buf_init != vb->cnt_buf_cleanup) pr_info(" buf_init: %u buf_cleanup: %u\n", vb->cnt_buf_init, vb->cnt_buf_cleanup); @@ -648,9 +646,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) #endif /* Free vb2 buffers */ - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; - ++buffer) { - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + for (i = start; i < q->max_num_buffers && i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) continue; @@ -690,7 +687,7 @@ EXPORT_SYMBOL(vb2_buffer_in_use); static bool __buffers_in_use(struct vb2_queue *q) { unsigned int buffer; - for (buffer = 0; buffer < vb2_get_num_buffers(q); ++buffer) { + for (buffer = 0; buffer < q->max_num_buffers; ++buffer) { struct vb2_buffer *vb = vb2_get_buffer(q, buffer); if (!vb) @@ -850,7 +847,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->max_num_buffers); mutex_unlock(&q->mmap_lock); /* @@ -960,7 +957,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, first_index, allocated_buffers); mutex_unlock(&q->mmap_lock); return ret; } @@ -1000,7 +997,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, bool no_previous_buffers = !q_num_bufs; int ret = 0; - if (q->num_buffers == q->max_num_buffers) { + if (q_num_bufs == q->max_num_buffers) { dprintk(q, 1, "maximum number of buffers already allocated\n"); return -ENOBUFS; } @@ -1100,7 +1097,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, *first_index, allocated_buffers); mutex_unlock(&q->mmap_lock); return -ENOMEM; } @@ -1714,7 +1711,7 @@ static int vb2_start_streaming(struct vb2_queue *q) * Forcefully reclaim buffers if the driver did not * correctly return them to vb2. */ - for (i = 0; i < vb2_get_num_buffers(q); ++i) { + for (i = 0; i < q->max_num_buffers; ++i) { vb = vb2_get_buffer(q, i); if (!vb) @@ -2120,7 +2117,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * to vb2 in stop_streaming(). */ if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { - for (i = 0; i < vb2_get_num_buffers(q); i++) { + for (i = 0; i < q->max_num_buffers; i++) { struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) @@ -2164,7 +2161,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * call to __fill_user_buffer() after buf_finish(). That order can't * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). */ - for (i = 0; i < vb2_get_num_buffers(q); i++) { + for (i = 0; i < q->max_num_buffers; i++) { struct vb2_buffer *vb; struct media_request *req; @@ -2568,7 +2565,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_num_buffers); + __vb2_queue_free(q, 0, q->max_num_buffers); kfree(q->bufs); q->bufs = NULL; bitmap_free(q->bufs_bitmap); From patchwork Thu Oct 19 12:52: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: 155546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361028vqb; Thu, 19 Oct 2023 05:57:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaCyAKybhUYX2+y/Wk43UCofJ9uwZcieU/PBRwsqa19Bu4mQxVp5aKWLvmga+rdAWHp81t X-Received: by 2002:a05:6a00:190e:b0:6b3:f29c:dde1 with SMTP id y14-20020a056a00190e00b006b3f29cdde1mr1814410pfi.21.1697720253566; Thu, 19 Oct 2023 05:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720253; cv=none; d=google.com; s=arc-20160816; b=jasggEitAJ9heZhN7wUbAZGSuwrU+sAHlgUx46b9zFgLzXI/SHYiEjqwMm2C6Oj3Fp wuNPC4KnkjyX+HPPF1EJvZHrUcni5y/U9yanSQUR4G43t8SVTshFvl7CEI/X2/Sd31RK a91nCpw/f8Vw5RrBBUxlI3vpKOgEdnXv3LEP5YQtKZ8jEG3HrZTL5l+Ftb+XDMBwLkjM gnIKm45n5XpT9KChEZhwZLjJhqe1Ba9rtCcC0PsYf+dGcgMSSP3iLTubGdFGtbUW3sHQ IKmGBcvlAtYRRZ+o+NwcPIKDUzr7UGkcWNdTAcV+9FmuWOEtClYmrm1M2VafqVmbXm4u lvBA== 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=OzSxQ6f+EEBopvdmbTJ7OerDOy2d0BTDw9aCMRpJHyc=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=W7G9SpVSt6MmoecRQQ7n5+AGVoQU8KOjrCEtT+84NH677IuSr1GXMpGU/91Esk26pw U0sqj5erDjWFydIYNrGjwUqdDJDrDAdiFI9yEYBIBZCG7M5u0pD250PNC+bpP0lgdHYE PZHuYxs5FkMyXnBhzdFIhr6BnivklI1zT0p3wilqnIMxvaIcZ3ouEWsuA2J7R98x/vr0 eqTIijR3BntkbwTaffVHG6cdb4ltYJaLizUevSt41UJJrIWTqXxhvJCKgIKtBs7Q179X TQ91lbYB5kKinH5kE3HxUgwTOP5eQ+MB+dv9HXi96S0pTfBmiMN45c+hyRUk9Sk2Z4k2 dN5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=g+ew1zAI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bv127-20020a632e85000000b005b368301d97si3506292pgb.305.2023.10.19.05.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=g+ew1zAI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id DCF42802092B; Thu, 19 Oct 2023 05:57:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346281AbjJSM4o (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346108AbjJSMyD (ORCPT ); Thu, 19 Oct 2023 08:54:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CA7310FF; Thu, 19 Oct 2023 05:53:00 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 8BA5D660739D; Thu, 19 Oct 2023 13:52:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719978; bh=TrQ304Bh/J6HBUNGRbQQNdVWgt2Fd5lXztRIN6+OHeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g+ew1zAI+YzzAz9GoUSL9RrHp24xSqVsxVZpej9dAgKP602XVE2NaY8HclgWPu+ML Jh9XYh3SJOC10hNW8LfEM3TrofUn13U48yYOu1coiGyZ1hHSWP9WdJ23btYaePIIPo VPaOBlNw86Alr8qhk3U8gZ0g1V/GCu32lzot4VOVxH1zNxzoQCNAQB139/2DakruS/ hsVaq/QJbMfvAuZX2gL4QkjThZms2QH2FtNe9zTtjapNus7e5F1AjRj+y6Uma8VIEs pJhufjJILgXr5Zbp+vrEd+lICWc7G9cgHLF75roGYt7pwb8paZzRHheUyDL01GBst6 Tc5lvEvQWPI3w== 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 v13 54/56] media: v4l2: Add DELETE_BUFS ioctl Date: Thu, 19 Oct 2023 14:52:20 +0200 Message-Id: <20231019125222.21370-55-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:57:27 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188712602051951 X-GMAIL-MSGID: 1780188712602051951 VIDIOC_DELETE_BUFS ioctl allows to delete buffers from a queue. The number of buffers to delete in given by count field of struct v4l2_delete_buffers and the range start at the index specified in the same structure. Signed-off-by: Benjamin Gaignard --- .../userspace-api/media/v4l/user-func.rst | 1 + .../media/v4l/vidioc-delete-bufs.rst | 80 +++++++++++++++++++ .../media/v4l/vidioc-reqbufs.rst | 1 + .../media/common/videobuf2/videobuf2-core.c | 30 +++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 20 +++++ drivers/media/v4l2-core/v4l2-dev.c | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 17 ++++ include/media/v4l2-ioctl.h | 4 + include/media/videobuf2-core.h | 12 +++ include/media/videobuf2-v4l2.h | 13 +++ include/uapi/linux/videodev2.h | 17 ++++ 11 files changed, 196 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/vidioc-delete-bufs.rst diff --git a/Documentation/userspace-api/media/v4l/user-func.rst b/Documentation/userspace-api/media/v4l/user-func.rst index 15ff0bf7bbe6..3fd567695477 100644 --- a/Documentation/userspace-api/media/v4l/user-func.rst +++ b/Documentation/userspace-api/media/v4l/user-func.rst @@ -17,6 +17,7 @@ Function Reference vidioc-dbg-g-chip-info vidioc-dbg-g-register vidioc-decoder-cmd + vidioc-delete-bufs vidioc-dqevent vidioc-dv-timings-cap vidioc-encoder-cmd diff --git a/Documentation/userspace-api/media/v4l/vidioc-delete-bufs.rst b/Documentation/userspace-api/media/v4l/vidioc-delete-bufs.rst new file mode 100644 index 000000000000..4791df1395d6 --- /dev/null +++ b/Documentation/userspace-api/media/v4l/vidioc-delete-bufs.rst @@ -0,0 +1,80 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later +.. c:namespace:: V4L + +.. _VIDIOC_DELETE_BUFS: + +************************ +ioctl VIDIOC_DELETE_BUFS +************************ + +Name +==== + +VIDIOC_DELETE_BUFS - Deletes buffers from a queue +Drivers using this feature must expose the ``V4L2_BUF_CAP_SUPPORTS_DELETE_BUFS`` +capability on the queue :c:func:`VIDIOC_REQBUFS` or :c:func:`VIDIOC_CREATE_BUFS` +are invoked. + +Synopsis +======== + +.. c:macro:: VIDIOC_DELETE_BUFs + +``int ioctl(int fd, VIDIOC_DELETE_BUFs, struct v4l2_delete_buffers *argp)`` + +Arguments +========= + +``fd`` + File descriptor returned by :c:func:`open()`. + +``argp`` + Pointer to struct :c:type:`v4l2_delete_buffers`. + +Description +=========== + +Applications can optionally call the :ref:`VIDIOC_DELETE_BUFS` ioctl to +delete buffers from a queue. + +.. c:type:: v4l2_delete_buffers + +.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| + +.. flat-table:: struct v4l2_delete_buffers + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u32 + - ``index`` + - The starting buffer index to delete. + * - __u32 + - ``count`` + - The number of buffers to be deleted with indices 'index' until 'index + count - 1'. + All buffers in this range must be valid and in DEQUEUED state. + In error case errno is set to ``EINVAL`` error code and index returns the index of + the invalid buffer. + If count and index are set to 0 :ref:`VIDIOC_DELETE_BUFS` will return 0. + * - __u32 + - ``type`` + - Type of the stream or buffers, this is the same as the struct + :c:type:`v4l2_format` ``type`` field. See + :c:type:`v4l2_buf_type` for valid values. + * - __u32 + - ``reserved``\ [13] + - A place holder for future extensions. Drivers and applications + must set the array to zero. + +Return Value +============ + +On success 0 is returned, on error -1 and the ``errno`` variable is set +appropriately. The generic error codes are described at the +:ref:`Generic Error Codes ` chapter. + +EBUSY + File I/O is in progress. + +EINVAL + The buffer ``index`` doesn't exist in the queue. diff --git a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst index 0b3a41a45d05..14d4a49c2945 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst @@ -121,6 +121,7 @@ aborting or finishing any DMA in progress, an implicit .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: .. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS: +.. _V4L2-BUF-CAP-SUPPORTS-DELETE-BUFS: .. raw:: latex diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 010a8bca0240..7068930a0ba6 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1665,6 +1665,36 @@ int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb) } EXPORT_SYMBOL_GPL(vb2_core_prepare_buf); +int vb2_core_delete_bufs(struct vb2_queue *q, unsigned int start, unsigned int count) +{ + unsigned int i, ret = 0; + + if (start == 0 && count == 0) + return 0; + + mutex_lock(&q->mmap_lock); + + for (i = start; i < start + count && i < q->max_num_buffers; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); + + if (!vb) { + ret = -EINVAL; + goto unlock; + } + if (vb->state != VB2_BUF_STATE_DEQUEUED) { + ret = -EINVAL; + goto unlock; + } + } + __vb2_queue_free(q, start, count); + dprintk(q, 2, "buffers deleted\n"); + +unlock: + mutex_unlock(&q->mmap_lock); + return ret; +} +EXPORT_SYMBOL_GPL(vb2_core_delete_bufs); + /* * vb2_start_streaming() - Attempt to start streaming. * @q: videobuf2 queue diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 56daf3b5b2ba..f003618efbc1 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -694,6 +694,8 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) if (q->supports_requests) *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS; #endif + if (q->supports_delete_bufs) + *caps |= V4L2_BUF_CAP_SUPPORTS_DELETE_BUFS; } static void validate_memory_flags(struct vb2_queue *q, @@ -751,6 +753,12 @@ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, } EXPORT_SYMBOL_GPL(vb2_prepare_buf); +int vb2_delete_bufs(struct vb2_queue *q, struct v4l2_delete_buffers *d) +{ + return vb2_core_delete_bufs(q, d->index, d->count); +} +EXPORT_SYMBOL_GPL(vb2_delete_bufs); + int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) { unsigned requested_planes = 1; @@ -1012,6 +1020,18 @@ EXPORT_SYMBOL_GPL(vb2_poll); /* vb2 ioctl helpers */ +int vb2_ioctl_delete_bufs(struct file *file, void *priv, + struct v4l2_delete_buffers *p) +{ + struct video_device *vdev = video_devdata(file); + + if (vb2_queue_is_busy(vdev->queue, file)) + return -EBUSY; + + return vb2_delete_bufs(vdev->queue, p); +} +EXPORT_SYMBOL_GPL(vb2_ioctl_delete_bufs); + int vb2_ioctl_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p) { diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index f81279492682..215654fd6581 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -720,6 +720,7 @@ static void determine_valid_ioctls(struct video_device *vdev) SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf); SET_VALID_IOCTL(ops, VIDIOC_STREAMON, vidioc_streamon); SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff); + SET_VALID_IOCTL(ops, VIDIOC_DELETE_BUFS, vidioc_delete_bufs); } if (is_vid || is_vbi || is_meta) { diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 628b013ca0c4..309632a010d1 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -489,6 +489,13 @@ static void v4l_print_create_buffers(const void *arg, bool write_only) v4l_print_format(&p->format, write_only); } +static void v4l_print_delete_buffers(const void *arg, bool write_only) +{ + const struct v4l2_delete_buffers *p = arg; + + pr_cont("index=%u, count=%u\n", p->index, p->count); +} + static void v4l_print_streamparm(const void *arg, bool write_only) { const struct v4l2_streamparm *p = arg; @@ -2161,6 +2168,15 @@ static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, return ret ? ret : ops->vidioc_prepare_buf(file, fh, b); } +static int v4l_delete_bufs(const struct v4l2_ioctl_ops *ops, + struct file *file, void *fh, void *arg) +{ + struct v4l2_delete_buffers *delete = arg; + int ret = check_fmt(file, delete->type); + + return ret ? ret : ops->vidioc_delete_bufs(file, fh, delete); +} + static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file, void *fh, void *arg) { @@ -2910,6 +2926,7 @@ static const struct v4l2_ioctl_info v4l2_ioctls[] = { IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0), IOCTL_INFO(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)), IOCTL_INFO(VIDIOC_QUERY_EXT_CTRL, v4l_query_ext_ctrl, v4l_print_query_ext_ctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_query_ext_ctrl, id)), + IOCTL_INFO(VIDIOC_DELETE_BUFS, v4l_delete_bufs, v4l_print_delete_buffers, INFO_FL_PRIO | INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_delete_buffers, type)), }; #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index edb733f21604..55afbde54211 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -163,6 +163,8 @@ struct v4l2_fh; * :ref:`VIDIOC_CREATE_BUFS ` ioctl * @vidioc_prepare_buf: pointer to the function that implements * :ref:`VIDIOC_PREPARE_BUF ` ioctl + * @vidioc_delete_bufs: pointer to the function that implements + * :ref:`VIDIOC_DELETE_BUFS ` ioctl * @vidioc_overlay: pointer to the function that implements * :ref:`VIDIOC_OVERLAY ` ioctl * @vidioc_g_fbuf: pointer to the function that implements @@ -422,6 +424,8 @@ struct v4l2_ioctl_ops { struct v4l2_create_buffers *b); int (*vidioc_prepare_buf)(struct file *file, void *fh, struct v4l2_buffer *b); + int (*vidioc_delete_bufs)(struct file *file, void *fh, + struct v4l2_delete_buffers *d); int (*vidioc_overlay)(struct file *file, void *fh, unsigned int i); int (*vidioc_g_fbuf)(struct file *file, void *fh, diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 288477075a0e..db3bd986624e 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -507,6 +507,7 @@ struct vb2_buf_ops { * @supports_requests: this queue supports the Request API. * @requires_requests: this queue requires the Request API. If this is set to 1, * then supports_requests must be set to 1 as well. + * @supports_delete_bufs: this queue supports DELETE_BUFS ioctl. * @uses_qbuf: qbuf was used directly for this queue. Set to 1 the first * time this is called. Set to 0 when the queue is canceled. * If this is 1, then you cannot queue buffers from a request. @@ -595,6 +596,7 @@ struct vb2_queue { unsigned int quirk_poll_must_check_waiting_for_buffers:1; unsigned int supports_requests:1; unsigned int requires_requests:1; + unsigned int supports_delete_bufs:1; unsigned int uses_qbuf:1; unsigned int uses_requests:1; unsigned int allow_cache_hints:1; @@ -846,6 +848,16 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, */ int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb); +/** + * vb2_core_delete_bufs() - + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @start: first index of the range of buffers to delete. + * @count: number of buffers to delete. + * + * Return: returns zero on success; an error code otherwise. + */ +int vb2_core_delete_bufs(struct vb2_queue *q, unsigned int start, unsigned int count); + /** * vb2_core_qbuf() - Queue a buffer from userspace * diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 5a845887850b..79cea8459f52 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -118,6 +118,17 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create); */ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, struct v4l2_buffer *b); +/** + * vb2_delete_bufs() - Delete buffers from the queue + * + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @d: delete parameter, passed from userspace to + * &v4l2_ioctl_ops->vidioc_delete_bufs handler in driver + * + * The return values from this function are intended to be directly returned + * from &v4l2_ioctl_ops->vidioc_delete_bufs handler in driver. + */ +int vb2_delete_bufs(struct vb2_queue *q, struct v4l2_delete_buffers *d); /** * vb2_qbuf() - Queue a buffer from userspace @@ -334,6 +345,8 @@ int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i); int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i); int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p); +int vb2_ioctl_delete_bufs(struct file *file, void *priv, + struct v4l2_delete_buffers *p); /* struct v4l2_file_operations helpers */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 13ddb5abf584..96e105149906 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1036,6 +1036,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) +#define V4L2_BUF_CAP_SUPPORTS_DELETE_BUFS (1 << 8) /** * struct v4l2_plane - plane info for multi-planar buffers @@ -2622,6 +2623,20 @@ struct v4l2_create_buffers { __u32 reserved[5]; }; +/** + * struct v4l2_delete_buffers - VIDIOC_DELETE_BUFS argument + * @index: the first buffer to be deleted + * @count: number of buffers to delete + * @type: enum v4l2_buf_type + * @reserved: future extensions + */ +struct v4l2_delete_buffers { + __u32 index; + __u32 count; + __u32 type; + __u32 reserved[13]; +}; + /* * I O C T L C O D E S F O R V I D E O D E V I C E S * @@ -2721,6 +2736,8 @@ struct v4l2_create_buffers { #define VIDIOC_DBG_G_CHIP_INFO _IOWR('V', 102, struct v4l2_dbg_chip_info) #define VIDIOC_QUERY_EXT_CTRL _IOWR('V', 103, struct v4l2_query_ext_ctrl) +#define VIDIOC_DELETE_BUFS _IOWR('V', 104, struct v4l2_delete_buffers) + /* Reminder: when adding new ioctls please add support for them to drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */ From patchwork Thu Oct 19 12:52:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 155557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp361501vqb; Thu, 19 Oct 2023 05:58:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfz8/Wt8/frVpScAM4eaC3B/lOA5D5nQNLcSqNyRk6gO1cRwU5nv260f8Ie90LZ+PfT6We X-Received: by 2002:a9d:61d4:0:b0:6c4:c3ac:a9dc with SMTP id h20-20020a9d61d4000000b006c4c3aca9dcmr2150143otk.21.1697720308612; Thu, 19 Oct 2023 05:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720308; cv=none; d=google.com; s=arc-20160816; b=vpp6CWvZOGhG81Onth1YEyt1Nmt7VaqOV7RVAKKAMPlj7ZELZzG8p68WJTTphLwsgi MMSQX7cnbyXiWHmgjUk1s+N1hOv/cbkJe/N+xOp0MMkTzgBLaiK8FAnVYYUNOnrgtyEl a9iN6bUZFw3mkw65WvT5MPY9W0mLCV6dw0wVrymIdImpEsOP0US+ISxAjQEObmFdrNNp PUBqSSIKompR9Qx/97AqKvsWvRMbnMWALIFJNykJCqMyOmLGZl7C80YGPVBwSLSsWvlA toz4njr0mHPmiU7cGL7fKMNkXDWYbkoi25GoLVR/HhdPc7OjBLrH2OjdpaN44dfExHNU jKgA== 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=BBbmoeOgSzf6cmSDSYo0xxyyvrTQBdluhroEQ4pTGbE=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=JDmGKk+mo0q7OJN2vGpTNkV+0/jghlWdJIdMFdyfFRqMJEEaO33LrmHEHaBUobqQsM NEf364IKgaDe/qPAm4xiWmd6HJxKaJuU6KjU97T+40azAtg6PJCqyLFEsnxtmAeUM1KZ zGWCAnKPxMu2qc7FvdWjQIBy9a/CPMETxd65husgt4baLjdjzpiBNLRi2+b/nIYHFTk4 ldW8G5649mSeyIUpU6k8OtVfkRdbuio9krclKOgqcVFBE2CeLLjuEp3iSntMCu+QlVGD hw15T9pWIALpGvf/sQT2rGifeTBKhv8/kSew9HTrMvkp+JAV9uDMgvRWKri2138GYgYj /j/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=m92WuhRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id n5-20020aa79845000000b006be062e4ecbsi6044120pfq.32.2023.10.19.05.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:58:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=m92WuhRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id B2824818CC87; Thu, 19 Oct 2023 05:58:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345902AbjJSM4f (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346098AbjJSMyC (ORCPT ); Thu, 19 Oct 2023 08:54:02 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE241700; Thu, 19 Oct 2023 05:53:00 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 0D580660739E; Thu, 19 Oct 2023 13:52:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719979; bh=LkM/7EVzkzeCersLJmzLfirkGugiivs+DlFzZEGNCYQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m92WuhRDE7xxdVNdj8Rui74jQ5iRmOdBOqItx3c2KN8+BfA3l9KCh2QKUHkp2ehan o3sv+C+C2q5/QwH/7T5RP/LFP17j70t0DfuQjKXBau6h21Fd0RPSIBVp+2FmEh+zEM snHfQIZfJYjoGchV1NTzD4z6n+pUktOCQDgs7Epa/+ypVDMT9XPUpH1aDGr9Vk64qQ ATRE9GtNi0PUUOdJprp2Cdr4CAo4iakXQT1C7ItAnA/JKa5DFgmwc9KweD9aPRNQ69 LH5WzXUbrlxGOM389nGVUEXiPibDqXW+5Tr/leVyRJ44IwPJH6EZqXHN3ezUc49ybS SE+lOjlKznSpQ== 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 v13 55/56] media: v4l2: Add mem2mem helpers for DELETE_BUFS ioctl Date: Thu, 19 Oct 2023 14:52:21 +0200 Message-Id: <20231019125222.21370-56-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 05:58:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188769932134537 X-GMAIL-MSGID: 1780188769932134537 Create v4l2-mem2mem helpers for VIDIOC_DELETE_BUFS ioctl. Signed-off-by: Benjamin Gaignard --- .../media/platform/verisilicon/hantro_drv.c | 1 + .../media/platform/verisilicon/hantro_v4l2.c | 1 + drivers/media/test-drivers/vim2m.c | 2 ++ drivers/media/v4l2-core/v4l2-mem2mem.c | 20 +++++++++++++++++++ include/media/v4l2-mem2mem.h | 12 +++++++++++ 5 files changed, 36 insertions(+) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index 7f5b82eb6649..c8fed313c36f 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -248,6 +248,7 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; dst_vq->lock = &ctx->dev->vpu_mutex; dst_vq->dev = ctx->dev->v4l2_dev.dev; + src_vq->supports_delete_bufs = true; return vb2_queue_init(dst_vq); } diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 27a1e77cca38..0fd1c2fc78c8 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -756,6 +756,7 @@ const struct v4l2_ioctl_ops hantro_ioctl_ops = { .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_delete_bufs = v4l2_m2m_ioctl_delete_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, diff --git a/drivers/media/test-drivers/vim2m.c b/drivers/media/test-drivers/vim2m.c index 3e3b424b4860..17213ce42059 100644 --- a/drivers/media/test-drivers/vim2m.c +++ b/drivers/media/test-drivers/vim2m.c @@ -960,6 +960,7 @@ static const struct v4l2_ioctl_ops vim2m_ioctl_ops = { .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_delete_bufs = v4l2_m2m_ioctl_delete_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_streamon = v4l2_m2m_ioctl_streamon, @@ -1133,6 +1134,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->mem_ops = &vb2_vmalloc_memops; dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; dst_vq->lock = &ctx->vb_mutex; + dst_vq->supports_delete_bufs = true; return vb2_queue_init(dst_vq); } diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 0cc30397fbad..d1d59943680f 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -831,6 +831,17 @@ int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, } EXPORT_SYMBOL_GPL(v4l2_m2m_prepare_buf); +int v4l2_m2m_delete_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, + struct v4l2_delete_buffers *d) +{ + struct vb2_queue *vq; + + vq = v4l2_m2m_get_vq(m2m_ctx, d->type); + + return vb2_delete_bufs(vq, d); +} +EXPORT_SYMBOL_GPL(v4l2_m2m_delete_bufs); + int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, struct v4l2_create_buffers *create) { @@ -1377,6 +1388,15 @@ int v4l2_m2m_ioctl_create_bufs(struct file *file, void *priv, } EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_create_bufs); +int v4l2_m2m_ioctl_delete_bufs(struct file *file, void *priv, + struct v4l2_delete_buffers *d) +{ + struct v4l2_fh *fh = file->private_data; + + return v4l2_m2m_delete_bufs(file, fh->m2m_ctx, d); +} +EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_delete_bufs); + int v4l2_m2m_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf) { diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index d6c8eb2b5201..161f85c42dc8 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -381,6 +381,16 @@ int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, struct v4l2_buffer *buf); +/** + * v4l2_m2m_delete_bufs() - delete buffers from the queue + * + * @file: pointer to struct &file + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @d: pointer to struct &v4l2_delete_buffers + */ +int v4l2_m2m_delete_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, + struct v4l2_delete_buffers *d); + /** * v4l2_m2m_create_bufs() - create a source or destination buffer, depending * on the type @@ -860,6 +870,8 @@ int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *rb); int v4l2_m2m_ioctl_create_bufs(struct file *file, void *fh, struct v4l2_create_buffers *create); +int v4l2_m2m_ioctl_delete_bufs(struct file *file, void *priv, + struct v4l2_delete_buffers *d); int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf); int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh, From patchwork Thu Oct 19 12:52: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: 155542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp360943vqb; Thu, 19 Oct 2023 05:57:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWOhYgmjJQXf/RBoHFXt5IReD89o9biIwVATMRdLPQC5QIz3L4s58n7918Ttn3fIjbii8M X-Received: by 2002:a17:902:d2ca:b0:1ca:1224:547a with SMTP id n10-20020a170902d2ca00b001ca1224547amr2650812plc.23.1697720242314; Thu, 19 Oct 2023 05:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697720242; cv=none; d=google.com; s=arc-20160816; b=kWr6K6dQrPQZ21rzMYIEJeS8okejdMhZzzaAiTylrDnGqi2Nz67AcqFqLuRLSngAow HIs+bLuPMXHz6zIn6k7y5cQp/nYePJOEJnOfOC0tMXi5JB0g/UyrW2Jnrg9F0NeGMUE9 2loijcbSKl48ToBVMU5Gc8LXqe4tuX6U9SoxCyg+gFgM1AqfMk6oleNtm6h1lKjFRMGV L/gmc9cid/krGzw+W0YJvgHmsPT+Y7EXiIa/rGFh6Wl+nES6EZaK3iqKiN0HqiYhr0JL uGa/z/jr4j7uHax1+nKWiPu1TqFQOTPagS4TyLD9Dtj3QrSAasvIxcsB/S8i0+ly3wOP a0TA== 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=V3SIv+BY82kt3dIIb3TGqHBNa1h3sHcqVcwzOz3RU90=; fh=ceA81l8d2hZW6pWH7VE5TwJxtgXUzAubfWIMcikPA1M=; b=Tc0gfnQ2caqVpPzeuC0zuwZKlILs2J/rkC+fX79WbvmECSjJrEu3TQUNL0icSNj0hQ mrpy2Hbco24lyVZH4z0CZVDwGtp2JdkoQxWXIX/OQMdU0NGYi4+CS0hv63cpQpzgbVce 5TyN9Lx1gv0s9uz/DEtqTXVm7MB1RDehsBHIf4YOqnwKfLckZ6tjJYbj3DeU9CafwoAC UP63iioDC1hfRBGBdG37KOKPEqsfVt9S9MQoDYfQAyVtJDwHqIoHSsOY57JiZ63bPc9f Qsg8paLCuhNDZajduvQivv7mb3VJWaFL5tJy99i7JI+PDqvgh0S3zCvAG3y6a4lYcLnL naEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=S+twYbAN; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j6-20020a170902da8600b001c3323ff53asi2326455plx.139.2023.10.19.05.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 05:57:22 -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=S+twYbAN; 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 7CC53822D0A1; Thu, 19 Oct 2023 05:57:21 -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 S1346165AbjJSM4q (ORCPT + 25 others); Thu, 19 Oct 2023 08:56:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346114AbjJSMyD (ORCPT ); Thu, 19 Oct 2023 08:54:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22B311709; Thu, 19 Oct 2023 05:53:01 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:ccea:1fb5:34eb:239b]) (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 8F33266073A4; Thu, 19 Oct 2023 13:52:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1697719980; bh=bvlqKNzionLKB1VClCmq81RGJBsdZ7hA0RN2y42SWPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S+twYbANrVJ+kjFi560OlpvROgm4yskA9m74KZaNoNOqqwZDuqk2lxtJueSvP7eSI SNg2Ux5H/OrSlPFcQMMythq1uzew7TVhUB7TFgkt3UuIpYUalnUV3nuH7PvlJNWLLe ZtuIXhV0/MPboo4zQLOr7XjDj2j76WDEJB8/9Le4qip9SrINsSKmYkqR/1tQap6LAB nchR9GtmCGKC6WMFiY//ZQ4VX9E5r4FSipS1trPZWtWjTIbV5FviGQFE/xDVNA08rf VS//ESVvprpVlJai3bN0OJaNLhxrLKG8wnLlOhjOP22Izkuqrp2ungM1xRwMYM5K9L eKBs9BkgGRvJw== 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 v13 56/56] media: test-drivers: Use helper for DELETE_BUFS ioctl Date: Thu, 19 Oct 2023 14:52:22 +0200 Message-Id: <20231019125222.21370-57-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231019125222.21370-1-benjamin.gaignard@collabora.com> References: <20231019125222.21370-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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, 19 Oct 2023 05:57:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780188700799540802 X-GMAIL-MSGID: 1780188700799540802 Allow test drivers to use DELETE_BUFS by adding vb2_ioctl_delete_bufs() helper. Signed-off-by: Benjamin Gaignard --- drivers/media/test-drivers/vicodec/vicodec-core.c | 2 ++ drivers/media/test-drivers/vimc/vimc-capture.c | 2 ++ drivers/media/test-drivers/visl/visl-video.c | 2 ++ drivers/media/test-drivers/vivid/vivid-core.c | 13 ++++++++++--- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c index 69cbe2c094e1..f14a8fd506d0 100644 --- a/drivers/media/test-drivers/vicodec/vicodec-core.c +++ b/drivers/media/test-drivers/vicodec/vicodec-core.c @@ -1339,6 +1339,7 @@ static const struct v4l2_ioctl_ops vicodec_ioctl_ops = { .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_delete_bufs = v4l2_m2m_ioctl_delete_bufs, .vidioc_streamon = v4l2_m2m_ioctl_streamon, .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, @@ -1725,6 +1726,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->mem_ops = &vb2_vmalloc_memops; dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; dst_vq->lock = src_vq->lock; + dst_vq->supports_delete_bufs = true; return vb2_queue_init(dst_vq); } diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index aa944270e716..fda7ea3a6cb6 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -221,6 +221,7 @@ static const struct v4l2_ioctl_ops vimc_capture_ioctl_ops = { .vidioc_expbuf = vb2_ioctl_expbuf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_delete_bufs = vb2_ioctl_delete_bufs, }; static void vimc_capture_return_all_buffers(struct vimc_capture_device *vcapture, @@ -435,6 +436,7 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc, q->min_buffers_needed = 2; q->lock = &vcapture->lock; q->dev = v4l2_dev->dev; + q->supports_delete_bufs = true; ret = vb2_queue_init(q); if (ret) { diff --git a/drivers/media/test-drivers/visl/visl-video.c b/drivers/media/test-drivers/visl/visl-video.c index 7cac6a6456eb..bd6c112f7846 100644 --- a/drivers/media/test-drivers/visl/visl-video.c +++ b/drivers/media/test-drivers/visl/visl-video.c @@ -521,6 +521,7 @@ const struct v4l2_ioctl_ops visl_ioctl_ops = { .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_delete_bufs = v4l2_m2m_ioctl_delete_bufs, .vidioc_streamon = v4l2_m2m_ioctl_streamon, .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, @@ -728,6 +729,7 @@ int visl_queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->mem_ops = &vb2_vmalloc_memops; dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; dst_vq->lock = &ctx->vb_mutex; + dst_vq->supports_delete_bufs = true; return vb2_queue_init(dst_vq); } diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index 353f035fcd19..06b18d8e2248 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -769,6 +769,7 @@ static const struct v4l2_ioctl_ops vivid_ioctl_ops = { .vidioc_expbuf = vb2_ioctl_expbuf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_delete_bufs = vb2_ioctl_delete_bufs, .vidioc_enum_input = vivid_enum_input, .vidioc_g_input = vivid_g_input, @@ -883,12 +884,18 @@ static int vivid_create_queue(struct vivid_dev *dev, * PAGE_SHIFT > 12, but then max_num_buffers will be clamped by * videobuf2-core.c to MAX_BUFFER_INDEX. */ - if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { q->max_num_buffers = 64; - if (buf_type == V4L2_BUF_TYPE_SDR_CAPTURE) + q->supports_delete_bufs = true; + } + if (buf_type == V4L2_BUF_TYPE_SDR_CAPTURE) { q->max_num_buffers = 1024; - if (buf_type == V4L2_BUF_TYPE_VBI_CAPTURE) + q->supports_delete_bufs = true; + } + if (buf_type == V4L2_BUF_TYPE_VBI_CAPTURE) { q->max_num_buffers = 32768; + q->supports_delete_bufs = true; + } if (allocators[dev->inst] != 1) q->io_modes |= VB2_USERPTR;