From 8dafe54adcd775a216b17d85b80b81947967fb86 Mon Sep 17 00:00:00 2001 From: mpi Date: Thu, 18 Dec 2014 10:44:17 +0000 Subject: [PATCH] If a host controller has been detached or reported a halt condition it should be considered as dead. In such condition the stack no longer submits I/O or schedules any USB task for its bus. However we need an explore task to detach the root hub since only the task thread is supposed to discover buses and attach/detach devices in order to avoid races. So reset the bus' dying flag when marking it as disconnecting in order to let the task be scheduled. This should be safe because a detached or halted HC should not trigger any new interrupt. Fix a panic when detaching USB PCMCIA cards reported by Tilo Stritzky. --- sys/dev/usb/usb.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/dev/usb/usb.c b/sys/dev/usb/usb.c index ef99af42c9e..ab8ce995603 100644 --- a/sys/dev/usb/usb.c +++ b/sys/dev/usb/usb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: usb.c,v 1.102 2014/08/10 11:18:57 mpi Exp $ */ +/* $OpenBSD: usb.c,v 1.103 2014/12/18 10:44:17 mpi Exp $ */ /* $NetBSD: usb.c,v 1.77 2003/01/01 00:10:26 thorpej Exp $ */ /* @@ -262,6 +262,13 @@ usb_detach_roothub(struct usb_softc *sc) * it. */ sc->sc_bus->flags |= USB_BUS_DISCONNECTING; + /* + * Reset the dying flag in case it has been set by the interrupt + * handler when unplugging an HC card otherwise the task wont be + * scheduled. This is safe since a dead HC should not trigger + * new interrupt. + */ + sc->sc_bus->dying = 0; usb_needs_explore(sc->sc_bus->root_hub, 0); usb_wait_task(sc->sc_bus->root_hub, &sc->sc_explore_task); -- 2.20.1