Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jun 2012 12:56:10 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r236752 - in stable/8/sys: kern sys
Message-ID:  <201206081256.q58CuASe060279@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Fri Jun  8 12:56:10 2012
New Revision: 236752
URL: http://svn.freebsd.org/changeset/base/236752

Log:
  Partially MFC r227701, r227847 and r227849 (by hselasky):
  Provide new device_delete_children() KPI without touching all consumers.

Modified:
  stable/8/sys/kern/subr_bus.c
  stable/8/sys/sys/bus.h

Modified: stable/8/sys/kern/subr_bus.c
==============================================================================
--- stable/8/sys/kern/subr_bus.c	Fri Jun  8 12:36:08 2012	(r236751)
+++ stable/8/sys/kern/subr_bus.c	Fri Jun  8 12:56:10 2012	(r236752)
@@ -1897,7 +1897,7 @@ device_delete_child(device_t dev, device
 	PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev)));
 
 	/* remove children first */
-	while ( (grandchild = TAILQ_FIRST(&child->children)) ) {
+	while ((grandchild = TAILQ_FIRST(&child->children)) != NULL) {
 		error = device_delete_child(child, grandchild);
 		if (error)
 			return (error);
@@ -1916,6 +1916,39 @@ device_delete_child(device_t dev, device
 }
 
 /**
+ * @brief Delete all children devices of the given device, if any.
+ *
+ * This function deletes all children devices of the given device, if
+ * any, using the device_delete_child() function for each device it
+ * finds. If a child device cannot be deleted, this function will
+ * return an error code.
+ * 
+ * @param dev		the parent device
+ *
+ * @retval 0		success
+ * @retval non-zero	a device would not detach
+ */
+int
+device_delete_children(device_t dev)
+{
+	device_t child;
+	int error;
+
+	PDEBUG(("Deleting all children of %s", DEVICENAME(dev)));
+
+	error = 0;
+
+	while ((child = TAILQ_FIRST(&dev->children)) != NULL) {
+		error = device_delete_child(dev, child);
+		if (error) {
+			PDEBUG(("Failed deleting %s", DEVICENAME(child)));
+			break;
+		}
+	}
+	return (error);
+}
+
+/**
  * @brief Find a device given a unit number
  *
  * This is similar to devclass_get_devices() but only searches for

Modified: stable/8/sys/sys/bus.h
==============================================================================
--- stable/8/sys/sys/bus.h	Fri Jun  8 12:36:08 2012	(r236751)
+++ stable/8/sys/sys/bus.h	Fri Jun  8 12:56:10 2012	(r236752)
@@ -407,6 +407,7 @@ device_t	device_add_child_ordered(device
 					 const char *name, int unit);
 void	device_busy(device_t dev);
 int	device_delete_child(device_t dev, device_t child);
+int	device_delete_children(device_t dev);
 int	device_attach(device_t dev);
 int	device_detach(device_t dev);
 void	device_disable(device_t dev);



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