From nobody Mon Apr 6 16:47:57 2026 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 561A92C3260 for ; Wed, 18 Mar 2026 20:23:57 +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=1773865438; cv=none; b=IYbn9LZdkIcUKY5WY0USb6VcVAZt4vQ94P0YQMHLTSgs5iJay4/qNKg1bTssSfCNEkILMKBfOabrWQqArORviDjzF1dix0DpXVLTb1CBqm+P+p1anjm8AgPRIXygvM78ndiqvV+COcSoOtfADGJe+2fGozgPCoaY9MKixPThjV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773865438; c=relaxed/simple; bh=NEm/TKzAJPTuRgXu8BpOYexrmSgMICNIiEk67EjaDf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n8uYHHNAyCOkmTBYijH4Wf8UhkukKR7D7+UwcX9lo/ruYybWLpmBmnxsgNmXKP+7VRjgEhkC+fwv7vRy6nh19GOQsbninHrXBfEyqcJLjDZKMxgFjcoihfpD1jBEMNdSPkqP4XSrl6soEViTu+voqcFxyqyfpmywp9dI9wLPvEg= 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=hBqdzf53; 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="hBqdzf53" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5a27a90a7b6so255795e87.1 for ; Wed, 18 Mar 2026 13:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1773865435; x=1774470235; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C+xHO5blJE+zF4h0uhf1u3z/t70Qd/4JVir1geZ2PM4=; b=hBqdzf534zqB/R0i8CWwEJrTtgTcD27LddskViSyyeKrxY7U1IV3aQN36xXpF6Oiey o7qegGtd5Bkvm0/oB3AQ5RqkLHYskpIDBRFitxL9tMCzjon429HK3GzafFp/rL/EpZXa dN70ak5waqmj63QTY2gb5hGGChMzTuMaOwIq4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773865435; x=1774470235; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=C+xHO5blJE+zF4h0uhf1u3z/t70Qd/4JVir1geZ2PM4=; b=ssYdK0bU8/om/Db+nMjuhB2H9AKpj2cyBOekjJNFTfwODopGIwZg3pR7A8P2d6zCQX hNY+lUKLOnQ8x4IHpan0f4Im4BW/HE3r3O0YABQX17YKs4C18760pFiVMnV+KnugIhVF 2UBUmsiVJ/lV4/bOjOkUlJ9kDT5AzVVDn1ZnbTPfIl0k0jdrFLHFF7XjZaSZNSMP11TC 9XtFVgzhVljOfJC9I1UxKZWd21KTQyRFcfU8CU0xVbrDxiHJtyqbktiFM4RALU20ifvw 6UdpXaeOO/7Nnqkm7NfwRXyivPwBuKfbOB4J7dufk8kz3qkx9pkADfXb7eGrYdEP/ODB tOcQ== X-Forwarded-Encrypted: i=1; AJvYcCWKUBqW7iqhDY3LK+BpdzwdOy17aHxNni2Oi6HQQYhniHs6+uRm8BNZV0olF6TWPG4AAvXQiqqmTa7b1rw=@vger.kernel.org X-Gm-Message-State: AOJu0YwSQ7tsZipgk4KWRmc3hnl+KkJDId/PP62DeNFRJOG2zuYGCC+p 7dIiVTpbBl9UaZt7L8KhsMxDI9BW3XDHg7bzTScyW42UBC1juJw9nsuPBCbvdMjADQ== X-Gm-Gg: ATEYQzzimqW+MgsMB7WW9L5QaiPkvqR5U4Gony4gs5ijevYEyqmK9hHDonaYON217mt CFeLNdS6OOh6yGJQjlcsMl7Dm+qjA6Mc44Xx1oOJIcpKYp7UT7hvaea6eR0X9tQMWwTTXw8/rc1 3mXYGpWDgFoMV7ZVmF7z4pq4hGK76sn7BfcqjfeW/ANjvLq05/F7hPReptEpVdad1SD3WhkkPTx FZaoCXO/iGozFKlsU4Db/6PBMzQWs+fHRxILqEDUs/9C4Lxbfnvmcp6iO6rlmI1FzLeAN2vRZN6 JYxb5brKkndEkfrv4ZmNLrnB4y7A4gq2YCwkafojiyiZi/yIvqTlsdnkdGphxIaQ5RcukJglzXV 5Z0ivEE+kb0fsCxaw9SCWVwPYDqVECMQ851bTknCRqaRz/AWwlVb3/zLtiSp8kwjD3Ob4+2/Pqz EZx9AkhzMVnEaSiIMIiTABbw5i2zpP9W7ymEpN4MZ+LE2ZtMDxB1Uf71bIAPnSOYOlUE7EHe+Cs Z6FUxCSs69n X-Received: by 2002:a05:6512:3c8f:b0:5a1:378c:11e5 with SMTP id 2adb3069b0e04-5a27969db57mr2133771e87.14.1773865435438; Wed, 18 Mar 2026 13:23:55 -0700 (PDT) Received: from ribalda.c.googlers.com.com (252.116.88.34.bc.googleusercontent.com. [34.88.116.252]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a279c2fbbfsm765472e87.30.2026.03.18.13.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 13:23:54 -0700 (PDT) From: Ricardo Ribalda To: Laurent Pinchart , Hans de Goede , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ricardo Ribalda Subject: [PATCH] media: uvcvideo: Add a stream backpointer in uvc_video_queue Date: Wed, 18 Mar 2026 20:22:36 +0000 Message-ID: <20260318202352.1374443-1-ribalda@chromium.org> X-Mailer: git-send-email 2.53.0.983.g0bb29b3bc5-goog In-Reply-To: <20260318192357.GD718539@killaraus.ideasonboard.com> References: <20260318192357.GD718539@killaraus.ideasonboard.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It is less prone to errors if we add a backpointer to stream from struct uvc_video_queue. Refactor the code. Suggested-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Reviewed-by: Laurent Pinchart --- Tested in real hardware with yavta: (console A) # yavta -c /dev/video1=20 (console B) # yavta -c /dev/video0 It would be great if we add it as a follow-up patch to the already merged series. Thanks! drivers/media/usb/uvc/uvc_driver.c | 2 +- drivers/media/usb/uvc/uvc_isight.c | 3 +-- drivers/media/usb/uvc/uvc_queue.c | 15 ++++++++------- drivers/media/usb/uvc/uvcvideo.h | 12 +++--------- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc= _driver.c index b0ca81d924b6..017b1f4ae3ab 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -2033,7 +2033,7 @@ int uvc_register_video_device(struct uvc_device *dev, int ret; =20 /* Initialize the video buffers queue. */ - ret =3D uvc_queue_init(queue, type); + ret =3D uvc_queue_init(stream, queue, type); if (ret) return ret; =20 diff --git a/drivers/media/usb/uvc/uvc_isight.c b/drivers/media/usb/uvc/uvc= _isight.c index ea9dc31dfbad..bb3e13c0d5a6 100644 --- a/drivers/media/usb/uvc/uvc_isight.c +++ b/drivers/media/usb/uvc/uvc_isight.c @@ -41,8 +41,7 @@ static int isight_decode(struct uvc_video_queue *queue, s= truct uvc_buffer *buf, 0xde, 0xad, 0xfa, 0xce }; =20 - struct uvc_streaming *stream =3D uvc_queue_to_stream(queue, - V4L2_BUF_TYPE_VIDEO_CAPTURE); + struct uvc_streaming *stream =3D queue->stream; unsigned int maxlen, nbytes; u8 *mem; int is_header =3D 0; diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_= queue.c index 89206f761006..3c002c8f442f 100644 --- a/drivers/media/usb/uvc/uvc_queue.c +++ b/drivers/media/usb/uvc/uvc_queue.c @@ -78,7 +78,7 @@ static int uvc_queue_setup(struct vb2_queue *vq, unsigned int sizes[], struct device *alloc_devs[]) { struct uvc_video_queue *queue =3D vb2_get_drv_priv(vq); - struct uvc_streaming *stream =3D uvc_queue_to_stream(queue, vq->type); + struct uvc_streaming *stream =3D queue->stream; unsigned int size; =20 switch (vq->type) { @@ -112,7 +112,7 @@ static int uvc_buffer_prepare(struct vb2_buffer *vb) =20 if (vb->type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT && vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0)) { - uvc_dbg(uvc_queue_to_stream(queue, vb->type)->dev, CAPTURE, + uvc_dbg(queue->stream->dev, CAPTURE, "[E] Bytes used out of bounds\n"); return -EINVAL; } @@ -159,17 +159,16 @@ static void uvc_buffer_finish(struct vb2_buffer *vb) { struct vb2_v4l2_buffer *vbuf =3D to_vb2_v4l2_buffer(vb); struct uvc_video_queue *queue =3D vb2_get_drv_priv(vb->vb2_queue); - struct uvc_streaming *stream =3D uvc_queue_to_stream(queue, vb->type); struct uvc_buffer *buf =3D uvc_vbuf_to_buffer(vbuf); =20 if (vb->state =3D=3D VB2_BUF_STATE_DONE) - uvc_video_clock_update(stream, vbuf, buf); + uvc_video_clock_update(queue->stream, vbuf, buf); } =20 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, vq->type); + struct uvc_streaming *stream =3D queue->stream; int ret; =20 lockdep_assert_irqs_enabled(); @@ -196,7 +195,7 @@ 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, vq->type); + struct uvc_streaming *stream =3D queue->stream; =20 lockdep_assert_irqs_enabled(); =20 @@ -237,10 +236,12 @@ static const struct vb2_ops uvc_meta_queue_qops =3D { .stop_streaming =3D uvc_stop_streaming_meta, }; =20 -int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type) +int uvc_queue_init(struct uvc_streaming *stream, struct uvc_video_queue *q= ueue, + enum v4l2_buf_type type) { int ret; =20 + queue->stream =3D stream; queue->queue.type =3D type; queue->queue.io_modes =3D VB2_MMAP | VB2_USERPTR | VB2_DMABUF; queue->queue.drv_priv =3D queue; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.h index 5ba698d2a23d..0a0c01b2420f 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -331,6 +331,7 @@ struct uvc_buffer { #define UVC_QUEUE_DISCONNECTED (1 << 0) =20 struct uvc_video_queue { + struct uvc_streaming *stream; struct video_device vdev; struct vb2_queue queue; struct mutex mutex; /* @@ -692,7 +693,8 @@ do { \ 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); +int uvc_queue_init(struct uvc_streaming *stream, struct uvc_video_queue *q= ueue, + 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); @@ -703,14 +705,6 @@ static inline int uvc_queue_streaming(struct uvc_video= _queue *queue) return vb2_is_streaming(&queue->queue); } =20 -static inline struct uvc_streaming * -uvc_queue_to_stream(struct uvc_video_queue *queue, unsigned int type) -{ - if (type =3D=3D V4L2_BUF_TYPE_META_CAPTURE) - return container_of(queue, struct uvc_streaming, meta.queue); - return container_of(queue, struct uvc_streaming, queue); -} - /* V4L2 interface */ extern const struct v4l2_ioctl_ops uvc_ioctl_ops; extern const struct v4l2_file_operations uvc_fops; --=20 2.53.0.983.g0bb29b3bc5-goog