Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jan 2016 08:32:11 +0000 (UTC)
From:      =?UTF-8?Q?Jean-S=c3=a9bastien_P=c3=a9dron?= <dumbbell@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r294490 - stable/10/sys/dev/iicbus
Message-ID:  <201601210832.u0L8WBJU035424@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dumbbell
Date: Thu Jan 21 08:32:11 2016
New Revision: 294490
URL: https://svnweb.freebsd.org/changeset/base/294490

Log:
  iicbus: Use device_delete_children() instead of explicit child removal
  
  If the bus is detached and deleted by a call to device_delete_child() or
  device_delete_children() on a device higher in the tree, I²C children
  were already detached and deleted. So the device_t pointer stored in sc
  points to freed memory: we must not try to delete it again.
  
  By using device_delete_children(), we let subr_bus.c figure out if there
  are children to take care of.
  
  While here, make sure iicbus_detach() and iicoc_detach() call
  device_delete_children() too, to be safe.
  
  Reviewed by:	jhb, imp
  Approved by:	jhb, imp
  Differential Revision:	https://reviews.freebsd.org/D3926

Modified:
  stable/10/sys/dev/iicbus/iicbb.c
  stable/10/sys/dev/iicbus/iicbus.c
  stable/10/sys/dev/iicbus/iicoc.c
  stable/10/sys/dev/iicbus/iicsmb.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/iicbus/iicbb.c
==============================================================================
--- stable/10/sys/dev/iicbus/iicbb.c	Thu Jan 21 08:24:54 2016	(r294489)
+++ stable/10/sys/dev/iicbus/iicbb.c	Thu Jan 21 08:32:11 2016	(r294490)
@@ -149,22 +149,9 @@ iicbb_attach(device_t dev)
 static int
 iicbb_detach(device_t dev)
 {
-	struct iicbb_softc *sc = (struct iicbb_softc *)device_get_softc(dev);
-	device_t child;
 
-	/*
-	 * We need to save child because the detach indirectly causes
-	 * sc->iicbus to be zeroed.  Since we added the device
-	 * unconditionally in iicbb_attach, we need to make sure we
-	 * delete it here.  See iicbb_child_detached.  We need that
-	 * callback in case newbus detached our children w/o detaching
-	 * us (say iicbus is a module and unloaded w/o iicbb being
-	 * unloaded).
-	 */
-	child = sc->iicbus;
 	bus_generic_detach(dev);
-	if (child)
-		device_delete_child(dev, child);
+	device_delete_children(dev);
 
 	return (0);
 }

Modified: stable/10/sys/dev/iicbus/iicbus.c
==============================================================================
--- stable/10/sys/dev/iicbus/iicbus.c	Thu Jan 21 08:24:54 2016	(r294489)
+++ stable/10/sys/dev/iicbus/iicbus.c	Thu Jan 21 08:32:11 2016	(r294490)
@@ -134,6 +134,7 @@ iicbus_detach(device_t dev)
 
 	iicbus_reset(dev, IIC_FASTEST, 0, NULL);
 	bus_generic_detach(dev);
+	device_delete_children(dev);
 	mtx_destroy(&sc->lock);
 	return (0);
 }

Modified: stable/10/sys/dev/iicbus/iicoc.c
==============================================================================
--- stable/10/sys/dev/iicbus/iicoc.c	Thu Jan 21 08:24:54 2016	(r294489)
+++ stable/10/sys/dev/iicbus/iicoc.c	Thu Jan 21 08:32:11 2016	(r294490)
@@ -229,6 +229,7 @@ static int
 iicoc_detach(device_t dev)
 {
 	bus_generic_detach(dev);
+	device_delete_children(dev);
 
 	return (0);
 }

Modified: stable/10/sys/dev/iicbus/iicsmb.c
==============================================================================
--- stable/10/sys/dev/iicbus/iicsmb.c	Thu Jan 21 08:24:54 2016	(r294489)
+++ stable/10/sys/dev/iicbus/iicsmb.c	Thu Jan 21 08:32:11 2016	(r294490)
@@ -167,11 +167,9 @@ static int
 iicsmb_detach(device_t dev)
 {
 	struct iicsmb_softc *sc = (struct iicsmb_softc *)device_get_softc(dev);
-	
+
 	bus_generic_detach(dev);
-	if (sc->smbus) {
-		device_delete_child(dev, sc->smbus);
-	}
+	device_delete_children(dev);
 	mtx_destroy(&sc->lock);
 
 	return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601210832.u0L8WBJU035424>