From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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 36A761C1AAA for ; Tue, 1 Jul 2025 06:45:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352330; cv=none; b=gGRi2NasoE0PWuUTcLB+gjTw6NrCiv2RaKpp/F4QWCAD/C7138UcLsTZgnEAlcFhXEAdrLEEvcmYes9whB4acMF0dgzlZ2ehoYeL9hKf/2FqQa2fC3kjHrfaxXzQeCggiRD+8VjKUfkYPzlsye32jR6CV4RFmimML6aTNdRPLp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352330; c=relaxed/simple; bh=ksdsuPOKtC1LX3xTsWx2D7Y+HomI7lOkC104d/s180U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mj4Hs5lIc+cBv7O7LMQx45MCvwGgCu7GhQVlGui01imYtguuc15xcM+Yy4CfdU/1ivTBltnGIToDUAWWX3fQEk57ge6uOkyRazst4RZLosVIyzQZZ5MdFtASCrVsDOOty+PbF6v22owOo0oMsZEO5TGSI3ygqvc7dYacFxymx2Y= 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=ba/WV1Oz; arc=none smtp.client-ip=209.85.167.43 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="ba/WV1Oz" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-553e5df44f8so2440900e87.3 for ; Mon, 30 Jun 2025 23:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352324; x=1751957124; 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=oAr8Ssh5T1mxHeb8g5LvgIUHQP1PrvIymeg1Z4t2fGg=; b=ba/WV1OzZTeiFTBPv7id/p8Y+8fMRR3gpemqnDM8stkzxZtDth0vttPwxh6O11IaMm gzjEoEcd2Ckatmtuqt/UtRZBoorOK7Iy+AC2T9hu6UJl1Kplvepa3at852T/xPEEANZw DZs0ZSRNtL/1mcV4vL5g6XFfCoP1UtGspjSxw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352324; x=1751957124; 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=oAr8Ssh5T1mxHeb8g5LvgIUHQP1PrvIymeg1Z4t2fGg=; b=ByPc4XiTRV3VbTypQjJX/RJGKJf4KTwmzkx/Ob9XB4yVVVyoj7mrWVkXUxhjIBvtb2 gzcFFA7MlLAIIb9dh8u5lDmh5SRnjWaXs61W+fFyLSeqjPFeWD+sdGW4D4oCO/og02nC ADfMoAT+IF+Ddy4FQIVeZHlOA0Ay+wmijPUPGqaKZ28Iw75Umiw6QUihkDHchJx6NLCR PO+6nHDADMe6ETtFGPNkBYJDcXtiDIq0DFYR4pPjNX7otMfiRlBjpqCPiwKPvJ9snQeM QQvzRlsM0oEbhU3c4kZkr43IiZirOXHiGuZ1JOeUZ1bH9hAqfB0Y22p7hxWm9R9/Mauu 7NZg== X-Forwarded-Encrypted: i=1; AJvYcCUyAgRIkJDXR9lLZWQ3weWH+kAT/mYvOMSUjWZxt0mdcjL8xMmUD7s8+O7fwZJxXWO0KGuJXRAKqYnlqrA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxp60oa+9wn8cCePknjT676AQsw9s9w3w7bispLq+vwna9aTJ0B 5s2scgI+yMcq09HbAsrEKxhWXkyRJMG6o5UZB7h+cu3sKnms1z8SkzTZZfV9TEkBLQ== X-Gm-Gg: ASbGncuqSMI74ZIf1+0RWy6LZlKBZIqMosvUxpIBsYtKeJCr+r8G5u7h9ahQb3QuQrY cAN0DMmDam7/7MiWCXNiIyN2b7V4tZzFbgjpVGoud8yOiVPosB8rdJX1pYfhgMrA1z288tP/fut PzszFa3cX5eXR3Ss4CSSyKPvnMgbCBlcYm6kcGOEmgOqfmIJNf4Un0XXvWUDT0po76deFV3vBcI trysnvAyHYQoA63M+fT2oSZbB1/GFyA3ukgZD7CW7NX/4F3nm5GvEQex9RCmFdXV/kZBwdh8385 K9f4Ggg3YvayzAJpLhwTWpMoh6q/0cDdlb9GPsNdrf15Vg1oTLU4wluuqcV8A7eogwyYaj4i07h 9doO3ogA/9kSmYTz16/3mVSdfxkuT1sFCCmV/1fGxUFCEgRdhx5Vi X-Google-Smtp-Source: AGHT+IGKyqF+jMb677mgfV7M01bOGoWj0ty6vFV0pKurbZGn45gqO6qgTCykWm6wG/zFa3SkW/swmw== X-Received: by 2002:a05:6512:3156:b0:553:34b7:5731 with SMTP id 2adb3069b0e04-5550b7eccf9mr4525970e87.3.1751352324334; Mon, 30 Jun 2025 23:45:24 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:23 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:13 +0000 Subject: [PATCH v4 1/7] 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: <20250701-uvc-grannular-invert-v4-1-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , 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 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. There are other side effects, some better than others: - Locking is now more coarse than before, the queue is locked for almost every ioctl. - vidioc_querybuf() can now work when the queue is busy. Future patches should look into the locking architecture of UVC to remove one of stream->mutex or queue->mutex. Reviewed-by: Hans de Goede Reviewed-by: Hans Verkuil Signed-off-by: Hans Verkuil Co-developed-by: Ricardo Ribalda Signed-off-by: Ricardo Ribalda Link: https://lore.kernel.org/r/20250616-uvc-fop-v4-1-250286570ee7@chromium= .org Signed-off-by: Hans de Goede --- drivers/media/usb/uvc/uvc_driver.c | 37 ++--- drivers/media/usb/uvc/uvc_metadata.c | 8 +- drivers/media/usb/uvc/uvc_queue.c | 143 -------------------- drivers/media/usb/uvc/uvc_v4l2.c | 252 +++----------------------------= ---- drivers/media/usb/uvc/uvcvideo.h | 36 +---- 5 files changed, 34 insertions(+), 442 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index 62eb45435d8bec5c955720ecb46fb8936871e6cc..accfb4ca3c72cb899185ddc8ecf= 4e29143d58fc6 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1961,31 +1961,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 /* @@ -2033,6 +2009,8 @@ int uvc_register_video_device(struct uvc_device *dev, 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 @@ -2397,9 +2375,12 @@ static int __uvc_resume(struct usb_interface *intf, = int reset) list_for_each_entry(stream, &dev->streams, list) { 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); + if (ret < 0) { + mutex_lock(&stream->queue.mutex); + vb2_streamoff(&stream->queue.queue, + stream->queue.queue.type); + mutex_unlock(&stream->queue.mutex); + } 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 1abdf1ea39956bbbadd3f166f37bdac518068648..d06ecf3418a988152c6c413568c= e32e60040fd87 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,19 +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); - file->private_data =3D NULL; + vb2_fop_release(file); =20 return 0; } @@ -753,91 +676,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 +683,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 +690,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 +706,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 +794,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)) { @@ -1469,50 +1301,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, @@ -1525,12 +1313,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, @@ -1557,11 +1346,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 11d6e3c2ebdfbabd7bbe5722f88ff85f406d9bb6..b300487e6ec9163ac8236803b9e= 819814233f419 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -328,7 +328,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; @@ -621,16 +624,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; }; @@ -689,36 +686,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.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 12CB719F130 for ; Tue, 1 Jul 2025 06:45:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352328; cv=none; b=HckcD153+RI+6muxirOhIZ7Vt0QC3q49fm5zWtIxSX+lar05QtlL1+uWQozRTgDzmzdsDqKLOoZqpbamRwQRaa8htITdDNAfuoaiDE9fyHjS2ryts+3jchAd0Y/Fp2oaPAa5JBzyAnZrybx9Ph8+OZZnzHm01SaQY7GvoEkPJ+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352328; c=relaxed/simple; bh=yqUXUVprqc4Kpn+kWKnhx6hx/ZsxT0W1igC+YxtmoeU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RBRZBbbl4g43D7s2eONQx1bxzPr+jgusw1dSaRJtTM7lsEpan0+sNeHkLoVK+oGZIntXWMAsDZS0ZalWsHZxRnndSejG4WoiuALxCMBFRNFrGGrP0Bs1zQZMeMpPWfLsgnTwQiN7I0LT9VORDxORqDSJazx7JIiXucM934ouTIU= 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=SQ4I4m+6; arc=none smtp.client-ip=209.85.167.49 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="SQ4I4m+6" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-555024588b1so3348444e87.1 for ; Mon, 30 Jun 2025 23:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352325; x=1751957125; 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=XrE6GNKbVHGpnk0TTosO+XCb4jgeJmiva3zLbz/vTGo=; b=SQ4I4m+62UjAXXXbkoJ0BDJxo4teoFxgg2PHJ0GiP+3Y5TFdFKqwGnaaX7r7zs+ZI0 WoWo/1FEUI4n1qjIIK4/q4XSXkxqHzlyhpFPVZQx2JsGQmFKAPKd8CEkiGFbY3a0ICsK +i2aKOtX5vJUOhwKb0ag0iYZXNUYkQl6KC/ZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352325; x=1751957125; 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=XrE6GNKbVHGpnk0TTosO+XCb4jgeJmiva3zLbz/vTGo=; b=cDkFND/J5b7jiGvfwhZyssa/1EGc0/a5CdGRT2JL+4O867pCuLcMjOcREICZWhM0Pu WH0+fsiA5HG7lfO8DNa6Xwnx1T71V3KJ9L8TOzE1pZCrJg/lILjvGjIHG3q/QKIC9tsX 2QH+WYj2Me2kR9jsns5isbx7PenrQ5kAQk81yVW3M61qQa4GR4kDZbJxGlrGvCDmue+P HCnD8J/5+mIU8G1BWilNd/gi630uWoWeV1FqpKkYfnwxw3ubyLySVdCuDpBTBG3dMOaF /Yw2YJWBhUhIrGQpETVL6bWFpQmkibJxRzpWPQ403cQSE8aISKAmr4I/E7YO0BEm48D0 jZ2A== X-Forwarded-Encrypted: i=1; AJvYcCVRXACo56vg0w3QZrSWGXWssRrGuqUbmBN02gXurSp1EvxcMrSRnjMZwOZzdM+IR7M6aMqOvwvCdyTGBDE=@vger.kernel.org X-Gm-Message-State: AOJu0YwhitiJcDV2FPxLW8chzEtRpHYLmA/wqiCfVuXGHZ9CywTAEv6d a75i1FYx9jNGQK49ISW+snQlobhSMG2I9euHT0TbpbrTnObjLDkfCZjlP3iicK2evA== X-Gm-Gg: ASbGncu8jJfaVdomIkHXOvlgZDo2gZxWcxVovsVAV6cPc/Rm/gLAhYWASrW2K/MDGPH rzfXa3o8n2kOkgMtnvQSSzowueqQ1wDx5jxP8hLwTzNMFPkiREkIbfqkjBZg6S+33HdhWHlG1Ov Ai/yci8gwSRdFWqnVNGVEDkIYNWlIZH9SCFSjaDpURqhiB4jOwp/LFM8xr1//G96wFrBrPVEoP3 AkRVEgPuAjNUudLh91GRk/moLUeb7AhA7ddIa2U1BqJd8LPFNwxZi/USPRX/akKG8+ul7Kp/wa+ tZSBkFB1R2TRequaYDRJCF443wPeHQe4BpaBCJcNzaHEmpHax7uYdPtj56b3YN1j+idYWr3BTXi MU46z7pCcTOqGv6SDjjnMmAQdVKeRkKOgRxdSgxTdSnDhMQE9k71g X-Google-Smtp-Source: AGHT+IHY76y/ZDISkpxUl6amnEu/t94jj6fApWTdAJWcSYw0wJUfwh4U1PILUm61fBldVaiwf60NWw== X-Received: by 2002:a05:6512:3d22:b0:553:2e59:a104 with SMTP id 2adb3069b0e04-5550b8cfec0mr5233484e87.37.1751352324890; Mon, 30 Jun 2025 23:45:24 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:24 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:14 +0000 Subject: [PATCH v4 2/7] media: uvcvideo: Handle locks in uvc_queue_return_buffers 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: <20250701-uvc-grannular-invert-v4-2-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 Most of the calls to uvc_queue_return_buffers() wrap the call with spin_lock_irq()/spin_unlock_irq(). Rename uvc_queue_return_buffers to __uvc_queue_return_buffers to indicate that this is the version that does not handle locks and create a new version of the function that handles the lock. Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda Link: https://lore.kernel.org/r/20250616-uvc-fop-v4-2-250286570ee7@chromium= .org Reviewed-by: Hans Verkuil Signed-off-by: Hans de Goede --- drivers/media/usb/uvc/uvc_queue.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 72c5494dee9f46ff61072e7d293bfaddda40e615..8f9737ac729546683ca48f5e71c= e3dfacbae2926 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -42,13 +42,15 @@ static inline struct uvc_buffer *uvc_vbuf_to_buffer(str= uct vb2_v4l2_buffer *buf) * * This function must be called with the queue spinlock held. */ -static void uvc_queue_return_buffers(struct uvc_video_queue *queue, - enum uvc_buffer_state state) +static void __uvc_queue_return_buffers(struct uvc_video_queue *queue, + enum uvc_buffer_state state) { enum vb2_buffer_state vb2_state =3D state =3D=3D UVC_BUF_STATE_ERROR ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_QUEUED; =20 + lockdep_assert_held(&queue->irqlock); + while (!list_empty(&queue->irqqueue)) { struct uvc_buffer *buf =3D list_first_entry(&queue->irqqueue, struct uvc_buffer, @@ -59,6 +61,14 @@ static void uvc_queue_return_buffers(struct uvc_video_qu= eue *queue, } } =20 +static void uvc_queue_return_buffers(struct uvc_video_queue *queue, + enum uvc_buffer_state state) +{ + spin_lock_irq(&queue->irqlock); + __uvc_queue_return_buffers(queue, state); + spin_unlock_irq(&queue->irqlock); +} + /* -----------------------------------------------------------------------= ------ * videobuf2 queue operations */ @@ -171,9 +181,7 @@ static int uvc_start_streaming(struct vb2_queue *vq, un= signed int count) if (ret =3D=3D 0) return 0; =20 - spin_lock_irq(&queue->irqlock); uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED); - spin_unlock_irq(&queue->irqlock); =20 return ret; } @@ -187,9 +195,7 @@ static void uvc_stop_streaming(struct vb2_queue *vq) if (vq->type !=3D V4L2_BUF_TYPE_META_CAPTURE) uvc_video_stop_streaming(uvc_queue_to_stream(queue)); =20 - spin_lock_irq(&queue->irqlock); uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); - spin_unlock_irq(&queue->irqlock); } =20 static const struct vb2_ops uvc_queue_qops =3D { @@ -263,7 +269,7 @@ void uvc_queue_cancel(struct uvc_video_queue *queue, in= t disconnect) unsigned long flags; =20 spin_lock_irqsave(&queue->irqlock, flags); - uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); + __uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); /* * This must be protected by the irqlock spinlock to avoid race * conditions between uvc_buffer_queue and the disconnection event that --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 690EC2AE68 for ; Tue, 1 Jul 2025 06:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352329; cv=none; b=Q5xPXq/bstJ2YJaAqzHm8zzYWuMwAGOE2e6Ud7XxHcJ6rF2UAPYwAkYuZBxg2jlKIP3pzkKjOqyqTp1HxUNa2V30fOM8F9HxwgCV1JfjFtbPJmON5DC/7pGDtup/lR/QfUwPvwI5L5VYprzjn04NJFcxlwqz43YMKQ/FFt7aYx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352329; c=relaxed/simple; bh=jhmtrOZynF97yPTl8KLNDy4e5vqCIcVcQhtc4QKka7E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HkFKFDhwSwPcBwSNlv2tBiAd+J7NpR8sxIa4IuC9EIdsQhNXrBr/iHBia24d5zAMXU0F0f8JXbNQYsp1Im4z4tia8ZEDQ/gu0Y1PBbfOcqQThTai/ZYUiAUDahwR43M9oXRHaTtd9B2JrdEf89m0FOxqM2b67UVBpgQ5F7xHTKE= 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=Vm5mIpfV; arc=none smtp.client-ip=209.85.167.52 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="Vm5mIpfV" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5535652f42cso6298640e87.2 for ; Mon, 30 Jun 2025 23:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352325; x=1751957125; 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=2sXxnutuQNshAuN25MG1B9YNe5116VtrTWttVb+J9U0=; b=Vm5mIpfVaz3rUdhYcQQRP92XWGAmyxL2SrEQWE15C/sj2HAgFX5bPZLiBb2WTL0X3R j4COTNY9FodlmoMyKPYGjdvXj1p429hmAt7W5PRIV15t8okmwxRPhxETo/lDLBYNPjkE k5pZ9qpNn/7kjDBRaPzxS9zGgQdc3bWBbXUm4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352325; x=1751957125; 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=2sXxnutuQNshAuN25MG1B9YNe5116VtrTWttVb+J9U0=; b=wWwnOCoqD8iQE6Ng9d1Fm+j3yMqxdTQUGpESdCtahhXh98wjCvHdhUdfWfZbkKcdlX r3NVS0tjW8k/UzA1+b2YUKx6V6Qc1q08FkIXVLglRIttH/Lf/VLSVDESpcAPiA5jGxqA +dc8RCQnlt87RYw3+QPs7Fn+zkns3w1Br9wYFDxMXY8qyqUvua0LyMlSmKbSguoAVccI jPFZTaXxb4OrLmZOxdbf73ZS/DWUWU3+RcBYJOWDMuZg98JIMcQB2gmL1AC4NItnhpeM DoCko+QMq0pGcP54xZx7OfxiHaZ1ajh9xEx6XmiVm8T199WyWo91RSUXSG4deHX58MjE 3U0Q== X-Forwarded-Encrypted: i=1; AJvYcCUwFH4bjpwKG8YtCglD/mo+61W7a25cVTT7qwlxN3KZ9/w1AjAD68EFBYsMfH/ZiXQKwaKC816WW4iK31E=@vger.kernel.org X-Gm-Message-State: AOJu0Yx15j6B9HibvTsA8cCoFEHVlv7ulLVsrQeaU3IpF/0X7oNnYBkA oCTS1Dmq+/2oT28/+N10qRkSlwXYur2ntbh1Q0eSUxiazTOfIj40FYLJvA3io8F6RA== X-Gm-Gg: ASbGncuJ78ioF73r5tG+TxaOyi4uxblkvKZPlkkboxdB8CWQS+XLToVQAyOrvYOP8qB W3ZvOkYWwca1vJ+zgKUh8ggQGqGomA/6r1PRoH+Gwptgtdjw2DklqBOBOR3HECkvoclVBEOP912 zysnwcPB5qKNCrogsY8KHK6pNcHgkTXcofh0q+ZNYmS78uxwCo8w2PVJIFvi8o8vdlp3ozpC9Kc Mr8vXkFCZy8CAES7ujubLLsdcLPGnfH0FhgQw3B+IMwSj+AHqWVInHXgygLuivpOJ4ffspCUfZZ Oyw4BMkpQapn43lo7lwlsZ8DvzbcuIT8vrSHjksIkOixQtQORjNAt1AJl+CYXYyRlb9I2H1tEtv j3d7z2lM5zwS/Ek6xVn+eV/PUw8tbDz4T2jqUZ+tZW8knVmLQ0MQ6 X-Google-Smtp-Source: AGHT+IF1etfyT7/NUGPtPe6d6TgQJ1iZ8CgDGWZOhy283zZxe+7Pl5YxqqWScvwVSr2a+sYL6DYvnA== X-Received: by 2002:a05:6512:ba1:b0:553:2869:3a5 with SMTP id 2adb3069b0e04-5550b8d00f2mr4123019e87.48.1751352325396; Mon, 30 Jun 2025 23:45:25 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:25 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:15 +0000 Subject: [PATCH v4 3/7] media: uvcvideo: Split uvc_stop_streaming() 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: <20250701-uvc-grannular-invert-v4-3-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 uvc_stop_streaming() is used for meta and video nodes. Split the function in two to avoid confusion. Use this opportunity to rename uvc_start_streaming() to uvc_start_streaming_video(), as it is only called by the video nodes. Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda Link: https://lore.kernel.org/r/20250616-uvc-fop-v4-3-250286570ee7@chromium= .org Reviewed-by: Hans Verkuil Signed-off-by: Hans de Goede --- drivers/media/usb/uvc/uvc_queue.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 8f9737ac729546683ca48f5e71ce3dfacbae2926..b11f56d62ec0495a86105803674= 86dfaa31c450d 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -167,7 +167,7 @@ static void uvc_buffer_finish(struct vb2_buffer *vb) uvc_video_clock_update(stream, vbuf, buf); } =20 -static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count) +static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int co= unt) { struct uvc_video_queue *queue =3D vb2_get_drv_priv(vq); struct uvc_streaming *stream =3D uvc_queue_to_stream(queue); @@ -186,14 +186,22 @@ static int uvc_start_streaming(struct vb2_queue *vq, = unsigned int count) return ret; } =20 -static void uvc_stop_streaming(struct vb2_queue *vq) +static void uvc_stop_streaming_video(struct vb2_queue *vq) { struct uvc_video_queue *queue =3D vb2_get_drv_priv(vq); =20 lockdep_assert_irqs_enabled(); =20 - if (vq->type !=3D V4L2_BUF_TYPE_META_CAPTURE) - uvc_video_stop_streaming(uvc_queue_to_stream(queue)); + uvc_video_stop_streaming(uvc_queue_to_stream(queue)); + + uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); +} + +static void uvc_stop_streaming_meta(struct vb2_queue *vq) +{ + struct uvc_video_queue *queue =3D vb2_get_drv_priv(vq); + + lockdep_assert_irqs_enabled(); =20 uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); } @@ -203,15 +211,20 @@ static const struct vb2_ops uvc_queue_qops =3D { .buf_prepare =3D uvc_buffer_prepare, .buf_queue =3D uvc_buffer_queue, .buf_finish =3D uvc_buffer_finish, - .start_streaming =3D uvc_start_streaming, - .stop_streaming =3D uvc_stop_streaming, + .start_streaming =3D uvc_start_streaming_video, + .stop_streaming =3D uvc_stop_streaming_video, }; =20 static const struct vb2_ops uvc_meta_queue_qops =3D { .queue_setup =3D uvc_queue_setup, .buf_prepare =3D uvc_buffer_prepare, .buf_queue =3D uvc_buffer_queue, - .stop_streaming =3D uvc_stop_streaming, + /* + * .start_streaming is not provided here. Metadata relies on video + * streaming being active. If video isn't streaming, then no metadata + * will arrive either. + */ + .stop_streaming =3D uvc_stop_streaming_meta, }; =20 int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 23CCE24337B for ; Tue, 1 Jul 2025 06:45:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352331; cv=none; b=DSysZ6JesliNH0Hns1GVKMwKVA+LV7Pp6W4yXiRHBQN6u8/MhSGfFBWXFQRt4lHAh6ZzDckXC/Xm7xv1SNfcraFV3xQ9yXwnABRVucCa/w4zD0W+rQK7thz1x29ivFMxNBTU88Q/HrCrmNq+GViYuFBKreKvKJ066HlwPVURbCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352331; c=relaxed/simple; bh=hUSTM0cz4lDmfgU98My5Gb8Nx4v9DP1TnSn7IZqRpUY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nLuS61j6Q/az+EKoCdfwFBNiGxMZfAfyVUUhdq2Ri6rbpFU9x5QZOb4NIvlBqzm7+L7d2YhK5pFjA3Bs1jhLkriomG65cnCpKHUTNapxbE8BIPH0aGc3YtVqgUwOd1xqiwwb8bLHIsTP1IWbYMkB7N5MeLbxD1Iyz3/LNtYoPsQ= 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=a3Et2EUP; arc=none smtp.client-ip=209.85.167.48 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="a3Et2EUP" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-555024588b1so3348462e87.1 for ; Mon, 30 Jun 2025 23:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352326; x=1751957126; 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=dnt386dfMPODMMm6G8wrSthRtbiPhPkQSBX13EJa6EE=; b=a3Et2EUP5QXTMZZnaOz3ydsC/HEf7oGUzD/O15CmPBqjPixL+S5K54zH1+NLAcLPW/ kpEuGMSNhg4CnAsbU/MbGvP4TblksbgtqP8T9RQMxyVR1cqaiGqmT3PHiG1yezUTCIIa nHsttCAHFS+LA1qYM0/AoKcITlsZtOoV0XOnY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352326; x=1751957126; 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=dnt386dfMPODMMm6G8wrSthRtbiPhPkQSBX13EJa6EE=; b=XIsq21O4ms1WXybOPZeGENthXvblDyMRpdL8VH/uKCtl9g+c/d2Cd8HN8ADn7jWHPZ zoc8cckbuy5YIPZjTy2ApWTjg18p6MWpwyhzLrB7mhSd+07zes8TRMluyA1iCxH4kmgc fMCqrzBkNkEp2c6s9pRS6C9Cuy8J1vdisE+BDozYsFlmFqDlwX8FJlbS3kNXis00GFrR afsylBcAnN/Er66skEGHQrH+wxFFisXfydEPaxI7EOTI8kKua7QNFdzG3RvwzHjqd9SA 7fNDR+GNbxzP9RQp2ZgqP/GhnCDOWugo/lELoY1rxdZ7pdIEFkdqorknzSyYtg3810xl lW2g== X-Forwarded-Encrypted: i=1; AJvYcCWLv7k1OI8EY8fB/LO6FM7NDms2ZyYYhYZ2xNEckZaqPNORpKBgWwoXw0Yf41xJtfRbR2Tlf+Lq4WAbJoA=@vger.kernel.org X-Gm-Message-State: AOJu0Yzvdy8utuf0bEFdsToUCje+xkol6/n+LmUEY45DEBI7pbZBw3TL pmpE3qhA0xzICpqL2Kpgwmz7vR0owOrUVmLAMYyl+Z0EKOCztrJaGP5tlC7Md692kuqyxdpcvla mHjoG3Q== X-Gm-Gg: ASbGnctjVPUTo8L2+XfXydlNVrh5bxMUE36TkV2xDcqR6+cWmrj4LP2opPbxO6dljzF L8V/fMTlQT/aOc3PAlgLh6fWDS8tOuaUPtiXxWsfPlgVkadWKThTtG7iZKLO6VrOWqcihnBlfs3 qdO+HWD+lnU/1Ow75QqQJ0oZtzF2JqjiStBqPVC8T9tidui9sINY02ja8yaOAcx8jX8pDfx6VZm To0Br29njszlG2my3u4byt0M8svuSvlbXJ33lmkXqjsvt7QZ1CmsomF+6LQM3SJU59VP2N9m8np Nw9m0m3pplNHO/SSgdOL1lBQDJvZXxww2GUQkkjX597drauEihnfPiZK4u87tRpVnXl4Vjved+k mXphtWNGtWz13b5MP1tLh7ji8/lOkQ6YFXIefWYQGHg== X-Google-Smtp-Source: AGHT+IH4VAWYadnkTABTwlDViNU8+AGBugAzVXxKx8UY3xTvmveCwSD8omN9bv03frtrJgumJ0kdLA== X-Received: by 2002:a05:6512:104f:b0:553:2450:5895 with SMTP id 2adb3069b0e04-5550b81161amr6427078e87.4.1751352325958; Mon, 30 Jun 2025 23:45:25 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:25 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:16 +0000 Subject: [PATCH v4 4/7] 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: <20250701-uvc-grannular-invert-v4-4-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede 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 tracks the streaming state for us. Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda Link: https://lore.kernel.org/r/20250616-uvc-fop-v4-4-250286570ee7@chromium= .org Reviewed-by: Hans Verkuil Signed-off-by: Hans de Goede --- drivers/media/usb/uvc/uvc_queue.c | 9 +++++++ drivers/media/usb/uvc/uvc_v4l2.c | 51 ++---------------------------------= ---- drivers/media/usb/uvc/uvcvideo.h | 1 - 3 files changed, 11 insertions(+), 50 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index b11f56d62ec0495a8610580367486dfaa31c450d..790184c9843d211d34fa7d66801= 631d5a07450bd 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -175,12 +175,18 @@ static int uvc_start_streaming_video(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); + uvc_queue_return_buffers(queue, UVC_BUF_STATE_QUEUED); =20 return ret; @@ -189,11 +195,14 @@ static int uvc_start_streaming_video(struct vb2_queue= *vq, unsigned int count) static void uvc_stop_streaming_video(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 uvc_video_stop_streaming(uvc_queue_to_stream(queue)); =20 + uvc_pm_put(stream->dev); + uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR); } =20 diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index d06ecf3418a988152c6c413568ce32e60040fd87..7ab1bdcfb493fe9f47dbdc86da2= 3cba98d7d10ff 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); =20 @@ -676,50 +673,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) { @@ -1320,8 +1273,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 b300487e6ec9163ac8236803b9e819814233f419..3e6d2d912f3a1cfcf63b2bc8edd= 3f86f3da305db 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -629,7 +629,6 @@ struct uvc_fh { struct uvc_video_chain *chain; struct uvc_streaming *stream; unsigned int pending_async_ctrls; - bool is_streaming; }; =20 /* ------------------------------------------------------------------------ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 C84F6257449 for ; Tue, 1 Jul 2025 06:45:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352331; cv=none; b=TObDvcNzMs2uRyvrrXaxmO4wCTNDdJmf3qQO1FaftM2Xwg2mf9PlMeTc/WPBrAe8pZ6X1i/cznSw1ZRkoiWUrvuE4KBN1Va544uqBVlBlKnqSW0ZocnQgCKuCVoQYlIAYr0Hxt6xDWvePWmiAoYdPRVkbD2a4vHXLQojvDyQKec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352331; c=relaxed/simple; bh=T/ENgDFNkXtO15nvmRhR15iE4Gpc/i5d+Eopejkp9ok=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kyXGl9S5+1Cn6ZIKuD7Ol9MESQU8rSZM/QoSAytAdDsrlrpEfHSiQXdMOYVwhxE469tk6yosJCCQeAicnpILt8vG7XbicYU/TV8Cf++qBSVNFi5aeL0buLqkKYgJs7GehXCZ+1igiZRp+q+NobZ5TEj44487rCwwlH73kZdsVvw= 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=cVFyVHz5; arc=none smtp.client-ip=209.85.167.54 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="cVFyVHz5" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-553bcf41440so5331853e87.3 for ; Mon, 30 Jun 2025 23:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352327; x=1751957127; 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=kZdlFdfPdmkQXJkoN8XjUo5zo6CJqcXC2iQo+5kU+Hg=; b=cVFyVHz54lWvTGZpZjp90kB7Ja1MJ8KStzTO1ykvoFJtoYyrxWNBRpnN5RA00LVU00 tGzhVBzV6llqUUsVdMJqWiOpFwzz1/wDKK7x0HDj9JLRMvl0/jLxvUF7GhRaTQUGJh3d 4O6D4/5KH9WB5amOXTaYW+RGIDGMwOq2F8ir4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352327; x=1751957127; 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=kZdlFdfPdmkQXJkoN8XjUo5zo6CJqcXC2iQo+5kU+Hg=; b=cXcpiDJ2A2jrejMN4kNmsUEHb3QAekZnBvw9qJsUV6bDnKYSDVljyB+rm/7128EsNn aMYmZHCUr8Zsy1+CkoruDuGy2TLeGTP3hRG6KXqQjefBmmRCMJEIYTRTwT+XLIzYTnsL A12sCwOnEhFhkxbIt756+uMofXyQRxRbkiYOVUsY8CQhJZ34/aKZCapD0YCJRuXvmFwC /DzRLRwUGv9HqRFz3jigiNpDv9KzROK1pB0JVd44WQgrbeTC68IWlvJIQEOjPufoRe+M tdhOhqXLXkHiIJoBeJyH6IymJedUu6mTTGuf1ItX2VI687NJyf+bcjHocpDcNaMNqZRI vPGA== X-Forwarded-Encrypted: i=1; AJvYcCU/wThyHz5a3sAlWKvGH5YXSZqqGuvyL4y7I6VoVRksbQNoX0P6ZHTxXhAdn16TPTurbFuckGIDN7Np6CI=@vger.kernel.org X-Gm-Message-State: AOJu0YwqXqrP4o35grocrWS+lfWGYBdx6Iby2NP2gKBlD9osqq1fFA40 CsfE7rLQlkTUPExDhgSc44Kka/Z3JhM1UQaGlQmoPnBaZ568yYxbtn6e3tdih6I8SQ== X-Gm-Gg: ASbGncutyU7xCA0+S+qIwv4xUmyUYoeQsFTN6BbKqEnb2lReGHXvZoDNDN2AGvkrqM6 JqL0QNMFPWPajgCWCIr4Xyg0euHJJxtcj3XD1godeJ3t1L2NNP2lgyQNvW2Pm1MBgiy3J41CyFS iCkrdz2yOuVfyPqgIcZGeCy6CW8+fQ+dEIW1uWTD8tWCC6yAPfDoWM3l/EvIBXnzpeLerzKpQEM yY/QTIsF7lKYhwjiBkHCFD6hOchi2NFS81webwrIj5b8zG4iJerYL6IptCZtSthJtHgS8/+dpFx mgfex2ITbAoy+tDGfXEU8oNC4sjPX75yyguaqdxhjdMyTTLnkNy25AU8UJwspaB3Qfb/H7YJnrh X2zwtQ+ndXr6QO61DWiQbkEj7m6EffvAc8rg1rk1kKA== X-Google-Smtp-Source: AGHT+IFUk5DwN4L6iLti9NTtyA0INwfyi72kxI97Q28rnDFt6sVumziGfDhe56SIw4UeX08NLnkvdQ== X-Received: by 2002:ac2:4e05:0:b0:553:33b3:b944 with SMTP id 2adb3069b0e04-5550ba44a0dmr4812865e87.54.1751352326511; Mon, 30 Jun 2025 23:45:26 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:26 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:17 +0000 Subject: [PATCH v4 5/7] media: uvcvideo: Turn on the camera if V4L2_EVENT_SUB_FL_SEND_INITIAL 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: <20250701-uvc-grannular-invert-v4-5-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 If we subscribe to an event with V4L2_EVENT_SUB_FL_SEND_INITIAL, the driver needs to report back some values that require the camera to be powered on. But VIDIOC_SUBSCRIBE_EVENT is not part of the ioctls that turn on the camera. We could unconditionally turn on the camera during VIDIOC_SUBSCRIBE_EVENT, but it is more efficient to turn it on only during V4L2_EVENT_SUB_FL_SEND_INITIAL, which we believe is not a common usecase. To avoid a list_del if uvc_pm_get() fails, we move list_add_tail to the end of the function. Reviewed-by: Hans de Goede Fixes: d1b618e79548 ("media: uvcvideo: Do not turn on the camera for some i= octls") Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_c= trl.c index 303b7509ec47964dc1bf0e28127075b4a3867511..efe609d7087752cb2ef516eef0f= ce12acd13e747 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2072,18 +2072,24 @@ static int uvc_ctrl_add_event(struct v4l2_subscribe= d_event *sev, unsigned elems) goto done; } =20 - list_add_tail(&sev->node, &mapping->ev_subs); if (sev->flags & V4L2_EVENT_SUB_FL_SEND_INITIAL) { struct v4l2_event ev; u32 changes =3D V4L2_EVENT_CTRL_CH_FLAGS; s32 val =3D 0; =20 + ret =3D uvc_pm_get(handle->chain->dev); + if (ret) + goto done; + if (uvc_ctrl_mapping_is_compound(mapping) || __uvc_ctrl_get(handle->chain, ctrl, mapping, &val) =3D=3D 0) changes |=3D V4L2_EVENT_CTRL_CH_VALUE; =20 uvc_ctrl_fill_event(handle->chain, &ev, ctrl, mapping, val, changes); + + uvc_pm_put(handle->chain->dev); + /* * Mark the queue as active, allowing this initial event to be * accepted. @@ -2092,6 +2098,8 @@ static int uvc_ctrl_add_event(struct v4l2_subscribed_= event *sev, unsigned elems) v4l2_event_queue_fh(sev->fh, &ev); } =20 + list_add_tail(&sev->node, &mapping->ev_subs); + done: mutex_unlock(&handle->chain->ctrl_mutex); return ret; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 493EB25B31E for ; Tue, 1 Jul 2025 06:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352331; cv=none; b=Kfj6l8O3GF8Lub6ihSClccT+MccFnozxKY7yeoiuPZpsFNMBkJR0nLrpin9v+XiEeir2wTO8jKOAjQyUFPYp8ydJoYSkv+98vdqrnbMomFBlsWxHrelJIcYyaznx+oDHGRFxNGCAwCktOIkS99FTg7kfdxL7GY54Xo5E08D2tfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352331; c=relaxed/simple; bh=PvzBPmJzhk7/IJxcpwht8QvcuAIPS9riiN7xib6R3SY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T1t2g+xoH39WrYGxVTP1s7n7uvjCyS48ebv0EbY1Lv40Pvo28r1hVu3VebSq0xoQ8K+4K84vQ43iKmyhVgO5xPgEVVj4iRWecCJ1ypZMsUAE0PRAZ5G0F1DTXNIf9gnujBElV/mjnCPgnCgzG7eCt3kJ0vcFWmnLtTDWOxSLKWo= 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=ltGk97A2; arc=none smtp.client-ip=209.85.167.42 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="ltGk97A2" Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-555024588a8so3017449e87.0 for ; Mon, 30 Jun 2025 23:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352327; x=1751957127; 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=QqqRfEOXg2jWas5fsy2pOgHyxsxuUlHa0I3FSs4Ep3Q=; b=ltGk97A2UfVrljRalSNOiV+Rof/mrWCtsHqYDe07xdQgW0ibPypsRbhnBP0WKacf7s 0qiaHb202WvAPRLwfP/xGySy5mUBmLt913aQ5uS798orZ9CVOPH4RitwfLHGO+ApWW2S TpeiTtk4mBChMhULVYddpH3lUm7HvEHc9sztw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352327; x=1751957127; 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=QqqRfEOXg2jWas5fsy2pOgHyxsxuUlHa0I3FSs4Ep3Q=; b=mPDL2PZFuMGutZdLCJ4adYTSkB4otcehwwbGifRTIKqV0zk+rwyDbgaai5iekcejvh Crt0c+1fRJwfgne7AqwP920HYpvsX5EX+U+93zoLkmuGORtBxdyxsbrd7KXlvECcCnRJ F5IkgM6+6UbqTjJbzejWxS41VC7czU7RpsQ4slpnziIDWtltrN0lbJPgZxqRYYrCimsH m+/3lYLRhqVm2A4m+28yqjQhyihdpwxTU+nl0pwJzYsHkF+iNgQETwKziLg9MlXq2r5U PzKOWdM5YqJcP/shZzFWVcV/muuJmXoXxUp9nGob0gE7Lg0heDsgmrO98GaPZhizSfS5 B4Qw== X-Forwarded-Encrypted: i=1; AJvYcCUsawC9LK8O1QYyPVdjmuYt0/vbgrmXy/deorVX9p3KMgG7yhOEhHcemYaugWlM9GcFR/BrcPtR9zoFArE=@vger.kernel.org X-Gm-Message-State: AOJu0YwSvG4LQOQiubNSdNOanY/gnjxY3zHpj1/Cxt7JKJQgUKWaiSWg 06Q0VV0PkDQCxJoUxx0RGWSPTFIuNFsxIeHmpwllKo8pWZA8Fj5HJmoQ/6q3b3IOlA== X-Gm-Gg: ASbGncug6s7x67yKloynCQw0T52Rtbe0EuQXBwa0at3P2d4A3XliKfv+dD5wpLHgLJG eefcUL1GHgBV2Hp9dlg34FjKIMfTN1Fi7O9J2ltMrKmALq4IZXOrcUIi4+4Ra8bL1yaS0YQ6mLN 7VQOxIoWOYsDHwo8iiUkpSL8ivaNaIf8zDfypEKKg19brYN6CBZkcJaVUYlVzxtDelZOOQOi+J6 SwHB93JagE6RI2NyjXO3CL+SZvephvhJI0u0XdXukKGTlV5WiX7nezH0Q29oCvhbHReEmFKeR7E jO3SnZNR/dSdSJtRG4eZ3fTIRasdOWIoN27o2ndsbGzxzP5FAjSMaO3apVy4Ni1EZnByqFfkcoM LHoWvYN0NC62AKm11dZMW9uWkAod7JJx4c0mDi8MkXA== X-Google-Smtp-Source: AGHT+IHgQk5ifT43dRnxlWLw7XjRiZQPhcJoHtpDWw68OclgLWRSgzhN0ymKBlBDC7lKG/Ur6B5olQ== X-Received: by 2002:a05:6512:3083:b0:549:5866:6489 with SMTP id 2adb3069b0e04-5550ba224f5mr5229844e87.47.1751352327026; Mon, 30 Jun 2025 23:45:27 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:26 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:18 +0000 Subject: [PATCH v4 6/7] media: core: export v4l2_translate_cmd 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: <20250701-uvc-grannular-invert-v4-6-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 video_translate_cmd() can be useful for drivers to convert between the VIDIOC_*32 and VIDIOC_ defines. Let's export it. Now that the function is exported, use this opportunity to rename the function with the v4l2_ prefix, that is less ambiguous than video_ The VIDIOC_*32 defines are not accessible by the drivers, they live in v4l2-compat-ioctl32.c. Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/v4l2-core/v4l2-ioctl.c | 5 +++-- include/media/v4l2-ioctl.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core= /v4l2-ioctl.c index 650dc1956f73d2f1943b56c42140c7b8d757259f..d4c147ea52903290c93fad5c2d1= be59807d64614 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -3245,7 +3245,7 @@ static int check_array_args(unsigned int cmd, void *p= arg, size_t *array_size, return ret; } =20 -static unsigned int video_translate_cmd(unsigned int cmd) +unsigned int v4l2_translate_cmd(unsigned int cmd) { #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME) switch (cmd) { @@ -3266,6 +3266,7 @@ static unsigned int video_translate_cmd(unsigned int = cmd) =20 return cmd; } +EXPORT_SYMBOL_GPL(v4l2_translate_cmd); =20 static int video_get_user(void __user *arg, void *parg, unsigned int real_cmd, unsigned int cmd, @@ -3426,7 +3427,7 @@ video_usercopy(struct file *file, unsigned int orig_c= md, unsigned long arg, size_t array_size =3D 0; void __user *user_ptr =3D NULL; void **kernel_ptr =3D NULL; - unsigned int cmd =3D video_translate_cmd(orig_cmd); + unsigned int cmd =3D v4l2_translate_cmd(orig_cmd); const size_t ioc_size =3D _IOC_SIZE(cmd); =20 /* Copy arguments into temp kernel buffer */ diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index c6ec87e88dfef9e6cfe1d1fb587c1600882fb14d..82695c3a300a73219f262fb556e= d61a8f09d273e 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -679,6 +679,7 @@ long int v4l2_compat_ioctl32(struct file *file, unsigne= d int cmd, #endif =20 unsigned int v4l2_compat_translate_cmd(unsigned int cmd); +unsigned int v4l2_translate_cmd(unsigned int cmd); int v4l2_compat_get_user(void __user *arg, void *parg, unsigned int cmd); int v4l2_compat_put_user(void __user *arg, void *parg, unsigned int cmd); int v4l2_compat_get_array_args(struct file *file, void *mbuf, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 07:35:05 2025 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 D253B25C813 for ; Tue, 1 Jul 2025 06:45:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352332; cv=none; b=VDflzdr0scuaQ6UZmye0IYvzuSjdqgKqbotModgM64LvAM8GlFVydOKt95KTcO1eAp3M8OaHfujp6gx11S5G/qhJG4fQIVyqgmvSTFMzMqkf/NlNQ+Cx3KeQtR36HCUmFzsi0iygXahohG8LLEjy0FOu6ggyQ4xcij/OBQw6hZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751352332; c=relaxed/simple; bh=QmZpnmLlh6tX4XaANLS4O9Y/vCKXZvopPBJCBX6jXB4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eSv0nPVSHzQd6zJD+Y0pA1DAgaUJG6B3wIOrGtoWv0rQUwf7FYuovW8BkDKigRlz3HjRPETYrzmYnLT1OuNEeR5H/jmoXHlInyu60edcSdCbzyKMi+/jZ1bnodr1vj5PrbaaloeUrVftqb7Ahm1NY13JGkBxe2oRfBYE8zPjEjA= 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=R3TSDtgQ; arc=none smtp.client-ip=209.85.167.52 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="R3TSDtgQ" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-555163cd09aso2188286e87.3 for ; Mon, 30 Jun 2025 23:45:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1751352327; x=1751957127; 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=mD/ZZfdswixudH8eqV8nMYQf/9eq1jLBXUnC6Jy/I1E=; b=R3TSDtgQZ+7xQlc6edqU2udtstZq4sCOUKPPxSwmA49CKSkkEkg/vE40ks3HEmDlHf E7Dp32fowhMpNZkEnZYVX6IoVEtp8h+9F0znPmxrPZGvSVd7ebe5HlPh7NkrNnydXYsM cdeNUE8/Wh+rtoGK8uludInZtWaSwZFBVAgSY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751352327; x=1751957127; 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=mD/ZZfdswixudH8eqV8nMYQf/9eq1jLBXUnC6Jy/I1E=; b=bDBnBNOf9F5SG7nUpxbv67Sv82VNA/zUjkjZcUz8FkoSSId1WqOgZ5IsIVE5PyHJlN vDGo38qqWVDBxk/g3MRJpky+Iz/jnfeAUmHc4HGh1TiljFw+Zo4eVWLo/q/q6NP2hUt8 HSjVyDRqhmtEQMk7QCLF+AHExwX7YlkEBfL+u75ASIQKxztdvR682mscE3zu02qpCOVC bftbllbKLmkVpYOLD/VtlPRfhU0yGAcUHAE1XMlfBHP4Pz6YpopM4NofXdFab4hY/MT2 ourUCeJc1RlIwtXaLoYdcQx3CdttEFLYq6cVLrJqc4KBw1iZighbjeewjRVPgetNexbh KRAQ== X-Forwarded-Encrypted: i=1; AJvYcCXxBeomUzZvTIr0ER4G9i7/qcr2fdYyikTKtNxOwa9pUZYLk2PE/zyKzwviN4ywanx4yGL7iukekJbYWFE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz2jixkcqZ3+Yz7EB9x2lNjngvFgFx+pNlwLNYtYPuEEpcOq20y XV4Dqz1onjx4kWgGOo0XVXXezKnBNLExwZnOhj2Geu93XW41MvGtvqySAs+pf1ScAQ== X-Gm-Gg: ASbGncu/sbuuFmuTARmW8P2Xmhv9LGw+F3FKY0FhOwecU1/f8lC8JxOjChtOuu5bMK3 nPRa4HmAXrNXOqKEWYH0XtsQGV4JZu0ZAqVaSI2S/KOG9SBDHngXeqllzDv9VlMoIGKyJZaFGm/ qIZXx2knpzCZgGq1Hr73xhZ/TrFnjBUWccRGxjVi7l9XjFwlYK7oEazd96/ksE6CGEIjzFLzI7s Yw8js7Fh/6AjW+giE9hG4mWnhOwl4uBlaWc6AQEHglZXNnVxftiXE5msd5X/IHNLtuWpVE379gx IPHm0ZYMoYmBfkNZhbLAIy/oK2Ox3gl315jbcpx7jYLQQzk/E9PSHMzf9woNtE1lVkm4/qYGiew dIst7SgtKZKf2Oa2Pjr5xHw9T1h5a3+sPiU768RncEA== X-Google-Smtp-Source: AGHT+IHcvZzYcxMuIZSTWN1rrGh8R7B3bfUeWSAMkh500L9Xm26tRalN09L/Awjdk+uRi9ZggZqHFQ== X-Received: by 2002:a05:6512:3b0b:b0:553:abd6:cd3 with SMTP id 2adb3069b0e04-5550b7e96bcmr4895630e87.6.1751352327508; Mon, 30 Jun 2025 23:45:27 -0700 (PDT) Received: from ribalda.c.googlers.com (166.141.88.34.bc.googleusercontent.com. [34.88.141.166]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5550b2f162dsm1704836e87.248.2025.06.30.23.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 23:45:27 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 01 Jul 2025 06:45:19 +0000 Subject: [PATCH v4 7/7] media: uvcvideo: uvc_v4l2_unlocked_ioctl: Invert PM logic 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: <20250701-uvc-grannular-invert-v4-7-8003b9b89f68@chromium.org> References: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> In-Reply-To: <20250701-uvc-grannular-invert-v4-0-8003b9b89f68@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Hans de Goede , Hans de Goede Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.14.2 Instead of listing the IOCTLs that do not need to turn on the camera, list the IOCTLs that need to turn it on. This makes the code more maintainable. This patch changes the behaviour for unsupported IOCTLs. Those IOCTLs will not turn on the camera. Suggested-by: Hans Verkuil Reviewed-by: Hans de Goede Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 52 ++++++++++++++++++++----------------= ---- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 7ab1bdcfb493fe9f47dbdc86da23cba98d7d10ff..160f9cf6e6dbdbf39e3eff56a5d= 5ea1d977fbe22 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1222,36 +1222,36 @@ static long uvc_v4l2_unlocked_ioctl(struct file *fi= le, unsigned int cmd, unsigned long arg) { struct uvc_fh *handle =3D file->private_data; + unsigned int converted_cmd =3D v4l2_translate_cmd(cmd); int ret; =20 - /* The following IOCTLs do not need to turn on the camera. */ - switch (cmd) { - case VIDIOC_CREATE_BUFS: - case VIDIOC_DQBUF: - case VIDIOC_ENUM_FMT: - case VIDIOC_ENUM_FRAMEINTERVALS: - case VIDIOC_ENUM_FRAMESIZES: - case VIDIOC_ENUMINPUT: - case VIDIOC_EXPBUF: - case VIDIOC_G_FMT: - case VIDIOC_G_PARM: - case VIDIOC_G_SELECTION: - case VIDIOC_QBUF: - case VIDIOC_QUERYCAP: - case VIDIOC_REQBUFS: - case VIDIOC_SUBSCRIBE_EVENT: - case VIDIOC_UNSUBSCRIBE_EVENT: - return video_ioctl2(file, cmd, arg); - } - - ret =3D uvc_pm_get(handle->stream->dev); - if (ret) + /* The following IOCTLs need to turn on the camera. */ + switch (converted_cmd) { + case UVCIOC_CTRL_MAP: + case UVCIOC_CTRL_QUERY: + case VIDIOC_G_CTRL: + case VIDIOC_G_EXT_CTRLS: + case VIDIOC_G_INPUT: + case VIDIOC_QUERYCTRL: + case VIDIOC_QUERYMENU: + case VIDIOC_QUERY_EXT_CTRL: + case VIDIOC_S_CTRL: + case VIDIOC_S_EXT_CTRLS: + case VIDIOC_S_FMT: + case VIDIOC_S_INPUT: + case VIDIOC_S_PARM: + case VIDIOC_TRY_EXT_CTRLS: + case VIDIOC_TRY_FMT: + ret =3D uvc_pm_get(handle->stream->dev); + if (ret) + return ret; + ret =3D video_ioctl2(file, cmd, arg); + uvc_pm_put(handle->stream->dev); return ret; + } =20 - ret =3D video_ioctl2(file, cmd, arg); - - uvc_pm_put(handle->stream->dev); - return ret; + /* The other IOCTLs can run with the camera off. */ + return video_ioctl2(file, cmd, arg); } =20 const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { --=20 2.50.0.727.gbf7dc18ff4-goog