From nobody Thu Dec 18 14:10:54 2025 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 C3899223DCD for ; Mon, 2 Jun 2025 16:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880413; cv=none; b=Biw+wAKTt56C66Cx6bLxzpPwpRn0a+VoPIjkbDQJuKeUFRwKZJWJj401d15b1EsotYylR60KNNNB/tpNxXylko7J5EVE86PWdw/pQVESqw1vn5ln8IFEvQVOq6irSfk4tfOOs/M9nFZi30BV2MZivmu0v7Dwe7GvHwuXxbwkvLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880413; c=relaxed/simple; bh=pAwYR7oteo3vN3c/HkFqcbWJsyd0dKKMMaP2gKBrNyk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=trcIgTMRUjgC252GpWtor9MvEjILo02V6LsD1yRDF96fYHOzCAl4NwRSd+u2XLty4VSg2ny+74zj+FuxByZrWxdHMaH9jMSmU0w26D0xdJhLZYECle0nMdJwGrzN0t8A4kRgaaG+CqHLNJQBXOAfogCR2tBopevEJWoLKj5Zg+A= 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=DdTblg0f; arc=none smtp.client-ip=209.85.167.45 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="DdTblg0f" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5534edc6493so923462e87.1 for ; Mon, 02 Jun 2025 09:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748880410; x=1749485210; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=7YmjTdxkPOA1uf9GrAFrNIGDFJaY+dZi3frhM7shyiw=; b=DdTblg0fU3pwzPcNeLqzAj7tg1yU9UKx9BkUA+EuKggptE/0NLuOrVNLrA1p2WTCh9 Tmekuq4lCWCknT2pgp3KRlywD9RMnjlaLmrMgJB3SHdJDdBnGtnJJRuBiFEOq8LpayHu 18rLYzF7V9oG+r0uCWxyEd0rp40a8AXboe8Co= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748880410; x=1749485210; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7YmjTdxkPOA1uf9GrAFrNIGDFJaY+dZi3frhM7shyiw=; b=Wszm1VkFH1aNONCZkatQNIlzzKxjt7eiKpjopZ2U1myinaSj3cqYQFI8l03g6msSeI but+Vbgtavb3m90v5qY8v0rEaef2cjXsm0aC2p7LkSwCQa+0K7U8xCZGMqnXXRrtCYoe pQKb2S9Qbmr5RgD69nL0LItnIwKaxgzivILFul5Ksetoc+HVR0G9JGV+NL2NltE0oY/S Ud1UbZqZHEFHtJKYZ23O3g442B+C/mdYshvQCH61TQ352MWuLFBWCCcjCy6KouH3wpHm lTqzKu/n0d75MsVLt5T437TdrWE14kaY88RGfLjGA9hS00pvLpcnz9q6QL+3+WYrAccH 1Y3w== X-Forwarded-Encrypted: i=1; AJvYcCW/43fHXmC6GN3QUinFm5ONC5k14MYvy5fm30S4ZRTomMWI3nzOjIjLrhyvQoPqveb8kz4Orek/PbHrNNk=@vger.kernel.org X-Gm-Message-State: AOJu0YwvhdTQlvz49hTlyKOTu15vg73Tzwq4CTHhroiYS2st5p1cMlKD t4oA8VkXI3WZuQ9Ao56p35UQBhinMRunHzVK+CK8IJxZ+n61NszRcld9znbV1+Q4KQYFVQLMn7D klCY= X-Gm-Gg: ASbGnctg+RNw+iwVKIwwsqqh2nmoK2CIKgk0Pk3NoKzts3eo1JN4kSOBCx39/KZrylO YwtzPSsH/06GB85GLmVhJcg9McNVHXrRiXA3xmSUv2voXch7yCtqPyR/6tiHNNVbEGMdCzgm9Xy TPKlrv4yVb4GFG/922tDxI9QgDoXXDIZmOf1r8sJNjlV3uiDTC4gXMBmBzp0ELDXew5m0fDgnzU p1S0cRk54Ky2CnqA7eOcHkp4za58tJyJDZLyDRsoTCWDS9c7jfmYzVhQt1C+ntdXTjrP1sDim5o 8WIklPAmq5hUnVD7AB03HQ63ym9MSko9zgXiugGWYBlhNDxsV2hNJBO9KO483x5w/hSKAOK4FgI YwOpWwLRhOgRVxMPo6RaeR9ed1g== X-Google-Smtp-Source: AGHT+IGf8qGyIk7sMvU/JNZkuZUxxkGbZxcH8ZPvBXOi4UVuVYBe6H8zUb+NJG1maSMKMAj/rJEYQw== X-Received: by 2002:a05:6512:39c1:b0:553:2fec:b149 with SMTP id 2adb3069b0e04-5533d14f162mr3527974e87.10.1748880409806; Mon, 02 Jun 2025 09:06: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-5533789ff59sm1685113e87.70.2025.06.02.09.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 09:06:48 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 16:06:44 +0000 Subject: [PATCH v3 1/5] media: uvcvideo: Refactor uvc_queue_streamon Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250602-uvc-fop-v3-1-a99e18f65640@chromium.org> References: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> In-Reply-To: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> To: Laurent Pinchart , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans Verkuil X-Mailer: b4 0.14.2 Do uvc_pm_get before we call uvc_queue_streamon. Although the current code is correct, uvc_ioctl_streamon is always called after uvc_pm_get, this change makes the code more resiliant to future changes. This change also avoids calling streamoff, which is a rather ugly thing to do. Suggested-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Reviewed-by: Hans Verkuil Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 668a4e9d772c6d91f045ca75e2744b3a6c69da6b..862b4e34e5b629cf324479a9bb5= 9ebe8784ccd5d 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -853,15 +853,16 @@ static int uvc_ioctl_streamon(struct file *file, void= *fh, if (handle->is_streaming) return 0; =20 - ret =3D uvc_queue_streamon(&stream->queue, type); + ret =3D uvc_pm_get(stream->dev); if (ret) return ret; =20 - ret =3D uvc_pm_get(stream->dev); + ret =3D uvc_queue_streamon(&stream->queue, type); if (ret) { - uvc_queue_streamoff(&stream->queue, type); + uvc_pm_put(stream->dev); return ret; } + handle->is_streaming =3D true; =20 return 0; --=20 2.49.0.1266.g31b7d2e469-goog From nobody Thu Dec 18 14:10:54 2025 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 3E881224AE8 for ; Mon, 2 Jun 2025 16:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880428; cv=none; b=Gv4UA6oi3X2qTVcZBUL+Fr0QWpDKY5SOAfO6Pq3JotffrZoO0tHG1Tk1+dptoutgKMXxALeKg9w9OZ+RflX8POTUKlSf6YH/d6S3LsxbSJN4+qH+FGxP96x5KY6AN94oezkBMGUlZbXj+p5FwxvJ028M0v0YHMSYsSLM7uUPLAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880428; c=relaxed/simple; bh=Ij6zG2YNvNoyMgG7FCWx7uSNC0T7UFety25iU0PojKI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FMQrWP1rdWDW6DCpJTIBiRp0vJyApHOIdGVArB5E7M1rpH7Seu4VQzCmzMfIGYYd0uDTbn/BelnOihv8kge0VkhGpKzU5H3X68eyIO2RtvFNug8m/IAgu0Mh2EryiPf0E9AB46ZOeuHB4tx7+F6mnLR3DNCmG6o/t2vbj6Gs1W0= 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=hG98wBGl; arc=none smtp.client-ip=209.85.218.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="hG98wBGl" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-ad1b94382b8so806793866b.0 for ; Mon, 02 Jun 2025 09:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748880423; x=1749485223; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0hsvM1ityLLNBC4bN/XE4WBa61ejSufh04bhxVWi6Po=; b=hG98wBGlcZApkExYTO8ZhSwoTPwyCcF7ZzEwM2uilzW1CF6MUgLk/D5Hzn30J2Mybj 2il3SljOxiZJ2mzp0nwQYgd8XvGebizAsXhFQVSyMYtvAN7JHF1u+uLB5qI0vupRN33W oVXy0BZfiSkcDJXMouKH/C+psZzNwh9JWONlk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748880423; x=1749485223; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0hsvM1ityLLNBC4bN/XE4WBa61ejSufh04bhxVWi6Po=; b=TEPvjJgy7PBdPU8/MHF07pYIpoe0h7cyW3U5fh2rECfwBS/ZfancFwaAg/hAOrWLFJ IYVm9dYGo8qkGQreyFvY72vGxNsRhKjnlubj3b3B9IRFEv2a0T7uCaeGz5P7ORxr2o8n xKvv4vCkxSdPCco6A9Z1qI7JP+DgJZbZYuUPquhKwsacydFCBndqJ4bJbP+Mmhd510ta lB5UpNtKrjBYANrhnMnT26Ph5OndMSID/7OLTCmh0asUeZQAEVB9sMktfVzpz2h0aw28 pzLhkTLisAXlAfvxGgO8BjAR4JDOx1BvPX2rbowgphln8UGNvURq3RPuMB2BYJvFd4jJ z0wA== X-Forwarded-Encrypted: i=1; AJvYcCXcqc35tbswM8AmdAjwYRRJWvMkvPqBybf1aWXueTI8XcVpTv/DjeyrrdqG2waaPdH74RXRoeiIW27Xk1s=@vger.kernel.org X-Gm-Message-State: AOJu0YzMYvblAViLQXG89tNXplnT9PCvXVL/4H/xH9utIjuQtSwOkCSS vY4Dxc+aRhqHyBfeySdnJ1U+5AqQhUkstrHOB/ieYi4yZKJUPUwlY7XYN6tncK06ABs/+2VQ8O2 kNGo= X-Gm-Gg: ASbGnctuLP4ayHa/pnN8yR8p11hRjYD7zb0I5rUTaGIk9vwSrHBjQ7khhnQlCUV2A5S 2DHTJ/AtNQ0XGA9qXWMlo0Cq31oLOc9d1mYMuYuCitaVmwj4JOYTNelkp0vrI62r37t5vEkUTxl JU/NunZ5nlDZf+wcG/Dn3DtKQiLymK9nizaXbrzDc9n6/0kgvSSm/q6WbBmss9VhehUSAGWdaor 6BsMwt5cya5P/IU1z6vk00dGEhu00uj0PGjksF4HAGKBDCSJ2SUfUtzId1Otvg0cwabTMf2CG+m wZKz1ah8OVHeLgWgN/st/Ptltg1BUB801vKfW4t+kAxURI8lOgm8NPTCXZDjTxkVD23R0n06SYp J0CaFUv82jCM4QB0p6zLPuT9DqFr3LBu/lFEw X-Google-Smtp-Source: AGHT+IHjo6eQmiPFC1LXAh5wGRMa1pCptA0eavn86vc8psOoJptDHyfWAffK1CANC4655CIZzT8oTg== X-Received: by 2002:a05:6512:1328:b0:54e:81ec:2c83 with SMTP id 2adb3069b0e04-5533b8f412cmr4240839e87.18.1748880412772; Mon, 02 Jun 2025 09:06:52 -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-5533789ff59sm1685113e87.70.2025.06.02.09.06.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 09:06:50 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 16:06:45 +0000 Subject: [PATCH v3 2/5] media: uvcvideo: Use vb2 ioctl and fop helpers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250602-uvc-fop-v3-2-a99e18f65640@chromium.org> References: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> In-Reply-To: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> To: Laurent Pinchart , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hans de Goede , Hans Verkuil X-Mailer: b4 0.14.2 From: Hans Verkuil When uvc was written the vb2 ioctl and file operation helpers didn't exist. This patch switches uvc over to those helpers, which removes a lot of boilerplate code and simplifies VIDIOC_G/S_PRIORITY handling and allows us to drop the 'privileges' scheme, since that's now handled inside the vb2 helpers. This makes it possible for uvc to fix the v4l2-compliance streaming tests: warn: v4l2-test-formats.cpp(1075): Could not set fmt2 This patch introduces a change on behavior on the uvcdriver to be aligned with the rest of the subsystem. Now S_INPUT, S_PARM and S_FORMAT do no grant exclusive ownership of the device. Reviewed-by: Hans de Goede Reviewed-by: Hans Verkuil Signed-off-by: Hans Verkuil Co-developed-by: Ricardo Ribalda Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_driver.c | 34 +---- drivers/media/usb/uvc/uvc_metadata.c | 8 +- drivers/media/usb/uvc/uvc_queue.c | 143 -------------------- drivers/media/usb/uvc/uvc_v4l2.c | 251 +++----------------------------= ---- drivers/media/usb/uvc/uvcvideo.h | 37 +----- 5 files changed, 30 insertions(+), 443 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index da24a655ab68cc0957762f2b67387677c22224d1..4eeedab93b90939fc4c925012a1= 8b7d018ade39f 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1725,7 +1725,6 @@ static struct uvc_video_chain *uvc_alloc_chain(struct= uvc_device *dev) INIT_LIST_HEAD(&chain->entities); mutex_init(&chain->ctrl_mutex); chain->dev =3D dev; - v4l2_prio_init(&chain->prio); =20 return chain; } @@ -1958,31 +1957,7 @@ static void uvc_unregister_video(struct uvc_device *= dev) if (!video_is_registered(&stream->vdev)) continue; =20 - /* - * For stream->vdev we follow the same logic as: - * vb2_video_unregister_device(). - */ - - /* 1. Take a reference to vdev */ - get_device(&stream->vdev.dev); - - /* 2. Ensure that no new ioctls can be called. */ - video_unregister_device(&stream->vdev); - - /* 3. Wait for old ioctls to finish. */ - mutex_lock(&stream->mutex); - - /* 4. Stop streaming. */ - uvc_queue_release(&stream->queue); - - mutex_unlock(&stream->mutex); - - put_device(&stream->vdev.dev); - - /* - * For stream->meta.vdev we can directly call: - * vb2_video_unregister_device(). - */ + vb2_video_unregister_device(&stream->vdev); vb2_video_unregister_device(&stream->meta.vdev); =20 /* @@ -2029,7 +2004,8 @@ int uvc_register_video_device(struct uvc_device *dev, vdev->fops =3D fops; vdev->ioctl_ops =3D ioctl_ops; vdev->release =3D uvc_release; - vdev->prio =3D &stream->chain->prio; + vdev->queue =3D &queue->queue; + vdev->lock =3D &queue->mutex; if (type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT) vdev->vfl_dir =3D VFL_DIR_TX; else @@ -2399,8 +2375,8 @@ static int __uvc_resume(struct usb_interface *intf, i= nt reset) if (stream->intf =3D=3D intf) { ret =3D uvc_video_resume(stream, reset); if (ret < 0) - uvc_queue_streamoff(&stream->queue, - stream->queue.queue.type); + vb2_streamoff(&stream->queue.queue, + stream->queue.queue.type); return ret; } } diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/u= vc_metadata.c index 82de7781f5b6b70c5ba16bcba9e0741231231904..d3aab22f91cea21aefc56409924= dfa1451aec914 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -96,7 +96,7 @@ static int uvc_meta_v4l2_set_format(struct file *file, vo= id *fh, */ mutex_lock(&stream->mutex); =20 - if (uvc_queue_allocated(&stream->queue)) + if (vb2_is_busy(&stream->meta.queue.queue)) ret =3D -EBUSY; else stream->meta.format =3D fmt->dataformat; @@ -164,12 +164,6 @@ int uvc_meta_register(struct uvc_streaming *stream) =20 stream->meta.format =3D V4L2_META_FMT_UVC; =20 - /* - * The video interface queue uses manual locking and thus does not set - * the queue pointer. Set it manually here. - */ - vdev->queue =3D &queue->queue; - return uvc_register_video_device(dev, stream, vdev, queue, V4L2_BUF_TYPE_META_CAPTURE, &uvc_meta_fops, &uvc_meta_ioctl_ops); diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 2ee142621042167c2587b6a6fdd51c1a46d31c11..72c5494dee9f46ff61072e7d293= bfaddda40e615 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -242,153 +242,10 @@ int uvc_queue_init(struct uvc_video_queue *queue, en= um v4l2_buf_type type) return 0; } =20 -void uvc_queue_release(struct uvc_video_queue *queue) -{ - mutex_lock(&queue->mutex); - vb2_queue_release(&queue->queue); - mutex_unlock(&queue->mutex); -} - -/* -----------------------------------------------------------------------= ------ - * V4L2 queue operations - */ - -int uvc_request_buffers(struct uvc_video_queue *queue, - struct v4l2_requestbuffers *rb) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_reqbufs(&queue->queue, rb); - mutex_unlock(&queue->mutex); - - return ret ? ret : rb->count; -} - -int uvc_query_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *bu= f) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_querybuf(&queue->queue, buf); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_create_buffers(struct uvc_video_queue *queue, - struct v4l2_create_buffers *cb) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_create_bufs(&queue->queue, cb); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_buffer(struct uvc_video_queue *queue, - struct media_device *mdev, struct v4l2_buffer *buf) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_qbuf(&queue->queue, mdev, buf); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_export_buffer(struct uvc_video_queue *queue, - struct v4l2_exportbuffer *exp) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_expbuf(&queue->queue, exp); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_dequeue_buffer(struct uvc_video_queue *queue, struct v4l2_buffer *= buf, - int nonblocking) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_dqbuf(&queue->queue, buf, nonblocking); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type t= ype) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_streamon(&queue->queue, type); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type = type) -{ - int ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_streamoff(&queue->queue, type); - mutex_unlock(&queue->mutex); - - return ret; -} - -int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *v= ma) -{ - return vb2_mmap(&queue->queue, vma); -} - -#ifndef CONFIG_MMU -unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, - unsigned long pgoff) -{ - return vb2_get_unmapped_area(&queue->queue, 0, 0, pgoff, 0); -} -#endif - -__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, - poll_table *wait) -{ - __poll_t ret; - - mutex_lock(&queue->mutex); - ret =3D vb2_poll(&queue->queue, file, wait); - mutex_unlock(&queue->mutex); - - return ret; -} - /* -----------------------------------------------------------------------= ------ * */ =20 -/* - * Check if buffers have been allocated. - */ -int uvc_queue_allocated(struct uvc_video_queue *queue) -{ - int allocated; - - mutex_lock(&queue->mutex); - allocated =3D vb2_is_busy(&queue->queue); - mutex_unlock(&queue->mutex); - - return allocated; -} - /* * Cancel the video buffers queue. * diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v= 4l2.c index 862b4e34e5b629cf324479a9bb59ebe8784ccd5d..7a5ecbefa32c0a6b74c85d7f77a= 25b433598471e 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -47,8 +47,6 @@ void uvc_pm_put(struct uvc_device *dev) usb_autopm_put_interface(dev->intf); } =20 -static int uvc_acquire_privileges(struct uvc_fh *handle); - static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain, struct uvc_control_mapping *map, const struct uvc_xu_control_mapping *xmap) @@ -436,10 +434,6 @@ static int uvc_ioctl_s_fmt(struct file *file, void *fh, const struct uvc_frame *frame; int ret; =20 - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - if (fmt->type !=3D stream->type) return -EINVAL; =20 @@ -448,8 +442,7 @@ static int uvc_ioctl_s_fmt(struct file *file, void *fh, return ret; =20 mutex_lock(&stream->mutex); - - if (uvc_queue_allocated(&stream->queue)) { + if (vb2_is_busy(&stream->queue.queue)) { ret =3D -EBUSY; goto done; } @@ -513,10 +506,6 @@ static int uvc_ioctl_s_parm(struct file *file, void *f= h, unsigned int i; int ret; =20 - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - if (parm->type !=3D stream->type) return -EINVAL; =20 @@ -593,63 +582,6 @@ static int uvc_ioctl_s_parm(struct file *file, void *f= h, return 0; } =20 -/* ------------------------------------------------------------------------ - * Privilege management - */ - -/* - * Privilege management is the multiple-open implementation basis. The cur= rent - * implementation is completely transparent for the end-user and doesn't - * require explicit use of the VIDIOC_G_PRIORITY and VIDIOC_S_PRIORITY ioc= tls. - * Those ioctls enable finer control on the device (by making possible for= a - * user to request exclusive access to a device), but are not mature yet. - * Switching to the V4L2 priority mechanism might be considered in the fut= ure - * if this situation changes. - * - * Each open instance of a UVC device can either be in a privileged or - * unprivileged state. Only a single instance can be in a privileged state= at - * a given time. Trying to perform an operation that requires privileges w= ill - * automatically acquire the required privileges if possible, or return -E= BUSY - * otherwise. Privileges are dismissed when closing the instance or when - * freeing the video buffers using VIDIOC_REQBUFS. - * - * Operations that require privileges are: - * - * - VIDIOC_S_INPUT - * - VIDIOC_S_PARM - * - VIDIOC_S_FMT - * - VIDIOC_CREATE_BUFS - * - VIDIOC_REQBUFS - */ -static int uvc_acquire_privileges(struct uvc_fh *handle) -{ - /* Always succeed if the handle is already privileged. */ - if (handle->state =3D=3D UVC_HANDLE_ACTIVE) - return 0; - - /* Check if the device already has a privileged handle. */ - if (atomic_inc_return(&handle->stream->active) !=3D 1) { - atomic_dec(&handle->stream->active); - return -EBUSY; - } - - handle->state =3D UVC_HANDLE_ACTIVE; - return 0; -} - -static void uvc_dismiss_privileges(struct uvc_fh *handle) -{ - if (handle->state =3D=3D UVC_HANDLE_ACTIVE) - atomic_dec(&handle->stream->active); - - handle->state =3D UVC_HANDLE_PASSIVE; -} - -static int uvc_has_privileges(struct uvc_fh *handle) -{ - return handle->state =3D=3D UVC_HANDLE_ACTIVE; -} - /* ------------------------------------------------------------------------ * V4L2 file operations */ @@ -671,7 +603,6 @@ static int uvc_v4l2_open(struct file *file) v4l2_fh_add(&handle->vfh); handle->chain =3D stream->chain; handle->stream =3D stream; - handle->state =3D UVC_HANDLE_PASSIVE; file->private_data =3D handle; =20 return 0; @@ -686,18 +617,11 @@ static int uvc_v4l2_release(struct file *file) =20 uvc_ctrl_cleanup_fh(handle); =20 - /* Only free resources if this is a privileged handle. */ - if (uvc_has_privileges(handle)) - uvc_queue_release(&stream->queue); - if (handle->is_streaming) uvc_pm_put(stream->dev); =20 /* Release the file handle. */ - uvc_dismiss_privileges(handle); - v4l2_fh_del(&handle->vfh); - v4l2_fh_exit(&handle->vfh); - kfree(handle); + vb2_fop_release(file); file->private_data =3D NULL; =20 return 0; @@ -753,91 +677,6 @@ static int uvc_ioctl_try_fmt(struct file *file, void *= fh, return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); } =20 -static int uvc_ioctl_reqbufs(struct file *file, void *fh, - struct v4l2_requestbuffers *rb) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - mutex_lock(&stream->mutex); - ret =3D uvc_request_buffers(&stream->queue, rb); - mutex_unlock(&stream->mutex); - if (ret < 0) - return ret; - - if (ret =3D=3D 0) - uvc_dismiss_privileges(handle); - - return 0; -} - -static int uvc_ioctl_querybuf(struct file *file, void *fh, - struct v4l2_buffer *buf) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_query_buffer(&stream->queue, buf); -} - -static int uvc_ioctl_qbuf(struct file *file, void *fh, struct v4l2_buffer = *buf) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_queue_buffer(&stream->queue, - stream->vdev.v4l2_dev->mdev, buf); -} - -static int uvc_ioctl_expbuf(struct file *file, void *fh, - struct v4l2_exportbuffer *exp) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_export_buffer(&stream->queue, exp); -} - -static int uvc_ioctl_dqbuf(struct file *file, void *fh, struct v4l2_buffer= *buf) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - - if (!uvc_has_privileges(handle)) - return -EBUSY; - - return uvc_dequeue_buffer(&stream->queue, buf, - file->f_flags & O_NONBLOCK); -} - -static int uvc_ioctl_create_bufs(struct file *file, void *fh, - struct v4l2_create_buffers *cb) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_create_buffers(&stream->queue, cb); -} - static int uvc_ioctl_streamon(struct file *file, void *fh, enum v4l2_buf_type type) { @@ -845,11 +684,6 @@ static int uvc_ioctl_streamon(struct file *file, void = *fh, struct uvc_streaming *stream =3D handle->stream; int ret; =20 - if (!uvc_has_privileges(handle)) - return -EBUSY; - - guard(mutex)(&stream->mutex); - if (handle->is_streaming) return 0; =20 @@ -857,7 +691,7 @@ static int uvc_ioctl_streamon(struct file *file, void *= fh, if (ret) return ret; =20 - ret =3D uvc_queue_streamon(&stream->queue, type); + ret =3D vb2_ioctl_streamon(file, fh, type); if (ret) { uvc_pm_put(stream->dev); return ret; @@ -873,13 +707,12 @@ static int uvc_ioctl_streamoff(struct file *file, voi= d *fh, { struct uvc_fh *handle =3D fh; struct uvc_streaming *stream =3D handle->stream; + int ret; =20 - if (!uvc_has_privileges(handle)) - return -EBUSY; - - guard(mutex)(&stream->mutex); + ret =3D vb2_ioctl_streamoff(file, fh, type); + if (ret) + return ret; =20 - uvc_queue_streamoff(&stream->queue, type); if (handle->is_streaming) { handle->is_streaming =3D false; uvc_pm_put(stream->dev); @@ -962,13 +795,13 @@ static int uvc_ioctl_g_input(struct file *file, void = *fh, unsigned int *input) static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int inp= ut) { struct uvc_fh *handle =3D fh; + struct uvc_streaming *stream =3D handle->stream; struct uvc_video_chain *chain =3D handle->chain; u8 *buf; int ret; =20 - ret =3D uvc_acquire_privileges(handle); - if (ret < 0) - return ret; + if (vb2_is_busy(&stream->queue.queue)) + return -EBUSY; =20 if (chain->selector =3D=3D NULL || (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) { @@ -1471,50 +1304,6 @@ static long uvc_v4l2_unlocked_ioctl(struct file *fil= e, return ret; } =20 -static ssize_t uvc_v4l2_read(struct file *file, char __user *data, - size_t count, loff_t *ppos) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s: not implemented\n", __func__); - return -EINVAL; -} - -static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_mmap(&stream->queue, vma); -} - -static __poll_t uvc_v4l2_poll(struct file *file, poll_table *wait) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_poll(&stream->queue, file, wait); -} - -#ifndef CONFIG_MMU -static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, - unsigned long addr, unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct uvc_fh *handle =3D file->private_data; - struct uvc_streaming *stream =3D handle->stream; - - uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - - return uvc_queue_get_unmapped_area(&stream->queue, pgoff); -} -#endif - const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_g_fmt_vid_cap =3D uvc_ioctl_g_fmt, .vidioc_g_fmt_vid_out =3D uvc_ioctl_g_fmt, @@ -1527,12 +1316,13 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_enum_fmt_vid_out =3D uvc_ioctl_enum_fmt, .vidioc_try_fmt_vid_cap =3D uvc_ioctl_try_fmt, .vidioc_try_fmt_vid_out =3D uvc_ioctl_try_fmt, - .vidioc_reqbufs =3D uvc_ioctl_reqbufs, - .vidioc_querybuf =3D uvc_ioctl_querybuf, - .vidioc_qbuf =3D uvc_ioctl_qbuf, - .vidioc_expbuf =3D uvc_ioctl_expbuf, - .vidioc_dqbuf =3D uvc_ioctl_dqbuf, - .vidioc_create_bufs =3D uvc_ioctl_create_bufs, + .vidioc_reqbufs =3D vb2_ioctl_reqbufs, + .vidioc_querybuf =3D vb2_ioctl_querybuf, + .vidioc_prepare_buf =3D vb2_ioctl_prepare_buf, + .vidioc_qbuf =3D vb2_ioctl_qbuf, + .vidioc_expbuf =3D vb2_ioctl_expbuf, + .vidioc_dqbuf =3D vb2_ioctl_dqbuf, + .vidioc_create_bufs =3D vb2_ioctl_create_bufs, .vidioc_streamon =3D uvc_ioctl_streamon, .vidioc_streamoff =3D uvc_ioctl_streamoff, .vidioc_enum_input =3D uvc_ioctl_enum_input, @@ -1559,11 +1349,10 @@ const struct v4l2_file_operations uvc_fops =3D { #ifdef CONFIG_COMPAT .compat_ioctl32 =3D uvc_v4l2_compat_ioctl32, #endif - .read =3D uvc_v4l2_read, - .mmap =3D uvc_v4l2_mmap, - .poll =3D uvc_v4l2_poll, + .mmap =3D vb2_fop_mmap, + .poll =3D vb2_fop_poll, #ifndef CONFIG_MMU - .get_unmapped_area =3D uvc_v4l2_get_unmapped_area, + .get_unmapped_area =3D vb2_fop_get_unmapped_area, #endif }; =20 diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index b9f8eb62ba1d82ea7788cf6c10cc838a429dbc9e..3ddbf065a2cbae40ee48cb06f84= ca8f0052990c4 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -326,7 +326,10 @@ struct uvc_buffer { =20 struct uvc_video_queue { struct vb2_queue queue; - struct mutex mutex; /* Protects queue */ + struct mutex mutex; /* + * Serializes vb2_queue and + * fops + */ =20 unsigned int flags; unsigned int buf_used; @@ -349,7 +352,6 @@ struct uvc_video_chain { * uvc_fh.pending_async_ctrls */ =20 - struct v4l2_prio_state prio; /* V4L2 priority state */ u32 caps; /* V4L2 chain-wide caps */ u8 ctrl_class_bitmap; /* Bitmap of valid classes */ }; @@ -619,16 +621,10 @@ struct uvc_device { struct uvc_entity *gpio_unit; }; =20 -enum uvc_handle_state { - UVC_HANDLE_PASSIVE =3D 0, - UVC_HANDLE_ACTIVE =3D 1, -}; - struct uvc_fh { struct v4l2_fh vfh; struct uvc_video_chain *chain; struct uvc_streaming *stream; - enum uvc_handle_state state; unsigned int pending_async_ctrls; bool is_streaming; }; @@ -687,36 +683,11 @@ struct uvc_entity *uvc_entity_by_id(struct uvc_device= *dev, int id); =20 /* Video buffers queue management. */ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type); -void uvc_queue_release(struct uvc_video_queue *queue); -int uvc_request_buffers(struct uvc_video_queue *queue, - struct v4l2_requestbuffers *rb); -int uvc_query_buffer(struct uvc_video_queue *queue, - struct v4l2_buffer *v4l2_buf); -int uvc_create_buffers(struct uvc_video_queue *queue, - struct v4l2_create_buffers *v4l2_cb); -int uvc_queue_buffer(struct uvc_video_queue *queue, - struct media_device *mdev, - struct v4l2_buffer *v4l2_buf); -int uvc_export_buffer(struct uvc_video_queue *queue, - struct v4l2_exportbuffer *exp); -int uvc_dequeue_buffer(struct uvc_video_queue *queue, - struct v4l2_buffer *v4l2_buf, int nonblocking); -int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type t= ype); -int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type = type); void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect); struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, struct uvc_buffer *buf); struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *qu= eue); void uvc_queue_buffer_release(struct uvc_buffer *buf); -int uvc_queue_mmap(struct uvc_video_queue *queue, - struct vm_area_struct *vma); -__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, - poll_table *wait); -#ifndef CONFIG_MMU -unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue, - unsigned long pgoff); -#endif -int uvc_queue_allocated(struct uvc_video_queue *queue); static inline int uvc_queue_streaming(struct uvc_video_queue *queue) { return vb2_is_streaming(&queue->queue); --=20 2.49.0.1266.g31b7d2e469-goog From nobody Thu Dec 18 14:10:54 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 017B72253FB for ; Mon, 2 Jun 2025 16:06:55 +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=1748880417; cv=none; b=p52FFLU3Px40qpbTJ+Ek6uGCoXJ/Agep963FYDddkvrhSHsZkgM6sgzjIcMbDHGCjw4e4Gqy6bbPyvz5XDvTNDw0R2xc46Hjla+QSQs6WsgPXdMqsTN6mq514NaKN/BVpAhPe2bSzrvU+8FsYX/5n4CEBpKgtaEz5cgiQdiXbc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880417; c=relaxed/simple; bh=bpEYln/8wFdT/ptVY7qi+97NkzepeIhBhRswFy5rIAQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GBu1mSQjVOdmEFz8LHMppjHzivI74Ora4ecqOy13G2Gs0Zu1zhFqv9FVS+v+fKvRjcku9oA9norlQAFG9S6/FtJsEAG7XSk/ezWHvqicLiL6+2vdBHRazJnBGpgFb6l88mcl7wvE1JpxzwcmP9Csn9hvYeJh/fSc7Od8YkeIlkk= 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=JETXxFjx; 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="JETXxFjx" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-55351af2fc6so280650e87.0 for ; Mon, 02 Jun 2025 09:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748880414; x=1749485214; 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=efP3IxJ2OLjk9HTtbcsKFWKXCw7ZfZSVYKNc3/G7w2U=; b=JETXxFjxs3sP+TPlEuvAek/mrZ94FLvSvHUjAHjMrbmQNEajIMT9jvwxWmCG2TGx2g NVEBcRmoWmA6kv7eRvZM5FFF0PRIi0GWh5FAW7GdmpAdmfcP4y0DHIhZO2IcADTdnZjE eC/wYQQ/d1bcdG54PWSdumJxYJjt6QGYPcImg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748880414; x=1749485214; 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=efP3IxJ2OLjk9HTtbcsKFWKXCw7ZfZSVYKNc3/G7w2U=; b=iOJkqcht9WSVHmz7AkEqjTXPUD5oGPlYGOPTqVuASy0ipB1vOh2srqMbdiOO60Db3G xXZig4DjGP0O7U0LzdvMqTq5eCe3G22D09mDBMYbVkxsg5kMkoX6HH6Xa4kqrHEjjaZK FX2n+vnmE/bnn54NCodr6xpk0ngQQa+uO4nlaBoELTsxQIFuORe7ff4ZTr3MkfsqjzU3 QpNnw5loPuHD7idNUatoqduq9l2p4yE48lGgxeu7Tpp1CPAq48sj+wNInK4AQz5HyTIv QIB3KKi9uu6b60U3XXgqG5UduZYGsUqK5tewjqNo4yd7W4rXMawE1J+Zy4A15AW3y4wA RgyA== X-Forwarded-Encrypted: i=1; AJvYcCXTwLnWDA5n+q9vL+8k1jytW8qj7hsRV2LFPomR4GzOFzRfT5yhvkuKZpiX47keB7bvKhoRdRFC3LCqXEw=@vger.kernel.org X-Gm-Message-State: AOJu0YyBpsRTLAmR9NBKR7WssmOYjdqqTKxxM/ujgQb3vEPa5U7XDUlQ E1JKErm9OG8ZmpzQ8NQK6limZKJzrDC+IZcb4EyuxwgzEM3OOHLEowjdQ8FgbQe1IQ== X-Gm-Gg: ASbGncsyN+pi634KOshsJU6UUsVkgIfEIybau7bKn99Z72dWvHcE3oBi4rZnUTQ8X2T Vs3jujc2OTdLA3NQc/zPYlqwqn4Qu55iYBSglnsheYAMWWay3CV5LwYY88ttenOq3OqwYmXhvxB W+ig26fhVILn1wivgrblqtoMbKNxvK796eT15f0DFrzKPbPQfeS7+ZSbSLVIVcvu28B4HDzDxWT RclwxydPZ/amC8tBaNVEkz2g2E6AcGXxPpBXgexUoIUWIspaYmu2tIIi5rZj/hGMNCsy6jx4kYF kvjkvNAF8C7BjskpnlC6QW0ts27wMCBjkp05Zwjn5uyEoYY75BFdB57Ls35mYmJNYdhGE1XqTxh /sak1IyDO9INsq/3sWWg6ew6bMA== X-Google-Smtp-Source: AGHT+IFQDTvJfIrCftEwU9zeJo4OFOcaIU2aCEdgUR2dSt6cy7LF8kw8+QhTXCXa1wdxZHtucUBDhw== X-Received: by 2002:a05:6512:e9f:b0:553:2e3a:bae with SMTP id 2adb3069b0e04-5533d1b80edmr3477475e87.39.1748880414102; Mon, 02 Jun 2025 09:06:54 -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-5533789ff59sm1685113e87.70.2025.06.02.09.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 09:06:53 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 16:06:46 +0000 Subject: [PATCH v3 3/5] 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: <20250602-uvc-fop-v3-3-a99e18f65640@chromium.org> References: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> In-Reply-To: <20250602-uvc-fop-v3-0-a99e18f65640@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 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. Signed-off-by: Ricardo Ribalda Reviewed-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.49.0.1266.g31b7d2e469-goog From nobody Thu Dec 18 14:10:54 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 D066B22424C for ; Mon, 2 Jun 2025 16:06:57 +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=1748880419; cv=none; b=IAHICdQNrgl0hplm36GtfcozAfaJq/dM+yuFAywakJiJp8kQ2UZIZ3VxnAgU6KXlUcc94on2yWFJ2q+ZFJ+kN1QVkHCmlqZDx4nnkCD16BoCSaQbhSbLBm8xRNR4FWlLr0yW8jpPGTkfRqYIxLYTtg5V70PHq1WIFZMoMF64Hhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880419; c=relaxed/simple; bh=x8ARRUfk9oLGkaOrxkaBCWajZYx1f7oGSGAHZC6eR3A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RUiKPw2Lo/O3IlQVekKxm04RTd1CT07dDMptb+oHaucETecgwV9kF4aAyxun2UFej8JXg2OmrS+UWpIY2Te1f0ynGVToqShxQ389tpb7oOg46VMFm2wMXgAxlJa76yDISmTrD+tvQJx/x5wH5cJZOwS+HPHCKo9Jc7mol1syBdQ= 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=GNs+oMFL; 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="GNs+oMFL" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5533303070cso5135562e87.2 for ; Mon, 02 Jun 2025 09:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748880416; x=1749485216; 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=Tsl+7wQGk9ZntFAe3/W4dFK7sUDLARFjk/FGrlC2+fc=; b=GNs+oMFL9WBs5SHg1Jn/E3UWifROQyOe40NLvSthQjMU4G7cq/8ajIquarzAxVCnLA 8o/n2TeJP4gIo44dnsY5I2ALcdDJt7KjoQItsPO4Ix16/obhq/2iqHH4qaT0I8B2hO81 lpD+9h5GLA76/J8lVlHzW6vrTZPf89gvkCOGQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748880416; x=1749485216; 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=Tsl+7wQGk9ZntFAe3/W4dFK7sUDLARFjk/FGrlC2+fc=; b=TyO1enwQXFUKYvav6KCE4bOtIqu1RFas4/X5MNLDJPe/IX5RtGmiL6NlhLnz34f54M hA9R29UwOS0ytt6NSC9h9PW5LF1C2VeARuB/7xU/qoBkksbQgcqwSUXtGBqso3V7tcuN NQRaQERFXEevlNUhxv/oIMEB+S0mm+C+4Jq0oi3ViuJiQjxnxLBealDInxBhvcT2kjLj MI0EdScCcMw+zoT6bunUjVQsv9UTpRVAXaVWg3WJKiffCAzKuWy4dbe0uhUBelYPEhYE f5leWGmiaDvW+hY8RhIikGc0vLr2feSyLCFHWy/lGigjPbk1gd6dYugdzwH/LtdcFrjb oaUw== X-Forwarded-Encrypted: i=1; AJvYcCWVpDONCcBBQ31iqBpsFsEHR4ksPB61JX98oPJ9CdIjnSWJyUdS/gzZpcy9axeiyamkwHhnlyhd1r05g0w=@vger.kernel.org X-Gm-Message-State: AOJu0YxwfCVRV+S/brqnxwY1p/fXe8VLCnwUM7DUd3Nb+UkTt/dfU8GX a0DuFVcffkunYrg7s8eHn2gnpmwWk6jR00bX8FhRLGGQA5n9WvDCo4pgcKwYqbnDfQ== X-Gm-Gg: ASbGncv4rAFLWNswh6TsUB37G5Ildk/dXHmMn/qWcH0KW3eWbdePeN0sfOvuscPUvNo auYO9yKDZWbTNJHh4vlPr3+9eXBFyE3U9iSrAomR/BgJuJHfcnQWmXotAS9zbeTYzU4nO4U6XPt ZWpy54zkK6NRtkSJENMzcI5/doX7PnqteQN5Wa5RcG/6J00fBIoQj39J6W0svs7TOOkdNcRPzz+ deVOeuDPvxxwSQ03sp+Hik/kyfdMHelAP/SkRL0+zbBJ4dBnBrFVRow+ukA6lmB7WsLME7RkXk7 4JxcGNcduDAWubccmaAfWdKQ0+NSi34P6oLIcfvjA3oqBojjj8qAvG0dY5g+I4UB2I2lq8Rqfnm aIe6bbWfoX7WQV+C4gzy5ttfMKw== X-Google-Smtp-Source: AGHT+IFxmyew38lXdFBjLeeHnHTb6UXZ5u/rUZYcQG2foqP1RSS/ATAS64OuLPvFoinn2xt7EIx0SQ== X-Received: by 2002:a05:6512:3f26:b0:553:2a16:24fd with SMTP id 2adb3069b0e04-55343191677mr2358426e87.47.1748880415831; Mon, 02 Jun 2025 09:06:55 -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-5533789ff59sm1685113e87.70.2025.06.02.09.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 09:06:54 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 16:06:47 +0000 Subject: [PATCH v3 4/5] 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: <20250602-uvc-fop-v3-4-a99e18f65640@chromium.org> References: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> In-Reply-To: <20250602-uvc-fop-v3-0-a99e18f65640@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 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. Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- drivers/media/usb/uvc/uvc_queue.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 8f9737ac729546683ca48f5e71ce3dfacbae2926..3f357c2d48cfd258c26f0342007= d1d12f1e01007 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,15 @@ 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, + .stop_streaming =3D uvc_stop_streaming_meta, }; =20 int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) --=20 2.49.0.1266.g31b7d2e469-goog From nobody Thu Dec 18 14:10:54 2025 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 C8BB5225792 for ; Mon, 2 Jun 2025 16:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880420; cv=none; b=Y68EG4IqfofIGY0OgqurGHcxxAAa8uBYRzrrYYsClVUagbLGongPTm3POdzmyB0DxpFrjDFL551FzoxRcWZPZiQ4BblAamLMC0MLUNaCzyKo65QFpXx8tWxcrSXrMLX32wPJq0aLRN/dquJ+8ErKDfkqYyA02rHJkAp9h2jJYBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748880420; c=relaxed/simple; bh=mvmwmP+loYWmqDadmPQCngMfwJYHfBbGn3wUfyXPsa8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nuK4whpFvvU8e3ksnbunbLRyC5X4K8afIjxr3eZLCm1gqdfIydrln//C8pl/KpnPaMMVN66Kl5wQgYQnxma6qFMvB3vmBeoZIDISRyzbUilYD8QGfv0ZPIqm5/0A3NztWvnqMU9vcsoexFqzbUt5Iitdzm5IyOVGDxF7chjVXag= 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=Y5uqi4CP; arc=none smtp.client-ip=209.85.167.47 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="Y5uqi4CP" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-54e816aeca6so5899488e87.2 for ; Mon, 02 Jun 2025 09:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1748880417; x=1749485217; 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=y74ULT3LPdgyH4OAnVV/2bC+RHsnC8gdCTnFia7kZh4=; b=Y5uqi4CPpxII5RVEp6VBVxZf8rJOf7WeGCN7zXJoJnU0yGiBfITxTbJGlZZe+4w6uv 4C4ZtvMGedOCrkrqrluj7TYRUSAf756RyVw1nCfUD8VNgtfunK1ttWtytast2HwFr4JW oAMGjDJDA9a6VLtwd/TUsZBeFl2EfwwIWrPCw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748880417; x=1749485217; 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=y74ULT3LPdgyH4OAnVV/2bC+RHsnC8gdCTnFia7kZh4=; b=KzyxO6+P+hTPtOxFP116gGNDcmeGvaoV3nW2mfdNlaMbSjFZ/LjagteyrvwWOum5ve hBeOBSzIphQY4zBvxHOyiqqWhTbonP/ycgroORnKOypiLAKjIO1Rm2EkLgjQqyWCjDyy PxUglKSK9l7AS9kh3yl4HWZ394o0BvoH1heAhvTBz9MiCVi5L5TAykbl+Q+gL6MHliPU idhW9QU+o+Hulj+l095vKN/597anHJ9wMgKoUq4EDf4DWFXBY8sFS3ORk+EpAETNU1WU 1BUTDNt1D53vPraOmCTNsl025g9KYRl2HkxtBXtpvDHeztufdFaP+temf37XeBjF1+kK EDYQ== X-Forwarded-Encrypted: i=1; AJvYcCWI8D/P8xUfOA+OQHJ5bPeIow7TizIYvsiW1rrJYkq4QgmtDOiFuGrs76YYb5ChgXxPs1LKjUgGts7nVmI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5rKFeSCMmyn8ZGu0GeDCU4zWwirsYQFo95o6zdguL7Q3pazuB A5k1uxswtz25c+lCBTB5tctk4vGyA0CXfxWlZycBeRCCfx8sypfXUC34XG2jNbo2sg== X-Gm-Gg: ASbGncublRXrH7b0m2CJlV0YxkWPbsX8/b8wmzeC/2ipVWGy330eFUPLhz9DEJszFYG IQhQL6DPaoX1Lsv2ex1rR9pHnkTUBY39IYjWhhkFwNmynXmvqhspfI9wzPj8YEUeg6rXaExND2j ITI1g5l6yLAkpznOzV/oALUC5DMpiT5kW7Vuze+Sn5+RKQEKqWzRGOS+3uVu4HABx3wtXPVtMlJ L0EtxOvjSPyFMcUsDjVc2RDTEW6s2Kn7tyUowYOffkSYJvJDyg6i6UDKxfHf/DMJcjhaLWp0pQ+ kz1dq0S4I6EklptNX/UFAOWo08k0rjXMhdMJ92bszgUKGkN0Co5APFAwmg65vBAuNKpjTmW8vRq eyziDpGqkx1PlVpMSlbYc86cTp8OA6UuDfSa4ZhsgUdIFStI= X-Google-Smtp-Source: AGHT+IGTKU1WbVBlmwGCeTPrDflgtRy3jQ2qUN9dh8EbI3UeiEfXdHZO8sZqCEtiVUymDdZIURz+zA== X-Received: by 2002:a05:6512:b88:b0:553:37e7:867a with SMTP id 2adb3069b0e04-5533b93b66fmr3908786e87.49.1748880416881; Mon, 02 Jun 2025 09:06:56 -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-5533789ff59sm1685113e87.70.2025.06.02.09.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 09:06:56 -0700 (PDT) From: Ricardo Ribalda Date: Mon, 02 Jun 2025 16:06:48 +0000 Subject: [PATCH v3 5/5] media: uvcvideo: Remove stream->is_streaming field Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250602-uvc-fop-v3-5-a99e18f65640@chromium.org> References: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> In-Reply-To: <20250602-uvc-fop-v3-0-a99e18f65640@chromium.org> To: Laurent Pinchart , Hans de Goede , Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 The is_streaming field is used by modular PM to know if the device is currently streaming or not. With the transition to vb2 and fop helpers, we can use vb2 functions for the same functionality. The great benefit is that vb2 already takes track of the streaming state for us. Signed-off-by: Ricardo Ribalda Reviewed-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 3f357c2d48cfd258c26f0342007d1d12f1e01007..6e845705b3286348a60650eb262= e620dc6039d60 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 7a5ecbefa32c0a6b74c85d7f77a25b433598471e..d4bee0d4334b764c0cf02363b57= 3b55fb44eb228 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -617,9 +617,6 @@ static int uvc_v4l2_release(struct file *file) =20 uvc_ctrl_cleanup_fh(handle); =20 - if (handle->is_streaming) - uvc_pm_put(stream->dev); - /* Release the file handle. */ vb2_fop_release(file); file->private_data =3D NULL; @@ -677,50 +674,6 @@ static int uvc_ioctl_try_fmt(struct file *file, void *= fh, return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); } =20 -static int uvc_ioctl_streamon(struct file *file, void *fh, - enum v4l2_buf_type type) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - if (handle->is_streaming) - return 0; - - ret =3D uvc_pm_get(stream->dev); - if (ret) - return ret; - - ret =3D vb2_ioctl_streamon(file, fh, type); - if (ret) { - uvc_pm_put(stream->dev); - return ret; - } - - handle->is_streaming =3D true; - - return 0; -} - -static int uvc_ioctl_streamoff(struct file *file, void *fh, - enum v4l2_buf_type type) -{ - struct uvc_fh *handle =3D fh; - struct uvc_streaming *stream =3D handle->stream; - int ret; - - ret =3D vb2_ioctl_streamoff(file, fh, type); - if (ret) - return ret; - - if (handle->is_streaming) { - handle->is_streaming =3D false; - uvc_pm_put(stream->dev); - } - - return 0; -} - static int uvc_ioctl_enum_input(struct file *file, void *fh, struct v4l2_input *input) { @@ -1323,8 +1276,8 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops =3D { .vidioc_expbuf =3D vb2_ioctl_expbuf, .vidioc_dqbuf =3D vb2_ioctl_dqbuf, .vidioc_create_bufs =3D vb2_ioctl_create_bufs, - .vidioc_streamon =3D uvc_ioctl_streamon, - .vidioc_streamoff =3D uvc_ioctl_streamoff, + .vidioc_streamon =3D vb2_ioctl_streamon, + .vidioc_streamoff =3D vb2_ioctl_streamoff, .vidioc_enum_input =3D uvc_ioctl_enum_input, .vidioc_g_input =3D uvc_ioctl_g_input, .vidioc_s_input =3D uvc_ioctl_s_input, diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 3ddbf065a2cbae40ee48cb06f84ca8f0052990c4..f895f690f7cdc1af942d5f3a5f1= 0e9dd1c956a35 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -626,7 +626,6 @@ struct uvc_fh { struct uvc_video_chain *chain; struct uvc_streaming *stream; unsigned int pending_async_ctrls; - bool is_streaming; }; =20 /* ------------------------------------------------------------------------ --=20 2.49.0.1266.g31b7d2e469-goog