diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2011-11-19 10:11:50 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2011-11-19 10:11:50 +0000 |
commit | 11bcf702f4200a351f06b549e14bc9ea4fc76dcc (patch) | |
tree | d8ce224aa83a7409b55f7416386eadc3d984598d /sys/kern/subr_bus.c | |
parent | 76a869385c0c898a5815f16e4cc99ffc77d1f637 (diff) | |
download | src-11bcf702f4200a351f06b549e14bc9ea4fc76dcc.tar.gz src-11bcf702f4200a351f06b549e14bc9ea4fc76dcc.zip |
Move the device_delete_all_children() function from usb_util.c
to kern/subr_bus.c. Simplify this function so that it no longer
depends on malloc() to execute. Identify a few other places where
it makes sense to use device_delete_all_children().
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=227701
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r-- | sys/kern/subr_bus.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 4a36a8bae796..c337c78ace36 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1881,6 +1881,39 @@ device_delete_child(device_t dev, device_t child) } /** + * @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_all_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)) ) { + 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 |