linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: usbtv: Lock resolution while streaming
@ 2025-04-28 18:16 Ludwig Disterhof
  2025-06-17  8:05 ` Hans Verkuil
  0 siblings, 1 reply; 2+ messages in thread
From: Ludwig Disterhof @ 2025-04-28 18:16 UTC (permalink / raw)
  To: linux-media, linux-kernel; +Cc: mchehab, hverkuil

When an program is streaming (ffplay) and another program (qv4l2)
changes the TV standard from NTSC to PAL, the kernel crashes due to trying
to copy to unmapped memory.

Changing from NTSC to PAL increases the resolution in the usbtv struct,
but the video plane buffer isn't adjusted, so it overflows.

Fixes: 0e0fe3958fdd13d ("[media] usbtv: Add support for PAL video source")

Signed-off-by: Ludwig Disterhof <ludwig@disterhof.eu>
---
 drivers/media/usb/usbtv/usbtv-video.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
index be22a9697197..965a8ae82afe 100644
--- a/drivers/media/usb/usbtv/usbtv-video.c
+++ b/drivers/media/usb/usbtv/usbtv-video.c
@@ -73,6 +73,10 @@ static int usbtv_configure_for_norm(struct usbtv *usbtv, v4l2_std_id norm)
 	}
 
 	if (params) {
+		if (vb2_is_streaming(&usbtv->vb2q) &&
+		    (usbtv->width != params->cap_width ||
+		     usbtv->height != params->cap_height))
+			return -EBUSY;
 		usbtv->width = params->cap_width;
 		usbtv->height = params->cap_height;
 		usbtv->n_chunks = usbtv->width * usbtv->height
-- 
2.43.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: usbtv: Lock resolution while streaming
  2025-04-28 18:16 [PATCH] media: usbtv: Lock resolution while streaming Ludwig Disterhof
@ 2025-06-17  8:05 ` Hans Verkuil
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Verkuil @ 2025-06-17  8:05 UTC (permalink / raw)
  To: Ludwig Disterhof, linux-media, linux-kernel; +Cc: mchehab, hverkuil

Hi Ludwig,

I'm taking this patch, but with one change:

On 28/04/2025 20:16, Ludwig Disterhof wrote:
> When an program is streaming (ffplay) and another program (qv4l2)
> changes the TV standard from NTSC to PAL, the kernel crashes due to trying
> to copy to unmapped memory.
> 
> Changing from NTSC to PAL increases the resolution in the usbtv struct,
> but the video plane buffer isn't adjusted, so it overflows.
> 
> Fixes: 0e0fe3958fdd13d ("[media] usbtv: Add support for PAL video source")
> 
> Signed-off-by: Ludwig Disterhof <ludwig@disterhof.eu>
> ---
>  drivers/media/usb/usbtv/usbtv-video.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/media/usb/usbtv/usbtv-video.c b/drivers/media/usb/usbtv/usbtv-video.c
> index be22a9697197..965a8ae82afe 100644
> --- a/drivers/media/usb/usbtv/usbtv-video.c
> +++ b/drivers/media/usb/usbtv/usbtv-video.c
> @@ -73,6 +73,10 @@ static int usbtv_configure_for_norm(struct usbtv *usbtv, v4l2_std_id norm)
>  	}
>  
>  	if (params) {
> +		if (vb2_is_streaming(&usbtv->vb2q) &&

This should be vb2_is_busy(), not vb2_is_streaming().

is_busy() checks if buffers have been allocated since in that case you can't
make changes to the resolution until all buffers are released.

No need to do anything, I've made this change myself.

Regards,

	Hans

> +		    (usbtv->width != params->cap_width ||
> +		     usbtv->height != params->cap_height))
> +			return -EBUSY;
>  		usbtv->width = params->cap_width;
>  		usbtv->height = params->cap_height;
>  		usbtv->n_chunks = usbtv->width * usbtv->height


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-17  8:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28 18:16 [PATCH] media: usbtv: Lock resolution while streaming Ludwig Disterhof
2025-06-17  8:05 ` Hans Verkuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).