diff --git a/sys/dev/sound/usb/uaudio.c b/sys/dev/sound/usb/uaudio.c index a14cdf805353..06e2bd85cb88 100644 --- a/sys/dev/sound/usb/uaudio.c +++ b/sys/dev/sound/usb/uaudio.c @@ -1243,6 +1243,11 @@ uaudio_detach_sub(device_t dev) struct uaudio_softc *sc = device_get_softc(device_get_parent(dev)); unsigned i = uaudio_get_child_index_by_dev(sc, dev); int error = 0; + struct snddev_info *d; + struct pcm_channel *ch; + struct proc *p; + + d = device_get_softc(dev); repeat: if (sc->sc_child[i].pcm_registered) { @@ -1255,6 +1260,20 @@ uaudio_detach_sub(device_t dev) if (error) { device_printf(dev, "Waiting for sound application to exit!\n"); usb_pause_mtx(NULL, 2 * hz); + /* try to kill pid before repeating */ + + CHN_FOREACH(ch, d, channels.pcm) { + CHN_LOCK(ch); + if (ch->refcount > 0) { + device_printf(dev, "unregister attempt to kill " + " pid %d\n", ch->pid); + if ((p = pfind(ch->pid)) != NULL) { + kern_psignal(p, SIGKILL); + PROC_UNLOCK(p); + } + } + CHN_UNLOCK(ch); + } goto repeat; /* try again */ } return (0); /* success */