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

Ian Lepore ian at FreeBSD.org
Thu Jul 5 16:00:59 UTC 2018


Author: ian
Date: Thu Jul  5 16:00:58 2018
New Revision: 335989
URL: https://svnweb.freebsd.org/changeset/base/335989

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

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	Thu Jul  5 15:52:26 2018	(r335988)
+++ head/sys/dev/usb/controller/ehci_imx.c	Thu Jul  5 16:00:58 2018	(r335989)
@@ -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,12 +334,8 @@ 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);
+	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);
-
 	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


More information about the svn-src-all mailing list