From nobody Fri Dec 19 13:06:37 2025 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 60C1918E050 for ; Thu, 22 May 2025 17:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747936732; cv=none; b=reN6X4yA8/1jGF752RSL+IgiJjV316AO5Kv4N8SPR463cx/9RXoGXICCFVfYFgGvf8vX8O/3WNguIgg+WLT9QGT6xpzCmq3rzeORhXLf+fJyS8Rra1wEP/4wKgG0DB/Hxw1iu8UrTe1sXW9mFAjW/y/b9UYlpSi1v+y5ShdRl6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747936732; c=relaxed/simple; bh=QcG3SUn+imyDe25SjF5FB7e+cnIdZBxIsQWIVlcGZhU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SO0mjGbZvlY9M0W4f7VKWRpGVRzfAqcnDC0AnTKK8dmjlr+JLS9s/VLnn04mo5BWKuL50ThpRF/pSA7hBXS4+huZqn1/Mm6hjPswp4TTExAzQFtE01W0CeP21S2l5p5E9UTiH+p/xgPEe8RMnezaz7DQNNSPlQM8RTeZyIRccVA= 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=J9oaSQmC; arc=none smtp.client-ip=209.85.167.53 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="J9oaSQmC" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-551ed0038a0so6723594e87.2 for ; Thu, 22 May 2025 10:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1747936728; x=1748541528; 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=Eq6hiXCLW/5+B6e/F9cx3BxUfpM989hM42lId2PS3xs=; b=J9oaSQmC5nZ644gvntnIywShg3iVyL5HLmt3gVNNMEPoRpg0yTjvPaaJVG9dERZ0NW mxp4J0WyREo5QI6Q2ifvWZCoJxVV8p6w20XV2Ti7x5EJT5Y1wXHp9gWuBZKBgjJnxP2X Z3/SAHcD9yIt070L3zb7wNsFO8tBVS88nVihg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747936728; x=1748541528; 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=Eq6hiXCLW/5+B6e/F9cx3BxUfpM989hM42lId2PS3xs=; b=qRssSPHoR4amQrL6XThw8WUamIVeR4hphHZC1v3uh/alH56xcs/J9Atmi7OozMiKpd RSjG6Ekc7rP2Fgi6ysqryQKyqdl5DSpAePDhAFGVtBdv7CTflCT+7c5aXm1NavVHLe5G oWmPWuI+3BBSPiVWrrMsGf5nxB9WO8/TBgc3oG5+aZwHBCa4tAASm8qq8JHIk/tc4hU+ QMQ944z7rJ7HR60VOmlJOuWJ3PkF7YMNNk8SjLsEYXEFD4GGTZ+zzZ/2YVimK5N8n/px G38gNOuC2EnSqNe8h0PFFg+X+VlNQDCoBK8GT3qcuV59yx1rZdFUpdNX1VpCNS/6DUjZ tfwg== X-Forwarded-Encrypted: i=1; AJvYcCUpXyipWUEv8LvWgxJCVX+RAj+TY/lfTd7xvvfgOxdtm/aWfoyGuLuqD+EHND3KMFISqdb3RWKE0M/a2h8=@vger.kernel.org X-Gm-Message-State: AOJu0YzRrCPZgM9qaCUo8+amhWjgfLhIQEEr3VkhLanHUblhB9m2M64u OP165XMCq9xmfq4A3QA3DRG3zgG8CKZxl90/by++ySmfm6kFgENxGWX5ACK7U0DT7A== X-Gm-Gg: ASbGnct4VizooXyUQFALKLGz9kOfLz7aI6IwwBpguOVv5GKjeS5IARH/4gLn9kfutZB dBGqwHVGmpENq4rJazUzUOYQOaZHZstSA+2WRZXcjHz5U4xnpQvnU6Kj1hyA1gQwFUMGRZQZoWR v0A1YYoMudi20igcJn0EDiige6LIUg9j1+cvgrw52jJOWtb5DhfTR4KPbi4JljEGh38PhjPpoK/ tVElQREeMDqmGD7WKUDSL+OOIxQhsoQdUoiaMr9b+1+rD0/0+gXqK0yEV3FbXWws8Slj0aTHlfj zXAvmh+Rj+BPGyRrItC0WnIdKbXhzGuxDuWEiX43pkEqtLSgOWOqZDwM8KUR0KEXNrhTDx/JjrA jVTIKBLRpGJ4cZXFzN0ktXtoldQ== X-Google-Smtp-Source: AGHT+IHtz+09CN3dUILoE5bvCx936+0JcoTZUsSxmv1K+SqjZ4Dfvhh4AkX2J/5LPVoG9ByQqGjbnQ== X-Received: by 2002:a05:6512:39c9:b0:545:1104:617d with SMTP id 2adb3069b0e04-550e7195516mr10182880e87.11.1747936728367; Thu, 22 May 2025 10:58:48 -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-550e703e858sm3483992e87.227.2025.05.22.10.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 May 2025 10:58:48 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 22 May 2025 17:58:46 +0000 Subject: [PATCH 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: <20250522-uvc-fop-v1-1-3bfe7a00f31d@chromium.org> References: <20250522-uvc-fop-v1-0-3bfe7a00f31d@chromium.org> In-Reply-To: <20250522-uvc-fop-v1-0-3bfe7a00f31d@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 Do uvc_pm_get before we call uvc_queue_streamon. Although the current code is correct, uvc_ioctl_streamon is allways called after uvc_pm_get, this change makes the code more resiliant to future changes. Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Reviewed-by: Hans Verkuil Reviewed-by: Laurent Pinchart --- 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.1151.ga128411c76-goog From nobody Fri Dec 19 13:06:37 2025 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 F0F161A315A for ; Thu, 22 May 2025 17:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747936735; cv=none; b=H5kyP0QS9OxGwjlS/Xxsft7gdv2599bUWwMBoEnP/kFMH7nXluUe+7CmdxdTRMofTm/duZazLK15Di6thJ3aTPJoFBKdqOScA5FHv/4wnj88Nug9qmcYWG5yXxKbApeu6wV+Wp3avMRViWg6VU87C9isF89ZWsepRtCirYe0S2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747936735; c=relaxed/simple; bh=Hqovwy3tLMvNqmQT71P3dSQeOq2Ze+lyDqLbqaDif94=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fZGOmCxSxLnumHyrF81Aq43mbWc9IbmSumVQlc9SQVWXIoi5xZcqup1yx25PynRYe6VpCRKD+UhbeTCkjO4o750gy0bec5xmbTxpzxEyB6rvl1B1q3su7srXEO+HlyvYcITJ3YCjsTgKbmd+cf0qCU5BHvbsP5HDnMmXMXHQvG4= 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=ECZnnmUL; arc=none smtp.client-ip=209.85.167.50 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="ECZnnmUL" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-551fc6d4a76so4376106e87.0 for ; Thu, 22 May 2025 10:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1747936729; x=1748541529; 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=9dQUTZ31D0zh+zulUyWmSUXmj3c3OqU40QtL4roneXY=; b=ECZnnmULMY5kOXMRKEOgQRTuCq+/sTE/QTvKXB4+HE7GhSYmvRVV5hkmnCUilG71Wc iJTh0T+UZ7h7LuklIEKokyq3R4+3eDBj4koRKqr5WbHaV63bvF5E11pM1OiIruNyIdzf 5beKyxNgIkjscr7ojRouN34R6Hfuf0nEKLfnQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747936729; x=1748541529; 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=9dQUTZ31D0zh+zulUyWmSUXmj3c3OqU40QtL4roneXY=; b=Znac5sv8+NQ8ZVFRWTJ7t+swf7baP+eCegsYYZq6XeGpTqIVzjJVz9IIcki7xG8mWv HoOu0dCP9xcq2TODbpebPzS5MlP7DBrt5vof/RHdjRLwr3EToPvGmhIevG2yhfra55M0 EbJB3XZh4OENNrbcEHl80Pti8nW5qNDI1RrOwCyIWE3GQ1obPv9glh+5Jvk7w52TcxZM IsRmRDXU0ixoian6IB/ejm58zaKmOqOzjcU9wf6TOc+0GBv+apUKeJC2RfadQsTJB1Dz F6DVTOJ8e9H0ZpTCZTi7iz3SOYp+bJrRhdgDsZACnGgAFQMNzMJVzcQR4xD9dT6u/miY +D/w== X-Forwarded-Encrypted: i=1; AJvYcCWyFZSB832Efp/9m7YbZObYZzcgO9WfA4s16J6c1D3DxOopi9sPdxmL38RBUudrH/3P6aK7O3UMnFGkv8I=@vger.kernel.org X-Gm-Message-State: AOJu0Yyje0RW60KksZ2PWi+qD2PN62stf//F2YtiFpzQEpzv/gU9Y93V 8pryiRRSdNOgmmaEuqXGiKOYpzBRppfytjwOfMBKTtfAsdbnue+ax0+p76Z/GA3KhQ== X-Gm-Gg: ASbGncuJLHvvzDmK3jaqbVoIaQ2jpJQoEBzBqlISNcUrHEhvS6l0r1/iVMADdxO7JZ1 IkUBs6hFrRn6XAQspxtRkU/8drAO2CNdTL94FxgZpxK2k7LnOUHnf57RIwcECavRp2rLrJ0wp4U 5C+RdloUOtc4Yd0sefXU51kKQVVgV6mVpHPzWGoHA7PG1ySysqOJX++l/2mrkDub+BMRCdb3GyU Ro/z1hGW6+Wwd/KZERKg3okvApfpdZEws3UbYV85JRUsX/B6xHLn0CdQrguDCKCdMP2az0Y54q0 zqCRZ+dKXlX0RHSmHjEnJKqT3DWsPWNkU1Okh3DeoaFvJ+giGN5gGoLdzdYxrol1gbduzrTxTGo peCsge9zWA/XGNSA6exlhL/aPsQ== X-Google-Smtp-Source: AGHT+IEc978JlOlQfR0ep4DR6VFUm7Powq0ZltTYBG4OhNAbP6HrPN/YqTlC5BW2uoOXlcoYFvuACw== X-Received: by 2002:a05:6512:4406:b0:550:e3a0:19d4 with SMTP id 2adb3069b0e04-550e97a40damr6185697e87.19.1747936728889; Thu, 22 May 2025 10:58:48 -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-550e703e858sm3483992e87.227.2025.05.22.10.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 May 2025 10:58:48 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 22 May 2025 17:58:47 +0000 Subject: [PATCH 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: <20250522-uvc-fop-v1-2-3bfe7a00f31d@chromium.org> References: <20250522-uvc-fop-v1-0-3bfe7a00f31d@chromium.org> In-Reply-To: <20250522-uvc-fop-v1-0-3bfe7a00f31d@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 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 boilerplatecode 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 gran exclusive ownership of the device. Signed-off-by: Hans Verkuil Co-developed-by: Ricardo Ribalda Signed-off-by: Ricardo Ribalda Reviewed-by: Hans Verkuil Reviewed-by: Hans de Goede --- 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.1151.ga128411c76-goog From nobody Fri Dec 19 13:06:37 2025 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 2DD071A3175 for ; Thu, 22 May 2025 17:58:50 +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=1747936733; cv=none; b=MHqIVZ+c/MNJ/bOhTYM9WKyTjs/9Fx9MmjwQyA0depJwyxwUAPN5l8Z5izAxt76fhZhomBCwQHMv8vgO4C/PHEX6Xh09/3I0XnCj1TOPRF6/TZq7yeNCt2nZ8w4bCyA+adptqQ5cAZ03RZVUkWbJ1VXSu7MB7feC6LHQlukPn4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747936733; c=relaxed/simple; bh=bydw5Ui1Tm31HV00k8hjsx9u+m7wpL+0gQpn2hpNiaY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Rtgcof5Ac73KrcX9MtVZIWc0UXAzLEMxi9khGLWW25wSFOFmLAub7a/VV/+mbnmyS6Xh9tbJhN84ET8Ya+Xi4KboxV3OEhlZnciBq3WW9bKtpzf0A4sbk2jCrV5IQXczo55DlOO2Xcsn7pjsfaNike4jhramDToi110p5F5fYiQ= 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=m7Zo6JR5; 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="m7Zo6JR5" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-551eb58b707so7351433e87.0 for ; Thu, 22 May 2025 10:58:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1747936729; x=1748541529; 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=e2ietCEWaMSFLfYqQUoQI2jJOy0qZzPyzPT/ShmHYYA=; b=m7Zo6JR5wnDeVYbQYBslCHS/SZ/rlaHxWQ4Irk04m5KnDD1nRRasEMQVUN0C70A8o2 rdp8bFLlCnI907fjAX+zUP6RLskaSp9SARmEZlwO5tyDggOIbWzVTsBUWi261AO2NB7z rYfKP3uAqMgykqrBVPDkuhkOQ8+MFd+TC4Tlg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747936729; x=1748541529; 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=e2ietCEWaMSFLfYqQUoQI2jJOy0qZzPyzPT/ShmHYYA=; b=Z/LZPROS5iU8wQxhdIwEYkAI/tzakaRACyv+Bm2ewIfub/v49rkduimTmPb/wXeQbz 0X8QyGt+ZQNteMeBlaMItnsdK67smYp7EJPcaNZEls9QDq7Ed+5HQybpAue3xNs4Hr1Y ZFZF6e4jopmGiOMWMgEZh3jTUcJvHpywD2UCXyDO6B6T5uG6YVTLAA3J8kKyEqJuchIT j13okMx8GR97ERDrHyDgFFfPqFymNftLhcaNe6ZykKLd7oXymWBJ3g9GtTxCtINr9EJ3 h3/nxC2OCMVGL3cB1Ua1TjyX0z1if3nG3u7kP4iVFG28BHKFLygagiUVbs8zykrFlGON 9J9Q== X-Forwarded-Encrypted: i=1; AJvYcCWYXLDCo01JwJ+z3tP7d6qdq3PAA3f+sGD3zXewigTEnsoTJ1nOAgeR2SPrX+PpKgcI+FxgMXkHeK7tya8=@vger.kernel.org X-Gm-Message-State: AOJu0Yxf718h+/3ayF4eVTI7V8G0T7zz8SSF9WxBaX3jP33iIK6lmpCx Hx1jnMt5RD9/LuCzfvYHNlYm1BsMAYnqRCkLN0vbzqRI6j1aSk/wG7MMwN0Kz15jCw== X-Gm-Gg: ASbGnctKsKo2yRHsuzvavtiLgSq5q1QuYD9eHNIoNfPI6kMDNe3nPMkCT5fBpImtgrg f35+xS+Z/vCllpv4YzHpvOVjYn25RkcnVfEunjPH14Fj1fbtBZ9SJLm5btLT69GEbGPDDvAxBL0 BMik6j8nNJnN0zgS1OB2zvaM5eDMKyjo0h1ke8YzV+D/VfSrhNyUoGK1sWhX3Ml/a603AC2eq1p PcFDP0B8leJ7F2/GKQkX23DTlSfVCQJDC+Vr8U/Cmw8GhjM4duFie+v1gRCI45EU7GPCKcwKZLW mr51UdyJRhwz6K3PAp6MihuGRpC3PSiolrZ7CYoR4tjowedBGWqIx1G02KGXYEqqgsIXjxZRMy2 NK19EVWBZNWGlra2qc06tB8kXGPIsipUd2P75 X-Google-Smtp-Source: AGHT+IFQHiACQws5UAdZS7de+bdyVNoxTk6zhZQaW3UjcwLI08Kw75LBltk94ixJi/18ILaVsZ5dGw== X-Received: by 2002:a05:6512:3f27:b0:551:f76c:59fb with SMTP id 2adb3069b0e04-551f76c5c68mr5405231e87.40.1747936729292; Thu, 22 May 2025 10:58:49 -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-550e703e858sm3483992e87.227.2025.05.22.10.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 May 2025 10:58:49 -0700 (PDT) From: Ricardo Ribalda Date: Thu, 22 May 2025 17:58:48 +0000 Subject: [PATCH 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: <20250522-uvc-fop-v1-3-3bfe7a00f31d@chromium.org> References: <20250522-uvc-fop-v1-0-3bfe7a00f31d@chromium.org> In-Reply-To: <20250522-uvc-fop-v1-0-3bfe7a00f31d@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. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 12 +++++------- drivers/media/usb/uvc/uvcvideo.h | 1 - 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 7a5ecbefa32c0a6b74c85d7f77a25b433598471e..51419f443f2c43dfd17a9782352= bd2cde1094732 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -617,7 +617,8 @@ static int uvc_v4l2_release(struct file *file) =20 uvc_ctrl_cleanup_fh(handle); =20 - if (handle->is_streaming) + if (stream->queue.queue.owner =3D=3D file->private_data && + uvc_queue_streaming(&stream->queue)) uvc_pm_put(stream->dev); =20 /* Release the file handle. */ @@ -684,7 +685,7 @@ static int uvc_ioctl_streamon(struct file *file, void *= fh, struct uvc_streaming *stream =3D handle->stream; int ret; =20 - if (handle->is_streaming) + if (uvc_queue_streaming(&stream->queue)) return 0; =20 ret =3D uvc_pm_get(stream->dev); @@ -697,8 +698,6 @@ static int uvc_ioctl_streamon(struct file *file, void *= fh, return ret; } =20 - handle->is_streaming =3D true; - return 0; } =20 @@ -707,16 +706,15 @@ static int uvc_ioctl_streamoff(struct file *file, voi= d *fh, { struct uvc_fh *handle =3D fh; struct uvc_streaming *stream =3D handle->stream; + bool was_streaming =3D uvc_queue_streaming(&stream->queue); int ret; =20 ret =3D vb2_ioctl_streamoff(file, fh, type); if (ret) return ret; =20 - if (handle->is_streaming) { - handle->is_streaming =3D false; + if (was_streaming) uvc_pm_put(stream->dev); - } =20 return 0; } 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.1151.ga128411c76-goog