public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Hans Verkuil <hans@jjverkuil.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hans de Goede <hansg@kernel.org>
Subject: Re: [PATCH v4 3/5] media: uvcvideo: Split uvc_stop_streaming()
Date: Mon, 30 Jun 2025 17:17:07 +0300	[thread overview]
Message-ID: <20250630141707.GG20333@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20250616-uvc-fop-v4-3-250286570ee7@chromium.org>

On Mon, Jun 16, 2025 at 03:24:40PM +0000, Ricardo Ribalda wrote:
> 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 <hansg@kernel.org>
> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
> ---
>  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..3f357c2d48cfd258c26f0342007d1d12f1e01007 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);
>  }
>  
> -static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
> +static int uvc_start_streaming_video(struct vb2_queue *vq, unsigned int count)
>  {
>  	struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
>  	struct uvc_streaming *stream = uvc_queue_to_stream(queue);
> @@ -186,14 +186,22 @@ static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
>  	return ret;
>  }
>  
> -static void uvc_stop_streaming(struct vb2_queue *vq)
> +static void uvc_stop_streaming_video(struct vb2_queue *vq)
>  {
>  	struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
>  
>  	lockdep_assert_irqs_enabled();
>  
> -	if (vq->type != 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 = vb2_get_drv_priv(vq);
> +
> +	lockdep_assert_irqs_enabled();
>  
>  	uvc_queue_return_buffers(queue, UVC_BUF_STATE_ERROR);

I haven't checked where it was introduced, but I think you have a race
here. uvc_queue_return_buffers() will return all buffers currently
sitting in the queue->irqqueue. This can race with a bunch of places in
uvc_video.c that call uvc_queue_get_current_buffer() or
uvc_queue_get_next_buffer(), as those functions return a buffer without
removing it from the list.

>  }
> @@ -203,15 +211,15 @@ static const struct vb2_ops uvc_queue_qops = {
>  	.buf_prepare = uvc_buffer_prepare,
>  	.buf_queue = uvc_buffer_queue,
>  	.buf_finish = uvc_buffer_finish,
> -	.start_streaming = uvc_start_streaming,
> -	.stop_streaming = uvc_stop_streaming,
> +	.start_streaming = uvc_start_streaming_video,
> +	.stop_streaming = uvc_stop_streaming_video,
>  };
>  
>  static const struct vb2_ops uvc_meta_queue_qops = {
>  	.queue_setup = uvc_queue_setup,
>  	.buf_prepare = uvc_buffer_prepare,
>  	.buf_queue = uvc_buffer_queue,
> -	.stop_streaming = uvc_stop_streaming,
> +	.stop_streaming = uvc_stop_streaming_meta,
>  };
>  
>  int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type)

-- 
Regards,

Laurent Pinchart

  parent reply	other threads:[~2025-06-30 14:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16 15:24 [PATCH v4 0/5] media: uvcvideo: use vb2 ioctl and fop helpers Ricardo Ribalda
2025-06-16 15:24 ` [PATCH v4 1/5] media: uvcvideo: Use " Ricardo Ribalda
2025-06-16 15:24 ` [PATCH v4 2/5] media: uvcvideo: Handle locks in uvc_queue_return_buffers Ricardo Ribalda
2025-06-17  9:21   ` Hans Verkuil
2025-06-16 15:24 ` [PATCH v4 3/5] media: uvcvideo: Split uvc_stop_streaming() Ricardo Ribalda
2025-06-17  9:27   ` Hans Verkuil
2025-06-30 12:59     ` Hans de Goede
2025-06-30 13:10       ` Laurent Pinchart
2025-06-30 13:12         ` Hans de Goede
2025-06-30 13:24           ` Laurent Pinchart
2025-06-30 13:26             ` Ricardo Ribalda
2025-06-30 14:17   ` Laurent Pinchart [this message]
2025-06-30 15:12     ` Hans de Goede
2025-06-30 15:24       ` Laurent Pinchart
2025-06-16 15:24 ` [PATCH v4 4/5] media: uvcvideo: Remove stream->is_streaming field Ricardo Ribalda
2025-06-17  9:29   ` Hans Verkuil
2025-06-16 15:24 ` [PATCH v4 5/5] media: uvcvideo: Use prio state from v4l2_device Ricardo Ribalda
2025-06-16 18:30   ` Ricardo Ribalda
2025-06-16 20:50     ` Hans de Goede
2025-06-17 10:07     ` Laurent Pinchart
2025-06-17 11:09       ` Ricardo Ribalda
2025-06-17 14:06         ` Laurent Pinchart
2025-06-17  9:35   ` Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250630141707.GG20333@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hans@jjverkuil.nl \
    --cc=hansg@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox