FreeBSD/sys/kern/subr_bus.c
/**
 * @brief Delete a device
 *
 * This function deletes a device along with all of its children. If
 * the device currently has a driver attached to it, the device is
 * detached first using device_detach().
 *
 * @param dev		the parent device
 * @param child		the device to delete
 *
 * @retval 0		success
 * @retval non-zero	a unit error code describing the error
 */
@brief Delete a device
This function deletes a device along with all of its children. If
the device currently has a driver attached to it, the device is
detached first using device_detach().

@param dev           the parent device
@param child         the device to delete

@retval 0            success
@retval non-zero     a unit error code describing the error
@brief Delete a device This function deletes a device along with all of its children . If the device currently has a driver attached to it the device is detached first using device_detach () . @param dev the parent device @param child the device to delete @retval 0 success @retval non - zero a unit error code describing the error
int
device_delete_child(device_t dev, device_t child)
{
	int error;
	device_t grandchild;
	PDEBUG(("%s from %s", DEVICENAME(child), DEVICENAME(dev)));
	while ((grandchild = TAILQ_FIRST(&child->children)) != NULL) {
		error = device_delete_child(child, grandchild);
		if (error)
			return (error);
	}
	if ((error = device_detach(child)) != 0)
		return (error);
	if (child->devclass)
		devclass_delete_device(child->devclass, child);
	if (child->parent)
		BUS_CHILD_DELETED(dev, child);
	TAILQ_REMOVE(&dev->children, child, link);
	TAILQ_REMOVE(&bus_data_devices, child, devlink);
	kobj_delete((kobj_t) child, M_BUS);
	bus_data_generation_update();
	return (0);
}
int device_delete_child ( device_t dev , device_t child ) { int error ; device_t grandchild ; PDEBUG ( ( " " , DEVICENAME ( child ) , DEVICENAME ( dev ) ) ) ; while ( ( grandchild = TAILQ_FIRST ( & child -> children ) ) != NULL ) { error = device_delete_child ( child , grandchild ) ; if ( error ) return ( error ) ; } if ( ( error = device_detach ( child ) ) != 0 ) return ( error ) ; if ( child -> devclass ) devclass_delete_device ( child -> devclass , child ) ; if ( child -> parent ) BUS_CHILD_DELETED ( dev , child ) ; TAILQ_REMOVE ( & dev -> children , child , link ) ; TAILQ_REMOVE ( & bus_data_devices , child , devlink ) ; kobj_delete ( ( kobj_t ) child , M_BUS ) ; bus_data_generation_update ( ) ; return ( 0 ) ; }
@brief Delete a device
 This function deletes a device along with all of its children.
@brief Delete a device This function deletes a device along with all of its children .
/* remove children first */