From e9da4d1a66332b8407fdafea85104843c00052dc Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Thu, 3 Feb 2022 22:44:35 +0000 Subject: [PATCH 10/13] fixup! ucom(4): Rework open/close/attach/detach logic. --- sys/dev/usb/ucom.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/dev/usb/ucom.c b/sys/dev/usb/ucom.c index 9dd654202f16..53aaeba9d2b6 100644 --- a/sys/dev/usb/ucom.c +++ b/sys/dev/usb/ucom.c @@ -798,10 +798,15 @@ ucomclose(dev_t dev, int flag, int mode, struct lwp *l) /* * We're now closed. Can reopen after this point, so resume * transfers, mark us no longer closing, and notify anyone - * waiting in open. + * waiting in open. The state may be OPEN or ATTACHED at this + * point -- OPEN if the device was already open when we closed + * it, ATTACHED if we interrupted it in the process of opening. */ mutex_enter(&sc->sc_lock); + KASSERTMSG(sc->sc_state == UCOM_ATTACHED || sc->sc_state == UCOM_OPEN, + "%s sc=%p state=%d", device_xname(sc->sc_dev), sc, sc->sc_state); KASSERT(sc->sc_closing); + sc->sc_state = UCOM_ATTACHED; sc->sc_closing = false; cv_broadcast(&sc->sc_statecv); mutex_exit(&sc->sc_lock);