svn commit: r329479 - head/sys/dev/usb/controller

Ian Lepore ian at FreeBSD.org
Sat Feb 17 23:23:27 UTC 2018


Author: ian
Date: Sat Feb 17 23:23:27 2018
New Revision: 329479
URL: https://svnweb.freebsd.org/changeset/base/329479

Log:
  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.

Modified:
  head/sys/dev/usb/controller/ehci_imx.c

Modified: head/sys/dev/usb/controller/ehci_imx.c
==============================================================================
--- head/sys/dev/usb/controller/ehci_imx.c	Sat Feb 17 23:05:19 2018	(r329478)
+++ head/sys/dev/usb/controller/ehci_imx.c	Sat Feb 17 23:23:27 2018	(r329479)
@@ -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


More information about the svn-src-head mailing list