Index: sys/dev/usb/ucom.c =================================================================== RCS file: /cvsroot/src/sys/dev/usb/ucom.c,v retrieving revision 1.112 diff -n -u -r1.112 ucom.c --- sys/dev/usb/ucom.c 10 May 2016 10:40:33 -0000 1.112 +++ sys/dev/usb/ucom.c 14 May 2016 10:22:03 -0000 @@ -174,6 +174,7 @@ int sc_swflags; u_char sc_opening; /* lock during open */ + u_char sc_closing; /* lock during close */ int sc_refcnt; u_char sc_dying; /* disconnecting */ @@ -282,6 +283,7 @@ sc->sc_tx_stopped = 0; sc->sc_swflags = 0; sc->sc_opening = 0; + sc->sc_closing = 0; sc->sc_refcnt = 0; sc->sc_dying = 0; @@ -542,9 +544,10 @@ } /* - * Do the following iff this is a first open. + * Wait while the device is initialized by the + * first opener or cleaned up by the last closer. */ - while (sc->sc_opening) { + while (sc->sc_opening || sc->sc_closing) { error = cv_wait_sig(&sc->sc_opencv, &sc->sc_lock); if (error) { @@ -681,6 +684,8 @@ mutex_enter(&sc->sc_lock); tp = sc->sc_tty; + sc->sc_closing = 1; + if (!ISSET(tp->t_state, TS_ISOPEN)) { goto out; } @@ -706,6 +711,9 @@ usb_detach_broadcast(sc->sc_dev, &sc->sc_detachcv); out: + sc->sc_closing = 0; + cv_signal(&sc->sc_opencv); + mutex_exit(&sc->sc_lock); return 0;