Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp463290rdb; Tue, 16 Jan 2024 06:03:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZHC0j1lIdOWulZkn9Mp+NTNyZFjFVvfo9KYuhW2RzlRiaOqCHOqodESfNoObQIijn0fVV X-Received: by 2002:ad4:5b82:0:b0:681:5953:50d5 with SMTP id 2-20020ad45b82000000b00681595350d5mr4698037qvp.10.1705413810968; Tue, 16 Jan 2024 06:03:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705413810; cv=none; d=google.com; s=arc-20160816; b=PBSYyw99AXtbmgbNtjUUrTn1TkY055szBwUF9/srUAU7SOP+WfDiZepZvL8WI/bGVs jJogOJ040pEK5T2ZnMcf2EI9gQ3B9f7Js71U9yyrnxqMola/2qTNNptobqEw6x52JJj4 kTG0EkEtAlj8eNQcJNXSY1SdwnIU9+09wZ5KanWrxY+o4URzrj2XiDYrrLHfV0SZqB1X aXJsa0wNioMT5YOGpznlMTdEB3B0nK4lqjXw4Upj+J7WB4oLyuxFZATjs1X+zTqvDkQj TDwMMFtXIQ76aSinBdrhhyELRNVi/KvL6C0kA1bNv9caMo0j1daz4smxrKZVFW/Aay+M bhdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=8qeT6Q/z/ACCS6tqh3qLoAzHo24ykOZeDRlwxptJp/0=; fh=s5ILSJYGrltTZ4252qGnp2owfPbQLBzfcEObv0h78nE=; b=xSJIEAs6tLL8ZOIpZxPNp1CEhunlQ/N/XuTYCVSLGmLOi5E9QWjygcEgA6K4/QVTrM cKRQEh5+WtAVcixxAurKEUA+uxiClIuTeKGvhjTHeobva70p1raF92ckMbvxxRE1SvEP gHpuhgzocTiEOeeu8noD2t2Qut0/hPwKrNBwmPwqDNlvoCWFoS1+gcuqxllJlsdVIBsG fJe8I8E08trXloYX9JVOwXzrBTMbgBK448Ii0KYimXSdwz1794bXhUoQBbKN2boFXrxa 1c3pr3y7kS6to8kSNsRbYUOm09rZPQT2o8gWM+lffQ+WSojHldDIoaSKOvfCy5+dEww2 2wOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a11-20020a05622a02cb00b0042a084999d6si635099qtx.726.2024.01.16.06.03.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 06:03:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27443-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27443-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B008F1C2222D for ; Tue, 16 Jan 2024 14:03:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D0331BDE9; Tue, 16 Jan 2024 14:03:21 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ED3A1BDD6; Tue, 16 Jan 2024 14:03:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3490DC433C7; Tue, 16 Jan 2024 14:03:18 +0000 (UTC) Message-ID: Date: Tue, 16 Jan 2024 15:03:16 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] media: core: Refactor vb2_ioctl_create_bufs() to always set capabilities flags Content-Language: en-US, nl To: Benjamin Gaignard , tfiga@chromium.org, m.szyprowski@samsung.com, mchehab@kernel.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com References: <20240115170826.214519-1-benjamin.gaignard@collabora.com> From: Hans Verkuil In-Reply-To: <20240115170826.214519-1-benjamin.gaignard@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 15/01/2024 18:08, Benjamin Gaignard wrote: > vb2_create_bufs() takes care of setting V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS > flag and vb2_queue max_num_buffers field so call it instead duplicate the > same code in vb2_ioctl_create_bufs(). Testing p->count after calling > vb2_create_bufs() is safe since the function also check it. > > Fixes: d055a76c0065 ("media: core: Report the maximum possible number of buffers for the queue") > Signed-off-by: Benjamin Gaignard > --- > .../media/common/videobuf2/videobuf2-v4l2.c | 23 ++++++++++--------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > index 54d572c3b515..bf304a7234a0 100644 > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > @@ -1029,23 +1029,24 @@ 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 (vb2_queue_is_busy(vdev->queue, file)) { > + res = -EBUSY; > + goto failed; > + } > + > + res = vb2_create_bufs(vdev->queue, p); > + if (res == 0) > + vdev->queue->owner = file->private_data; This would set owner when called with p->count == 0, but that's not what you want. I decided to make an attempt at this myself, I'll post a patch. Regards, Hans > + > +failed: > /* > * 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. > + * Any -EBUSY result from vb2_verify_memory_type() or > + * vb2_queue_is_busy() can be mapped to 0. > */ > if (p->count == 0) > return res != -EBUSY ? res : 0; > - if (res) > - return res; > - if (vb2_queue_is_busy(vdev->queue, file)) > - return -EBUSY; > > - res = vb2_create_bufs(vdev->queue, p); > - if (res == 0) > - vdev->queue->owner = file->private_data; > return res; > } > EXPORT_SYMBOL_GPL(vb2_ioctl_create_bufs);