From 47d67d245151d173b124a9f3aaed40e9ed7a9bda Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Sat, 17 Feb 2018 23:23:27 +0000 Subject: [PATCH] Do not try to deallocate memory that wasn't allocated (you'd think that would be safe, but the function also tries to destroy mutexes that never got created). I guess this can only happen when imx_ehci_detach() is called on the error-exit path from imx_ehci_attach(), and that path never got exercised before today. --- sys/dev/usb/controller/ehci_imx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/dev/usb/controller/ehci_imx.c b/sys/dev/usb/controller/ehci_imx.c index c116cb9b31e..20d04084524 100644 --- a/sys/dev/usb/controller/ehci_imx.c +++ b/sys/dev/usb/controller/ehci_imx.c @@ -268,6 +268,7 @@ 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[] = { @@ -331,7 +332,8 @@ imx_ehci_detach(device_t dev) bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->ehci_mem_res); - usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc); + 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); @@ -413,6 +415,7 @@ imx_ehci_attach(device_t dev) err = ENOMEM; goto out; } + sc->usb_mem_allocated = true; /* * Set handle to USB related registers subregion used by