Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb During detach, re-use the functions that halt pl...



details:   https://anonhg.NetBSD.org/src/rev/7c9df9a6dcc4
branches:  trunk
changeset: 948697:7c9df9a6dcc4
user:      jdc <jdc%NetBSD.org@localhost>
date:      Tue Dec 29 08:04:59 2020 +0000

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

diffstat:

 sys/dev/usb/uaudio.c |  35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diffs (92 lines):

diff -r de445eebac33 -r 7c9df9a6dcc4 sys/dev/usb/uaudio.c
--- a/sys/dev/usb/uaudio.c      Tue Dec 29 08:00:48 2020 +0000
+++ b/sys/dev/usb/uaudio.c      Tue Dec 29 08:04:59 2020 +0000
@@ -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 @@
         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 @@
        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 @@
        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 @@
        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



Home | Main Index | Thread Index | Old Index