FreeBSD/sys/kern/subr_bus.c
/**
 * @brief Get a list of children of a device
 *
 * An array containing a list of all the children of the given device
 * is allocated and returned in @p *devlistp. The number of devices
 * in the array is returned in @p *devcountp. The caller should free
 * the array using @c free(p, M_TEMP).
 *
 * @param dev		the device to examine
 * @param devlistp	points at location for array pointer return
 *			value
 * @param devcountp	points at location for array size return value
 *
 * @retval 0		success
 * @retval ENOMEM	the array allocation failed
 */
@brief Get a list of children of a device
An array containing a list of all the children of the given device
is allocated and returned in @p *devlistp. The number of devices
in the array is returned in @p *devcountp. The caller should free
the array using @c free(p, M_TEMP).

@param dev           the device to examine
@param devlistp      points at location for array pointer return
value
@param devcountp     points at location for array size return value

@retval 0            success
@retval ENOMEM       the array allocation failed
@brief Get a list of children of a device An array containing a list of all the children of the given device is allocated and returned in @p * devlistp . The number of devices in the array is returned in @p * devcountp . The caller should free the array using @c free ( p M_TEMP ) . @param dev the device to examine @param devlistp points at location for array pointer return value @param devcountp points at location for array size return value @retval 0 success @retval ENOMEM the array allocation failed
int
device_get_children(device_t dev, device_t **devlistp, int *devcountp)
{
	int count;
	device_t child;
	device_t *list;
	count = 0;
	TAILQ_FOREACH(child, &dev->children, link) {
		count++;
	}
	if (count == 0) {
		*devlistp = NULL;
		*devcountp = 0;
		return (0);
	}
	list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
	if (!list)
		return (ENOMEM);
	count = 0;
	TAILQ_FOREACH(child, &dev->children, link) {
		list[count] = child;
		count++;
	}
	*devlistp = list;
	*devcountp = count;
	return (0);
}
int device_get_children ( device_t dev , device_t * * devlistp , int * devcountp ) { int count ; device_t child ; device_t * list ; count = 0 ; TAILQ_FOREACH ( child , & dev -> children , link ) { count ++ ; } if ( count == 0 ) { * devlistp = NULL ; * devcountp = 0 ; return ( 0 ) ; } list = malloc ( count * sizeof ( device_t ) , M_TEMP , M_NOWAIT | M_ZERO ) ; if ( ! list ) return ( ENOMEM ) ; count = 0 ; TAILQ_FOREACH ( child , & dev -> children , link ) { list [ count ] = child ; count ++ ; } * devlistp = list ; * devcountp = count ; return ( 0 ) ; }
@brief Get a list of children of a device
 An array containing a list of all the children of the given device
 is allocated and returned in @p *devlistp.
@brief Get a list of children of a device An array containing a list of all the children of the given device is allocated and returned in @p * devlistp .