Module Name:    src
Committed By:   jdc
Date:           Tue Dec 29 08:04:59 UTC 2020

Modified Files:
        src/sys/dev/usb: uaudio.c

Log Message:
During detach, re-use the functions that halt playback and record DMA.
Prevents a panic during shutdown when media is playing.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/dev/usb/uaudio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/uaudio.c
diff -u src/sys/dev/usb/uaudio.c:1.165 src/sys/dev/usb/uaudio.c:1.166
--- src/sys/dev/usb/uaudio.c:1.165	Sat Mar 14 02:35:33 2020
+++ src/sys/dev/usb/uaudio.c	Tue Dec 29 08:04:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: uaudio.c,v 1.165 2020/03/14 02:35:33 christos Exp $	*/
+/*	$NetBSD: uaudio.c,v 1.166 2020/12/29 08:04:59 jdc Exp $	*/
 
 /*
  * Copyright (c) 1999, 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.165 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uaudio.c,v 1.166 2020/12/29 08:04:59 jdc Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -343,6 +343,8 @@ Static int	uaudio_trigger_input
 	 const audio_params_t *);
 Static int	uaudio_halt_in_dma(void *);
 Static int	uaudio_halt_out_dma(void *);
+Static void	uaudio_halt_in_dma_unlocked(struct uaudio_softc *);
+Static void	uaudio_halt_out_dma_unlocked(struct uaudio_softc *);
 Static int	uaudio_getdev(void *, struct audio_device *);
 Static int	uaudio_mixer_set_port(void *, mixer_ctrl_t *);
 Static int	uaudio_mixer_get_port(void *, mixer_ctrl_t *);
@@ -519,10 +521,13 @@ uaudio_detach(device_t self, int flags)
 	struct uaudio_softc *sc = device_private(self);
 	int rv = 0;
 
+	sc->sc_dying = 1;
+
 	pmf_device_deregister(self);
 
 	/* Wait for outstanding requests to complete. */
-	usbd_delay_ms(sc->sc_udev, UAUDIO_NCHANBUFS * UAUDIO_NFRAMES);
+	uaudio_halt_out_dma_unlocked(sc);
+	uaudio_halt_in_dma_unlocked(sc);
 
 	if (sc->sc_audiodev != NULL)
 		rv = config_detach(sc->sc_audiodev, flags);
@@ -2167,15 +2172,21 @@ uaudio_halt_out_dma(void *addr)
 	DPRINTF("%s", "enter\n");
 
 	mutex_exit(&sc->sc_intr_lock);
+	uaudio_halt_out_dma_unlocked(sc);
+	mutex_enter(&sc->sc_intr_lock);
+
+	return 0;
+}
+
+Static void
+uaudio_halt_out_dma_unlocked(struct uaudio_softc *sc)
+{
 	if (sc->sc_playchan.pipe != NULL) {
 		uaudio_chan_abort(sc, &sc->sc_playchan);
 		uaudio_chan_free_buffers(sc, &sc->sc_playchan);
 		uaudio_chan_close(sc, &sc->sc_playchan);
 		sc->sc_playchan.intr = NULL;
 	}
-	mutex_enter(&sc->sc_intr_lock);
-
-	return 0;
 }
 
 Static int
@@ -2186,15 +2197,21 @@ uaudio_halt_in_dma(void *addr)
 	DPRINTF("%s", "enter\n");
 
 	mutex_exit(&sc->sc_intr_lock);
+	uaudio_halt_in_dma_unlocked(sc);
+	mutex_enter(&sc->sc_intr_lock);
+
+	return 0;
+}
+
+Static void
+uaudio_halt_in_dma_unlocked(struct uaudio_softc *sc)
+{
 	if (sc->sc_recchan.pipe != NULL) {
 		uaudio_chan_abort(sc, &sc->sc_recchan);
 		uaudio_chan_free_buffers(sc, &sc->sc_recchan);
 		uaudio_chan_close(sc, &sc->sc_recchan);
 		sc->sc_recchan.intr = NULL;
 	}
-	mutex_enter(&sc->sc_intr_lock);
-
-	return 0;
 }
 
 Static int

Reply via email to