FreeBSD/sys/kern/subr_bus.c
/**
 * @brief Find a device given a unit number
 *
 * This is similar to devclass_get_devices() but only searches for
 * devices which have @p dev as a parent.
 *
 * @param dev		the parent device to search
 * @param unit		the unit number to search for.  If the unit is -1,
 *			return the first child of @p dev which has name
 *			@p classname (that is, the one with the lowest unit.)
 *
 * @returns		the device with the given unit number or @c
 *			NULL if there is no such device
 */
@brief Find a device given a unit number
This is similar to devclass_get_devices() but only searches for
devices which have @p dev as a parent.

@param dev           the parent device to search
@param unit          the unit number to search for.  If the unit is -1,
return the first child of @p dev which has name
@p classname (that is, the one with the lowest unit.)

@returns             the device with the given unit number or @c
NULL if there is no such device
@brief Find a device given a unit number This is similar to devclass_get_devices () but only searches for devices which have @p dev as a parent . @param dev the parent device to search @param unit the unit number to search for . If the unit is - 1 return the first child of @p dev which has name @p classname ( that is the one with the lowest unit . ) @returns the device with the given unit number or @c NULL if there is no such device
device_t
device_find_child(device_t dev, const char *classname, int unit)
{
	devclass_t dc;
	device_t child;
	dc = devclass_find(classname);
	if (!dc)
		return (NULL);
	if (unit != -1) {
		child = devclass_get_device(dc, unit);
		if (child && child->parent == dev)
			return (child);
	} else {
		for (unit = 0; unit < devclass_get_maxunit(dc); unit++) {
			child = devclass_get_device(dc, unit);
			if (child && child->parent == dev)
				return (child);
		}
	}
	return (NULL);
}
device_t device_find_child ( device_t dev , const char * classname , int unit ) { devclass_t dc ; device_t child ; dc = devclass_find ( classname ) ; if ( ! dc ) return ( NULL ) ; if ( unit != -1 ) { child = devclass_get_device ( dc , unit ) ; if ( child && child -> parent == dev ) return ( child ) ; } else { for ( unit = 0 ; unit < devclass_get_maxunit ( dc ) ; unit ++ ) { child = devclass_get_device ( dc , unit ) ; if ( child && child -> parent == dev ) return ( child ) ; } } return ( NULL ) ; }
@brief Find a device given a unit number
 This is similar to devclass_get_devices() but only searches for
 devices which have @p dev as a parent.
@brief Find a device given a unit number This is similar to devclass_get_devices () but only searches for devices which have @p dev as a parent .