FreeBSD/sys/kern/subr_bus.c
/**
 * @brief Detach a driver from a device
 *
 * This function is a wrapper around the DEVICE_DETACH() driver
 * method. If the call to DEVICE_DETACH() succeeds, it calls
 * BUS_CHILD_DETACHED() for the parent of @p dev, queues a
 * notification event for user-based device management services and
 * cleans up the device's sysctl tree.
 *
 * @param dev		the device to un-initialise
 *
 * @retval 0		success
 * @retval ENXIO	no driver was found
 * @retval ENOMEM	memory allocation failure
 * @retval non-zero	some other unix error code
 */
@brief Detach a driver from a device
This function is a wrapper around the DEVICE_DETACH() driver
method. If the call to DEVICE_DETACH() succeeds, it calls
BUS_CHILD_DETACHED() for the parent of @p dev, queues a
notification event for user-based device management services and
cleans up the device's sysctl tree.

@param dev           the device to un-initialise

@retval 0            success
@retval ENXIO        no driver was found
@retval ENOMEM       memory allocation failure
@retval non-zero     some other unix error code
@brief Detach a driver from a device This function is a wrapper around the DEVICE_DETACH () driver method . If the call to DEVICE_DETACH () succeeds it calls BUS_CHILD_DETACHED () for the parent of @p dev queues a notification event for user - based device management services and cleans up the device ' s sysctl tree . @param dev the device to un - initialise @retval 0 success @retval ENXIO no driver was found @retval ENOMEM memory allocation failure @retval non - zero some other unix error code
int
device_detach(device_t dev)
{
	int error;
	GIANT_REQUIRED;
	PDEBUG(("%s", DEVICENAME(dev)));
	if (dev->state == DS_BUSY)
		return (EBUSY);
	if (dev->state != DS_ATTACHED)
		return (0);
	if ((error = DEVICE_DETACH(dev)) != 0)
		return (error);
	devremoved(dev);
	if (!device_is_quiet(dev))
		device_printf(dev, "detached\n");
	if (dev->parent)
		BUS_CHILD_DETACHED(dev->parent, dev);
	if (!(dev->flags & DF_FIXEDCLASS))
		devclass_delete_device(dev->devclass, dev);
	dev->state = DS_NOTPRESENT;
	(void)device_set_driver(dev, NULL);
	device_sysctl_fini(dev);
	return (0);
}
int device_detach ( device_t dev ) { int error ; GIANT_REQUIRED ; PDEBUG ( ( " " , DEVICENAME ( dev ) ) ) ; if ( dev -> state == DS_BUSY ) return ( EBUSY ) ; if ( dev -> state != DS_ATTACHED ) return ( 0 ) ; if ( ( error = DEVICE_DETACH ( dev ) ) != 0 ) return ( error ) ; devremoved ( dev ) ; if ( ! device_is_quiet ( dev ) ) device_printf ( dev , " \n " ) ; if ( dev -> parent ) BUS_CHILD_DETACHED ( dev -> parent , dev ) ; if ( ! ( dev -> flags & DF_FIXEDCLASS ) ) devclass_delete_device ( dev -> devclass , dev ) ; dev -> state = DS_NOTPRESENT ; ( void ) device_set_driver ( dev , NULL ) ; device_sysctl_fini ( dev ) ; return ( 0 ) ; }
@brief Detach a driver from a device
 This function is a wrapper around the DEVICE_DETACH() driver
 method.
@brief Detach a driver from a device This function is a wrapper around the DEVICE_DETACH () driver method .