Index | Thread | Search

From:
Marcus Glocker <marcus@nazgul.ch>
Subject:
Re: sys/uvideo: fix crash on close isochronous endpoint's webcam
To:
"Kirill A. Korinsky" <kirill@korins.ky>
Cc:
tech@openbsd.org
Date:
Fri, 7 Mar 2025 21:39:30 +0100

Download raw body.

Thread
On Thu, Mar 06, 2025 at 09:12:55AM GMT, Kirill A. Korinsky wrote:

> tech@,
> 
> I'd like to fix a crash in uvide when I detach my Elgato webcam when
> it's streamming.
> 
> uvideo_vs_close is called from videoclose and by VIDIOC_STREAMOFF. When
> it's happened on detached webcam with isochronous endpoint, the system
> crashes inside usbd_set_interface.
> 
> Ok?

Usually we're using usbd_is_dying() to return from a function at the
very beginning.  Would it also work in your case to return from
uvideo_vs_close() at the very beginning instead of only wrapping it
around usbd_set_interface()?
 
> Index: sys/dev/usb/uvideo.c
> ===================================================================
> RCS file: /home/cvs/src/sys/dev/usb/uvideo.c,v
> diff -u -p -r1.249 uvideo.c
> --- sys/dev/usb/uvideo.c	4 Mar 2025 22:59:01 -0000	1.249
> +++ sys/dev/usb/uvideo.c	5 Mar 2025 22:40:46 -0000
> @@ -2169,8 +2163,9 @@ uvideo_vs_close(struct uvideo_softc *sc)
>  		 */
>  		usbd_delay_ms(sc->sc_udev, 100);
>  
> -		/* switch back to default interface (turns off cam LED) */
> -		(void)usbd_set_interface(sc->sc_vs_cur->ifaceh, 0);
> +		if (!usbd_is_dying(sc->sc_udev))
> +			/* switch back to default interface (turns off cam LED) */
> +			(void)usbd_set_interface(sc->sc_vs_cur->ifaceh, 0);
>  	}
>  }
>  
>