From nobody Wed Feb 11 08:13:47 2026 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FEC520F062 for ; Mon, 2 Jun 2025 12:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748869152; cv=none; b=HZoeMLEl/e4D0G1ORfRJrcRsJekXwlczBBZBdR3hC8MpwyP2BZPJcIud4nLUpRu034m3pHmtXAIIe8eJeevhbUB/P+CVzYyBhbxkjq83yyveC95Hq3KD855QQFcHLa32QXlurjuHMpnDDir/e3M30yuqK6cwZHGEcBLWTR/2DEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748869152; c=relaxed/simple; bh=pAwYR7oteo3vN3c/HkFqcbWJsyd0dKKMMaP2gKBrNyk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GTpV0AkGxfYtFKYoCU9mXEr2m/ja7MTHJiERYF3tpF13HVWHtiTvugiqssHt+4HLhjU8eZbF1/SJATPm4lpLCF6wCIozPp5pY95F9n96OI+pfTumEftCwyhg/sqmGwjXQFYnuBZaZ+kq+/d8jjUbL60X5cb/PcArni7eoHNLThg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=fqhGoqDF; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fqhGoqDF" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-55350d0eedeso312914e87.2 for ; Mon, 02 Jun 2025 05:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748869149; x=1749473949; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7YmjTdxkPOA1uf9GrAFrNIGDFJaY+dZi3frhM7shyiw=; b=fqhGoqDFhiA6lmteLazdFiNZ4vNoMm4aK0k4n5O8njS27lm5TVsyqCNaymkeXlg9cS SGuforgNkCC65tNJ7oPsT7KYSqCRMFA1WsLP6Rp+c2gxgMyFKwT+luu6QcVM/HLj/Qvo R2Ha7DE+8mO0lx9izTV0d74ILc/ppooSrbxuk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748869149; x=1749473949; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7YmjTdxkPOA1uf9GrAFrNIGDFJaY+dZi3frhM7shyiw=; b=a2IdUFxyY6rp7QUTCiScMIfwVEXuUdn5z2CDL55TfSyKiW+J0WLE5rRRuoe3aDuY/I IORXi0NLMiHv4njyO8tR8Kw12HvUKe+2vA5/boJi8Z9pvdxORM6J0UdiX0ydKYNuOtvd jlh/PtTRfen/vfWMWNVqtpYT658OxDkykRf6VxBoB64WlfbdtY9sCpaL1b0Oq1tOmEWc Hk5sx8NYp+9QOn4KcIzpd9/2dXKBHuYTUcjziENdr+j6gZkJKImekYRLL/kxS1glmjbX 5y1ESBfSj4Ln2lhVA/953cLPAA9WsJji1cqnxWXOb7utbZ+/7H26VKnAezQ7aYQQ7ZTw 24/g== X-Forwarded-Encrypted: i=1; AJvYcCW5+Pn5IrPH8OVfxDDzliO1l+Ewvzd2a5wAkdQYC0DLeTGYGX2QXFNjY7XEeCLk/84cVlXzDKHYhi6Sv1I=@vger.kernel.org X-Gm-Message-State: AOJu0YyCYHynODB645/C7dkXJB0Pc9LLEJjly4mVY81D334nydFTgZq6 EUf+oBYci+TKmBTFI8qm3SY7KKu/tU2/TYf+U+lfk3L7yVUtbCoKu+zaZZ/niUqIAQ== X-Gm-Gg: ASbGnctFn9buSIU32hPNReFmsVHOBlUJf5e0SDrOmnOavdgALPalJFXhXgVjpe2rZq/ Pr9oaG7EsEbI+T44uVrxw5Sk+qQS7Pc6wXTatMw5pXyYgp743VgmKltEC+x99J/DQDsKeAFLnj9 DxGfnFIy+vttZkw2ECXm9TOQDeclCKkkVq9yhnEHwCj4kJHtaRw/pmK13J8avG3Am+V7vAsqH/o uOi27YhdntkwoOJFimNsCpPgASmDZvwoIy+FDImJO/xzNRdh7SpSpBM/aVRM42RSuRq7rN41w00 Koq5u6vIA7KrYieyefDFVl9qx/wVJoXsRA7O3cTurVTjAxqbtNLdoJdirtNaE9s4wm3zSe6k78v gjUtCyQmUvOCDyq/mQT+EoWKJbQ== X-Google-Smtp-Source: AGHT+IENDYsuYrVM/PI/1zsFe+YIqnGhU0k6On7h3XKKfr6W2ID3ogEuuMlqT9Xqt6MGTCUJahfdTw== X-Received: by 2002:a05:6512:3d25:b0:553:3945:82a7 with SMTP id 2adb3069b0e04-5533d160fe8mr3828575e87.12.1748869148648; Mon, 02 Jun 2025 05:59:08 -0700 (PDT) Received: from ribalda.c.googlers.com (90.52.88.34.bc.googleusercontent.com. [34.88.52.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-553379377a8sm1601140e87.239.2025.06.02.05.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 05:59:07 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 12:59:02 +0000 Subject: [PATCH v2 1/3] media: uvcvideo: Refactor uvc_queue_streamon Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250602-uvc-fop-v2-1-508a293eae81@chromium.org> References: <20250602-uvc-fop-v2-0-508a293eae81@chromium.org> In-Reply-To: <20250602-uvc-fop-v2-0-508a293eae81@chromium.org> To: Laurent Pinchart , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil X-Mailer: b4 0.14.2 Do uvc_pm_get before we call uvc_queue_streamon. Although the current code is correct, uvc_ioctl_streamon is always called after uvc_pm_get, this change makes the code more resiliant to future changes. This change also avoids calling streamoff, which is a rather ugly thing to do. Suggested-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 668a4e9d772c6d91f045ca75e2744b3a6c69da6b..862b4e34e5b629cf324479a9bb5= 9ebe8784ccd5d 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -853,15 +853,16 @@ static int uvc_ioctl_streamon(struct file *file, void= *fh, if (handle->is_streaming) return 0; =20 - ret =3D uvc_queue_streamon(&stream->queue, type); + ret =3D uvc_pm_get(stream->dev); if (ret) return ret; =20 - ret =3D uvc_pm_get(stream->dev); + ret =3D uvc_queue_streamon(&stream->queue, type); if (ret) { - uvc_queue_streamoff(&stream->queue, type); + uvc_pm_put(stream->dev); return ret; } + handle->is_streaming =3D true; =20 return 0; --=20 2.49.0.1266.g31b7d2e469-goog From nobody Wed Feb 11 08:13:47 2026 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7CF021D018 for ; Mon, 2 Jun 2025 12:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748869157; cv=none; b=dJ95sRlcWkgWfo8QKWvY5WqREV8HWvPWjQE5eU1NGAEr2XE8lEO7f7nJawL0MtoAIeERdUJpKixs6CvvfxclLHaB7dJTVvv433M2WZvesAeHEwP7KjKB/4K3qf+75OGO9WMKEMloyR9aZp69ii6jRLyhgbfvyuCPRwrOTwuttWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748869157; c=relaxed/simple; bh=Ij6zG2YNvNoyMgG7FCWx7uSNC0T7UFety25iU0PojKI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bEwrQjuPladkBkgp9dyNNxipxfll+VFsp9eAIqR3/pjq7qL9u0CnzHqBLXItmFOgrZFTNfdgaaDqDiKsEfFhh0eL3ZTDlt1DDbLzmC9KcAPfmAGbpae9+yDj+CSBUN0dlNbBs34kwwc0D2I3kT63JT1RdIAVqQVs88YnZDQQ8Tw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=E4PQaL0D; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="E4PQaL0D" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-5533303070cso4872070e87.2 for ; Mon, 02 Jun 2025 05:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748869152; x=1749473952; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0hsvM1ityLLNBC4bN/XE4WBa61ejSufh04bhxVWi6Po=; b=E4PQaL0Dwu7L6G774iUQ7Vz4g/+FIxivUeJqCUsL7NpLkHWzwEQemHZCdWdCX3+cGj fZ4lzxhx4AOsNymhocUm6oVOVcUQCWdVJGxOHQEZSWTm18WWWhOCsLY1XIZtodcUqe/N 4WpnDT7/MOnuknX7ZGt8leihbqzKE1yZDstOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748869152; x=1749473952; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0hsvM1ityLLNBC4bN/XE4WBa61ejSufh04bhxVWi6Po=; b=rtEuli2TyDtFhkkvrga6xj98AFCp/VWaiSRncpO3E7+mg6eDBwru9/DNbiFBeYbaRk cVGRuMt7O7tmKPCGNIxcULSNDW8oqqCkVfOugNUVMzyM2Ie1bDj+Pl6rwOFB+/jcMefk yoXuImpHocfjGVj3SuxRUti3aoUoDVzwx4Z+FQ/TqQuMjtzIH43l0cO1BMP8zMIR1bdR +7cRm6f+OqEw10e6RucmhfhHImvOhJ+5G6VqUcjamdtOBbbu99RMDsVd1jVjCkCB3Bqf CIPbfut606c8hDH4tKnWJnIJsWGDENaQMMScHINVVFpAqr5ViatmjTIyXb25B1XH3CTn YlCw== X-Forwarded-Encrypted: i=1; AJvYcCUogfmzvLF2fnTMLFKHAFR85xt9taJ/PwF4DMKMO9fIhlZeFqrKVw/F6dGQdIo9HjNwr36IOs3DTkvvKqM=@vger.kernel.org X-Gm-Message-State: AOJu0YxgCXE1TWEb7yO5cA6uoisfKa/arQWFi1FtlNzcEeG3ctkwHe44 Qzq6V+tL8BwSOO2AORDz2acD7mi6P6Z8I0XrvsIErosU/1CyKDYJBw1SCtrN98F9+A== X-Gm-Gg: ASbGnct5PWsqsceQTdaMqGBbnJWRWwxxYdXQ4YrRSqmOgYzQ44DHbCveeXek8YeJAZH 1qDk1xq0GB/fBCwBtVVRCtquZfJmOcOXV4ahG70bL/s2ltplAqQTvyONBCjcJmhSAVNe+Acf9+J 42kt/4yMtqs6cN/oihEoC8jOXHpiWDtWw2lWVXqQKi6ci6wpcqlvGWGET+Ub/YxbGxuxibu4lWT jgVMkJKc90zKitMC0coLPjyep3f1Y4SZyAPEXK0SheTbtOMRhy6w3gRzpDCYUSQSqeUnsNaleSG SgKJCaZOG93W50yBxv6yWtdRnWEPP/5sq0EsR7QU5ATSMqzBhzas97GvvoLATa6gdplCX+Nv6S+ O7ynt5W/+tl46v7l9hLP2es2+Bw== X-Google-Smtp-Source: AGHT+IEuUiX5fIaavSpIGJlOt5eN8RtPmpJxnUk6i2AzGMu+xRUPmGNu5tt0dALDKASHKs8sItBT3w== X-Received: by 2002:a05:6512:3d8d:b0:553:2421:f5e3 with SMTP id 2adb3069b0e04-55342f68c8dmr1787400e87.19.1748869151733; Mon, 02 Jun 2025 05:59:11 -0700 (PDT) Received: from ribalda.c.googlers.com (90.52.88.34.bc.googleusercontent.com. [34.88.52.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-553379377a8sm1601140e87.239.2025.06.02.05.59.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 05:59:09 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 12:59:03 +0000 Subject: [PATCH v2 2/3] media: uvcvideo: Use vb2 ioctl and fop helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250602-uvc-fop-v2-2-508a293eae81@chromium.org> References: <20250602-uvc-fop-v2-0-508a293eae81@chromium.org> In-Reply-To: <20250602-uvc-fop-v2-0-508a293eae81@chromium.org> To: Laurent Pinchart , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans de Goede , Hans Verkuil X-Mailer: b4 0.14.2 From: Hans Verkuil When uvc was written the vb2 ioctl and file operation helpers didn't exist. This patch switches uvc over to those helpers, which removes a lot of boilerplate code and simplifies VIDIOC_G/S_PRIORITY handling and allows us to drop the 'privileges' scheme, since that's now handled inside the vb2 helpers. This makes it possible for uvc to fix the v4l2-compliance streaming tests: warn: v4l2-test-formats.cpp(1075): Could not set fmt2 This patch introduces a change on behavior on the uvcdriver to be aligned with the rest of the subsystem. Now S_INPUT, S_PARM and S_FORMAT do no grant exclusive ownership of the device. Reviewed-by: Hans de Goede Reviewed-by: Hans Verkuil Signed-off-by: Hans Verkuil Co-developed-by: Ricardo Ribalda Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 34 +---- drivers/media/usb/uvc/uvc_metadata.c | 8 +- drivers/media/usb/uvc/uvc_queue.c | 143 -------------------- drivers/media/usb/uvc/uvc_v4l2.c | 251 +++----------------------------= ---- drivers/media/usb/uvc/uvcvideo.h | 37 +----- 5 files changed, 30 insertions(+), 443 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index da24a655ab68cc0957762f2b67387677c22224d1..4eeedab93b90939fc4c925012a1= 8b7d018ade39f 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1725,7 +1725,6 @@ static struct uvc_video_chain *uvc_alloc_chain(struct= uvc_device *dev) INIT_LIST_HEAD(&chain->entities); mutex_init(&chain->ctrl_mutex); chain->dev =3D dev; - v4l2_prio_init(&chain->prio); =20 return chain; } @@ -1958,31 +1957,7 @@ static void uvc_unregister_video(struct uvc_device *= dev) if (!video_is_registered(&stream->vdev)) continue; =20 - /* - * For stream->vdev we follow the same logic as: - * vb2_video_unregister_device(). - */ - - /* 1. Take a reference to vdev */ - get_device(&stream->vdev.dev); - - /* 2. Ensure that no new ioctls can be called. */ - video_unregister_device(&stream->vdev); - - /* 3. Wait for old ioctls to finish. */ - mutex_lock(&stream->mutex); - - /* 4. Stop streaming. */ - uvc_queue_release(&stream->queue); - - mutex_unlock(&stream->mutex); - - put_device(&stream->vdev.dev); - - /* - * For stream->meta.vdev we can directly call: - * vb2_video_unregister_device(). - */ + vb2_video_unregister_device(&stream->vdev); vb2_video_unregister_device(&stream->meta.vdev); =20 /* @@ -2029,7 +2004,8 @@ int uvc_register_video_device(struct uvc_device *dev, vdev->fops =3D fops; vdev->ioctl_ops =3D ioctl_ops; vdev->release =3D uvc_release; - vdev->prio =3D &stream->chain->prio; + vdev->queue =3D &queue->queue; + vdev->lock =3D &queue->mutex; if (type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT) vdev->vfl_dir =3D VFL_DIR_TX; else @@ -2399,8 +2375,8 @@ static int __uvc_resume(struct usb_interface *intf, i= nt reset) if (stream->intf =3D=3D intf) { ret =3D uvc_video_resume(stream, reset); if (ret < 0) - uvc_queue_streamoff(&stream->queue, - stream->queue.queue.type); + vb2_streamoff(&stream->queue.queue, + stream->queue.queue.type); return ret; } } diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/u= vc_metadata.c index 82de7781f5b6b70c5ba16bcba9e0741231231904..d3aab22f91cea21aefc56409924= dfa1451aec914 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -96,7 +96,7 @@ static int uvc_meta_v4l2_set_format(struct file *file, vo= id *fh, */ mutex_lock(&stream->mutex); =20 - if (uvc_queue_allocated(&stream->queue)) + if (vb2_is_busy(&stream->meta.queue.queue)) ret =3D -EBUSY; else stream->meta.format =3D fmt->dataformat; @@ -164,12 +164,6 @@ int uvc_meta_register(struct uvc_streaming *stream) =20 stream->meta.format =3D V4L2_META_FMT_UVC; =20 - /* - * The video interface queue uses manual locking and thus does not set - * the queue pointer. Set it manually here. - */ - vdev->queue =3D &queue->queue; - return uvc_register_video_device(dev, stream, vdev, queue, V4L2_BUF_TYPE_META_CAPTURE, &uvc_meta_fops, &uvc_meta_ioctl_ops); diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 2ee142621042167c2587b6a6fdd51c1a46d31c11..72c5494dee9f46ff61072e7d293= bfaddda40e615 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -242,153 +242,10 @@ int uvc_queue_init(struct uvc_video_queue *queue, en= um v4l2_buf_type type) return 0; } =20 -void uvc_queue_release(struct uvc_video_queue *queue) -{ - mutex_lock(&queue->mutex); - vb2_queue_release(&queue->queue); - mutex_unlock(&queue->mutex); -} - -/* -----------------------------------------------------------------------= ------ - * V4L2 queue operations - */ - -int uvc_request_buffers(struct uvc_video_queue *queue, - struct v4l2_requestbuffers *rb) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_reqbufs(&queue->queue, rb); - mutex_unlock(&queue->mutex); - - return ret ? ret : rb->count; -} - -int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *bu= f) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_querybuf(&queue->queue, buf); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_create_buffers(struct uvc_video_queue *queue, - struct v4l2_create_buffers *cb) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_create_bufs(&queue->queue, cb); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_buffer(struct uvc_video_queue *queue, - struct media_device *mdev, struct v4l2_buffer *buf) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_qbuf(&queue->queue, mdev, buf); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_export_buffer(struct uvc_video_queue *queue, - struct v4l2_exportbuffer *exp) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_expbuf(&queue->queue, exp); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *= buf, - int nonblocking) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_dqbuf(&queue->queue, buf, nonblocking); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type t= ype) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_streamon(&queue->queue, type); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type = type) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_streamoff(&queue->queue, type); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *v= ma) -{ - return vb2_mmap(&queue->queue, vma); -} - -#ifndef CONFIG_MMU -unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, - unsigned long pgoff) -{ - return vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0); -} -#endif - -__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, - poll_table *wait) -{ - __poll_t ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_poll(&queue->queue, file, wait); - mutex_unlock(&queue->mutex); - - return ret; -} - /* -----------------------------------------------------------------------= ------ * */ =20 -/* - * Check if buffers have been allocated. - */ -int uvc_queue_allocated(struct uvc_video_queue *queue) -{ - int allocated; - - mutex_lock(&queue->mutex); - allocated =3D vb2_is_busy(&queue->queue); - mutex_unlock(&queue->mutex); - - return allocated; -} - /* * Cancel the video buffers queue. * diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 862b4e34e5b629cf324479a9bb59ebe8784ccd5d..7a5ecbefa32c0a6b74c85d7f77a= 25b433598471e 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -47,8 +47,6 @@ void uvc_pm_put(struct uvc_device *dev) usb_autopm_put_interface(dev->intf); } =20 -static int uvc_acquire_privileges(struct uvc_fh *handle); - static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain, struct uvc_control_mapping *map, const struct uvc_xu_control_mapping *xmap) @@ -436,10 +434,6 @@ static int uvc_ioctl_s_fmt(struct file *file, void *fh, const struct uvc_frame *frame; int ret; =20 - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - if (fmt->type !=3D stream->type) return -EINVAL; =20 @@ -448,8 +442,7 @@ static int uvc_ioctl_s_fmt(struct file *file, void *fh, return ret; =20 mutex_lock(&stream->mutex); - - if (uvc_queue_allocated(&stream->queue)) { + if (vb2_is_busy(&stream->queue.queue)) { ret =3D -EBUSY; goto done; } @@ -513,10 +506,6 @@ static int uvc_ioctl_s_parm(struct file *file, void *f= h, unsigned int i; int ret; =20 - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - if (parm->type !=3D stream->type) return -EINVAL; =20 @@ -593,63 +582,6 @@ static int uvc_ioctl_s_parm(struct file *file, void *f= h, return 0; } =20 -/* ------------------------------------------------------------------------ - * Privilege management - */ - -/* - * Privilege management is the multiple-open implementation basis. The cur= rent - * implementation is completely transparent for the end-user and doesn't - * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioc= tls. - * Those ioctls enable finer control on the device (by making possible for= a - * user to request exclusive access to a device), but are not mature yet. - * Switching to the V4L2 priority mechanism might be considered in the fut= ure - * if this situation changes. - * - * Each open instance of a UVC device can either be in a privileged or - * unprivileged state. Only a single instance can be in a privileged state= at - * a given time. Trying to perform an operation that requires privileges w= ill - * automatically acquire the required privileges if possible, or return -E= BUSY - * otherwise. Privileges are dismissed when closing the instance or when - * freeing the video buffers using VIDIOC_REQBUFS. - * - * Operations that require privileges are: - * - * - VIDIOC_S_INPUT - * - VIDIOC_S_PARM - * - VIDIOC_S_FMT - * - VIDIOC_CREATE_BUFS - * - VIDIOC_REQBUFS - */ -static int uvc_acquire_privileges(struct uvc_fh *handle) -{ - /* Always succeed if the handle is already privileged. */ - if (handle->state =3D=3D UVC_HANDLE_ACTIVE) - return 0; - - /* Check if the device already has a privileged handle. */ - if (atomic_inc_return(&handle->stream->active) !=3D 1) { - atomic_dec(&handle->stream->active); - return -EBUSY; - } - - handle->state =3D UVC_HANDLE_ACTIVE; - return 0; -} - -static void uvc_dismiss_privileges(struct uvc_fh *handle) -{ - if (handle->state =3D=3D UVC_HANDLE_ACTIVE) - atomic_dec(&handle->stream->active); - - handle->state =3D UVC_HANDLE_PASSIVE; -} - -static int uvc_has_privileges(struct uvc_fh *handle) -{ - return handle->state =3D=3D UVC_HANDLE_ACTIVE; -} - /* ------------------------------------------------------------------------ * V4L2 file operations */ @@ -671,7 +603,6 @@ static int uvc_v4l2_open(struct file *file) v4l2_fh_add(&handle->vfh); handle->chain =3D stream->chain; handle->stream =3D stream; - handle->state =3D UVC_HANDLE_PASSIVE; file->private_data =3D handle; =20 return 0; @@ -686,18 +617,11 @@ static int uvc_v4l2_release(struct file *file) =20 uvc_ctrl_cleanup_fh(handle); =20 - /* Only free resources if this is a privileged handle. */ - if (uvc_has_privileges(handle)) - uvc_queue_release(&stream->queue); - if (handle->is_streaming) uvc_pm_put(stream->dev); =20 /* Release the file handle. */ - uvc_dismiss_privileges(handle); - v4l2_fh_del(&handle->vfh); - v4l2_fh_exit(&handle->vfh); - kfree(handle); + vb2_fop_release(file); file->private_data =3D NULL; =20 return 0; @@ -753,91 +677,6 @@ static int uvc_ioctl_try_fmt(struct file *file, void *= fh, return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); } =20 -static int uvc_ioctl_reqbufs(struct file *file, void *fh, - struct v4l2_requestbuffers *rb) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - mutex_lock(&stream->mutex); - ret =3D uvc_request_buffers(&stream->queue, rb); - mutex_unlock(&stream->mutex); - if (ret < 0) - return ret; - - if (ret =3D=3D 0) - uvc_dismiss_privileges(handle); - - return 0; -} - -static int uvc_ioctl_querybuf(struct file *file, void *fh, - struct v4l2_buffer *buf) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_query_buffer(&stream->queue, buf); -} - -static int uvc_ioctl_qbuf(struct file *file, void *fh, struct v4l2_buffer = *buf) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_queue_buffer(&stream->queue, - stream->vdev.v4l2_dev->mdev, buf); -} - -static int uvc_ioctl_expbuf(struct file *file, void *fh, - struct v4l2_exportbuffer *exp) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_export_buffer(&stream->queue, exp); -} - -static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer= *buf) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_dequeue_buffer(&stream->queue, buf, - file->f_flags & O_NONBLOCK); -} - -static int uvc_ioctl_create_bufs(struct file *file, void *fh, - struct v4l2_create_buffers *cb) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_create_buffers(&stream->queue, cb); -} - static int uvc_ioctl_streamon(struct file *file, void *fh, enum v4l2_buf_type type) { @@ -845,11 +684,6 @@ static int uvc_ioctl_streamon(struct file *file, void = *fh, struct uvc_streaming *stream =3D handle->stream; int ret; =20 - if (!uvc_has_privileges(handle)) - return -EBUSY; - - guard(mutex)(&stream->mutex); - if (handle->is_streaming) return 0; =20 @@ -857,7 +691,7 @@ static int uvc_ioctl_streamon(struct file *file, void *= fh, if (ret) return ret; =20 - ret =3D uvc_queue_streamon(&stream->queue, type); + ret =3D vb2_ioctl_streamon(file, fh, type); if (ret) { uvc_pm_put(stream->dev); return ret; @@ -873,13 +707,12 @@ static int uvc_ioctl_streamoff(struct file *file, voi= d *fh, { struct uvc_fh *handle =3D fh; struct uvc_streaming *stream =3D handle->stream; + int ret; =20 - if (!uvc_has_privileges(handle)) - return -EBUSY; - - guard(mutex)(&stream->mutex); + ret =3D vb2_ioctl_streamoff(file, fh, type); + if (ret) + return ret; =20 - uvc_queue_streamoff(&stream->queue, type); if (handle->is_streaming) { handle->is_streaming =3D false; uvc_pm_put(stream->dev); @@ -962,13 +795,13 @@ static int uvc_ioctl_g_input(struct file *file, void = *fh, unsigned int *input) static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int inp= ut) { struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; struct uvc_video_chain *chain =3D handle->chain; u8 *buf; int ret; =20 - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; + if (vb2_is_busy(&stream->queue.queue)) + return -EBUSY; =20 if (chain->selector =3D=3D NULL || (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { @@ -1471,50 +1304,6 @@ static long uvc_v4l2_unlocked_ioctl(struct file *fil= e, return ret; } =20 -static ssize_t uvc_v4l2_read(struct file *file, char __user *data, - size_t count, loff_t *ppos) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s: not implemented\n", __func__); - return -EINVAL; -} - -static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_mmap(&stream->queue, vma); -} - -static __poll_t uvc_v4l2_poll(struct file *file, poll_table *wait) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_poll(&stream->queue, file, wait); -} - -#ifndef CONFIG_MMU -static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, - unsigned long addr, unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_get_unmapped_area(&stream->queue, pgoff); -} -#endif - const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_g_fmt_vid_cap =3D uvc_ioctl_g_fmt, .vidioc_g_fmt_vid_out =3D uvc_ioctl_g_fmt, @@ -1527,12 +1316,13 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_enum_fmt_vid_out =3D uvc_ioctl_enum_fmt, .vidioc_try_fmt_vid_cap =3D uvc_ioctl_try_fmt, .vidioc_try_fmt_vid_out =3D uvc_ioctl_try_fmt, - .vidioc_reqbufs =3D uvc_ioctl_reqbufs, - .vidioc_querybuf =3D uvc_ioctl_querybuf, - .vidioc_qbuf =3D uvc_ioctl_qbuf, - .vidioc_expbuf =3D uvc_ioctl_expbuf, - .vidioc_dqbuf =3D uvc_ioctl_dqbuf, - .vidioc_create_bufs =3D uvc_ioctl_create_bufs, + .vidioc_reqbufs =3D vb2_ioctl_reqbufs, + .vidioc_querybuf =3D vb2_ioctl_querybuf, + .vidioc_prepare_buf =3D vb2_ioctl_prepare_buf, + .vidioc_qbuf =3D vb2_ioctl_qbuf, + .vidioc_expbuf =3D vb2_ioctl_expbuf, + .vidioc_dqbuf =3D vb2_ioctl_dqbuf, + .vidioc_create_bufs =3D vb2_ioctl_create_bufs, .vidioc_streamon =3D uvc_ioctl_streamon, .vidioc_streamoff =3D uvc_ioctl_streamoff, .vidioc_enum_input =3D uvc_ioctl_enum_input, @@ -1559,11 +1349,10 @@ const struct v4l2_file_operations uvc_fops =3D { #ifdef CONFIG_COMPAT .compat_ioctl32 =3D uvc_v4l2_compat_ioctl32, #endif - .read =3D uvc_v4l2_read, - .mmap =3D uvc_v4l2_mmap, - .poll =3D uvc_v4l2_poll, + .mmap =3D vb2_fop_mmap, + .poll =3D vb2_fop_poll, #ifndef CONFIG_MMU - .get_unmapped_area =3D uvc_v4l2_get_unmapped_area, + .get_unmapped_area =3D vb2_fop_get_unmapped_area, #endif }; =20 diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index b9f8eb62ba1d82ea7788cf6c10cc838a429dbc9e..3ddbf065a2cbae40ee48cb06f84= ca8f0052990c4 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -326,7 +326,10 @@ struct uvc_buffer { =20 struct uvc_video_queue { struct vb2_queue queue; - struct mutex mutex; /* Protects queue */ + struct mutex mutex; /* + * Serializes vb2_queue and + * fops + */ =20 unsigned int flags; unsigned int buf_used; @@ -349,7 +352,6 @@ struct uvc_video_chain { * uvc_fh.pending_async_ctrls */ =20 - struct v4l2_prio_state prio; /* V4L2 priority state */ u32 caps; /* V4L2 chain-wide caps */ u8 ctrl_class_bitmap; /* Bitmap of valid classes */ }; @@ -619,16 +621,10 @@ struct uvc_device { struct uvc_entity *gpio_unit; }; =20 -enum uvc_handle_state { - UVC_HANDLE_PASSIVE =3D 0, - UVC_HANDLE_ACTIVE =3D 1, -}; - struct uvc_fh { struct v4l2_fh vfh; struct uvc_video_chain *chain; struct uvc_streaming *stream; - enum uvc_handle_state state; unsigned int pending_async_ctrls; bool is_streaming; }; @@ -687,36 +683,11 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device= *dev, int id); =20 /* Video buffers queue management. */ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type); -void uvc_queue_release(struct uvc_video_queue *queue); -int uvc_request_buffers(struct uvc_video_queue *queue, - struct v4l2_requestbuffers *rb); -int uvc_query_buffer(struct uvc_video_queue *queue, - struct v4l2_buffer *v4l2_buf); -int uvc_create_buffers(struct uvc_video_queue *queue, - struct v4l2_create_buffers *v4l2_cb); -int uvc_queue_buffer(struct uvc_video_queue *queue, - struct media_device *mdev, - struct v4l2_buffer *v4l2_buf); -int uvc_export_buffer(struct uvc_video_queue *queue, - struct v4l2_exportbuffer *exp); -int uvc_dequeue_buffer(struct uvc_video_queue *queue, - struct v4l2_buffer *v4l2_buf, int nonblocking); -int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type t= ype); -int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type = type); void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf); struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *qu= eue); void uvc_queue_buffer_release(struct uvc_buffer *buf); -int uvc_queue_mmap(struct uvc_video_queue *queue, - struct vm_area_struct *vma); -__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, - poll_table *wait); -#ifndef CONFIG_MMU -unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, - unsigned long pgoff); -#endif -int uvc_queue_allocated(struct uvc_video_queue *queue); static inline int uvc_queue_streaming(struct uvc_video_queue *queue) { return vb2_is_streaming(&queue->queue); --=20 2.49.0.1266.g31b7d2e469-goog From nobody Wed Feb 11 08:13:47 2026 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC6BC21FF22 for ; Mon, 2 Jun 2025 12:59:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748869156; cv=none; b=FeiAAqMGOXnZxQVONfXW3qUOzFCXulyUBPaK/7Xnq1HqTvV7qktZ3yqU1wbcrUr2HyMRZNzX9zN6X5hgMF63UOPEvDMfdBxu8Q+cXTjHA+yLThChFykLGKsfvR67U0OFBhvjbAaxjKbGP5DL7yJGXcOHaHdwBVTj+4LNi4NrCdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748869156; c=relaxed/simple; bh=FGQS/DPv/UfUtSlsCQ6Vvh4EyONjnUMmQIJCXsOyPcw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PfEmKQcHQ/kBTNjRhmRq1RLRbMHHHTM85ca8e3cC26OKF2n3TIbHnAD21sQMaC/Mfa/GLmkIIxELANz6vqWP9C3hPv30a7MrUGGAvtW/UuOMuKFi4rmGfCCpIKCbpp5EAbSNsWKzMFjq8VNvBAQb40FBMsACNTLooqAuc+1nJ7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=B3myRb9y; arc=none smtp.client-ip=209.85.167.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="B3myRb9y" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-54acc0cd458so5398761e87.0 for ; Mon, 02 Jun 2025 05:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748869153; x=1749473953; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ToC+Tc0dmXcPfX/TTDxCxEcN/r59cEY9PxQCySvBfGI=; b=B3myRb9ybenA/oQbk7UzqtOVkZbBywmaWMxqBNc4aXFLXkob9QXrNlGcPUt9vmjdML I58F8eA7z/6SXPKurqtdSziOqbp56/bfBU1gVuPWAYV6jotVoRcfQk9l5Agbn2ClIN1D DXIuCFf/TYnRnKe8bo65C9BoLPV0zPK8ltf1k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748869153; x=1749473953; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ToC+Tc0dmXcPfX/TTDxCxEcN/r59cEY9PxQCySvBfGI=; b=eMGfdzldO6uGZ8DQA5yUdCcxl5N5fcjCoIhiLhzTRDyLIH2rwy786tGYQ7T/7HvBug LtrSRMxCN53LS6P6uVU1gYKCFNAWMbGsSyEwWNJl8g2buvPGqdqygcNnCPiiktZQbCF5 s9rLT17TcpL+4Fr5y+h8MvDDjkPuEcPvpEpKhsu7VwUHxbX5p9YnUJY5skTW9pBCv741 PvUlODBhNy/EiXZLUec3TYlqxmTFMvqgvHg26g0vOa5nktTd4K+2xggczvsSIe+CFBO0 dSFdUjJ0G6i2oVdsiW8FKvPWkKmAxv/ba0xYh9AbX45yZhyt4WgoDQeNI7Ze3VzFC843 KmZQ== X-Forwarded-Encrypted: i=1; AJvYcCUhOSL4TGMjdTmUkGyKw7lof8P7BTgvBGd+JXRTLVKNsmyebvUZtLQqQXcHSowI4ynlBjIn+2cQX3h8KRI=@vger.kernel.org X-Gm-Message-State: AOJu0YyO1trTdTACEUV8Z8sUDfiOlYzzrZBjNGETRUwCH6rp8JishLbg a1OWNRgUzBnKpedbcxxa51NqF/iFVpk6c4oyOb9cQRWsFqItPtgZ/zfLunwALQTkrA== X-Gm-Gg: ASbGncu4J9/ToyZNRxBWLIBhU9LM7918ElzEtCRk4D4MDdWvYLIh13tIhba0PfI7p6L 2DKfIWzr1ujiAUjv5bAEdWga769kp6ztUX5gdbSN8bXTecWRZUH60JdeXbV2LKjliW6l4/1sekv wgqsXtsNa3PBbquFnsRDa45pJZ8bDfYQOBaaS12LhA3pM7Lk3vzAzQ9eviE3q7T3lK0hMvclxtr p0Ew599iy78FQNdUftwk1Usc00vs5nYIE36nVzCSEQmqCFmYnmNm7oB8V/SjHb/1GgmJ6dEMte0 ZGNSborDLqX5m7wdNS+JzmEy/fWrUz3U9H0QSfnMtuWH6yX/2/UPNXhuhisqz8hkzuVix1G/4Yq r9FL7DZI7JYNnreY40YaYzIyoDg== X-Google-Smtp-Source: AGHT+IFdCNN4YdbC1Vdbn+B7IdgBUiXxK5TObG5L1wn0bDYUQJ6e5TVqvDwWnb2mlTLtx31JnwUl8Q== X-Received: by 2002:a05:6512:1318:b0:553:3332:b652 with SMTP id 2adb3069b0e04-5533b8fcdf3mr3719422e87.23.1748869152987; Mon, 02 Jun 2025 05:59:12 -0700 (PDT) Received: from ribalda.c.googlers.com (90.52.88.34.bc.googleusercontent.com. [34.88.52.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-553379377a8sm1601140e87.239.2025.06.02.05.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 05:59:11 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 12:59:04 +0000 Subject: [PATCH v2 3/3] media: uvcvideo: Remove stream->is_streaming field Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250602-uvc-fop-v2-3-508a293eae81@chromium.org> References: <20250602-uvc-fop-v2-0-508a293eae81@chromium.org> In-Reply-To: <20250602-uvc-fop-v2-0-508a293eae81@chromium.org> To: Laurent Pinchart , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 The is_streaming field is used by modular PM to know if the device is currently streaming or not. With the transition to vb2 and fop helpers, we can use vb2 functions for the same functionality. The great benefit is that vb2 already takes track of the streaming state for us. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_queue.c | 11 ++++++++- drivers/media/usb/uvc/uvc_v4l2.c | 51 ++---------------------------------= ---- drivers/media/usb/uvc/uvcvideo.h | 1 - 3 files changed, 12 insertions(+), 51 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 72c5494dee9f46ff61072e7d293bfaddda40e615..dff93bec204428b8aebc09332e0= 322fa68823fa4 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -165,12 +165,18 @@ static int uvc_start_streaming(struct vb2_queue *vq, = unsigned int count) =20 lockdep_assert_irqs_enabled(); =20 + ret =3D uvc_pm_get(stream->dev); + if (ret) + return ret; + queue->buf_used =3D 0; =20 ret =3D uvc_video_start_streaming(stream); if (ret =3D=3D 0) return 0; =20 + uvc_pm_put(stream->dev); + spin_lock_irq(&queue->irqlock); uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED); spin_unlock_irq(&queue->irqlock); @@ -181,11 +187,14 @@ static int uvc_start_streaming(struct vb2_queue *vq, = unsigned int count) static void uvc_stop_streaming(struct vb2_queue *vq) { struct uvc_video_queue *queue =3D vb2_get_drv_priv(vq); + struct uvc_streaming *stream =3D uvc_queue_to_stream(queue); =20 lockdep_assert_irqs_enabled(); =20 - if (vq->type !=3D V4L2_BUF_TYPE_META_CAPTURE) + if (vq->type !=3D V4L2_BUF_TYPE_META_CAPTURE) { + uvc_pm_put(stream->dev); uvc_video_stop_streaming(uvc_queue_to_stream(queue)); + } =20 spin_lock_irq(&queue->irqlock); uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 7a5ecbefa32c0a6b74c85d7f77a25b433598471e..d4bee0d4334b764c0cf02363b57= 3b55fb44eb228 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -617,9 +617,6 @@ static int uvc_v4l2_release(struct file *file) =20 uvc_ctrl_cleanup_fh(handle); =20 - if (handle->is_streaming) - uvc_pm_put(stream->dev); - /* Release the file handle. */ vb2_fop_release(file); file->private_data =3D NULL; @@ -677,50 +674,6 @@ static int uvc_ioctl_try_fmt(struct file *file, void *= fh, return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); } =20 -static int uvc_ioctl_streamon(struct file *file, void *fh, - enum v4l2_buf_type type) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - if (handle->is_streaming) - return 0; - - ret =3D uvc_pm_get(stream->dev); - if (ret) - return ret; - - ret =3D vb2_ioctl_streamon(file, fh, type); - if (ret) { - uvc_pm_put(stream->dev); - return ret; - } - - handle->is_streaming =3D true; - - return 0; -} - -static int uvc_ioctl_streamoff(struct file *file, void *fh, - enum v4l2_buf_type type) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D vb2_ioctl_streamoff(file, fh, type); - if (ret) - return ret; - - if (handle->is_streaming) { - handle->is_streaming =3D false; - uvc_pm_put(stream->dev); - } - - return 0; -} - static int uvc_ioctl_enum_input(struct file *file, void *fh, struct v4l2_input *input) { @@ -1323,8 +1276,8 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_expbuf =3D vb2_ioctl_expbuf, .vidioc_dqbuf =3D vb2_ioctl_dqbuf, .vidioc_create_bufs =3D vb2_ioctl_create_bufs, - .vidioc_streamon =3D uvc_ioctl_streamon, - .vidioc_streamoff =3D uvc_ioctl_streamoff, + .vidioc_streamon =3D vb2_ioctl_streamon, + .vidioc_streamoff =3D vb2_ioctl_streamoff, .vidioc_enum_input =3D uvc_ioctl_enum_input, .vidioc_g_input =3D uvc_ioctl_g_input, .vidioc_s_input =3D uvc_ioctl_s_input, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 3ddbf065a2cbae40ee48cb06f84ca8f0052990c4..f895f690f7cdc1af942d5f3a5f1= 0e9dd1c956a35 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -626,7 +626,6 @@ struct uvc_fh { struct uvc_video_chain *chain; struct uvc_streaming *stream; unsigned int pending_async_ctrls; - bool is_streaming; }; =20 /* ------------------------------------------------------------------------ --=20 2.49.0.1266.g31b7d2e469-goog