From 00c8d880f9dc8fc93a908966e6aa2d8fa9e97098 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 5 Jul 2018 16:00:58 +0000 Subject: [PATCH] Detach all children before beginning to tear down the hardware, instead of doing it last. Also, remove the local tracking of whether usb's busdma memory allocation got done, because it's safe to call the free_all function even if it wasn't. --- sys/dev/usb/controller/ehci_imx.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/sys/dev/usb/controller/ehci_imx.c b/sys/dev/usb/controller/ehci_imx.c index 20d040845243..3fa466357b24 100644 --- a/sys/dev/usb/controller/ehci_imx.c +++ b/sys/dev/usb/controller/ehci_imx.c @@ -268,7 +268,6 @@ struct imx_ehci_softc { device_t dev; struct resource *ehci_mem_res; /* EHCI core regs. */ struct resource *ehci_irq_res; /* EHCI core IRQ. */ - bool usb_mem_allocated; }; static struct ofw_compat_data compat_data[] = { @@ -313,13 +312,16 @@ imx_ehci_detach(device_t dev) { struct imx_ehci_softc *sc; ehci_softc_t *esc; + int err; sc = device_get_softc(dev); esc = &sc->ehci_softc; - if (esc->sc_bus.bdev != NULL) - device_delete_child(dev, esc->sc_bus.bdev); + /* First detach all children; we can't detach if that fails. */ + if ((err = device_delete_children(dev)) != 0) + return (err); + if (esc->sc_flags & EHCI_SCFLG_DONEINIT) ehci_detach(esc); if (esc->sc_intr_hdl != NULL) @@ -332,11 +334,7 @@ imx_ehci_detach(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->ehci_mem_res); - if (sc->usb_mem_allocated) - usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc); - - /* During module unload there are lots of children leftover */ - device_delete_children(dev); + usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc); return (0); } @@ -415,7 +413,6 @@ imx_ehci_attach(device_t dev) err = ENOMEM; goto out; } - sc->usb_mem_allocated = true; /* * Set handle to USB related registers subregion used by