FreeBSD/sys/kern/subr_bus.c
/**
 * @brief Get a list of devices in the devclass
 *
 * An array containing a list of all the devices in the given devclass
 * 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), even if @p *devcountp is 0.
 *
 * @param dc		the devclass 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 devices in the devclass
An array containing a list of all the devices in the given devclass
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), even if @p *devcountp is 0.

@param dc            the devclass 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 devices in the devclass An array containing a list of all the devices in the given devclass 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 ) even if @p * devcountp is 0 . @param dc the devclass 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
devclass_get_devices(devclass_t dc, device_t **devlistp, int *devcountp)
{
	int count, i;
	device_t *list;
	count = devclass_get_count(dc);
	list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
	if (!list)
		return (ENOMEM);
	count = 0;
	for (i = 0; i < dc->maxunit; i++) {
		if (dc->devices[i]) {
			list[count] = dc->devices[i];
			count++;
		}
	}
	*devlistp = list;
	*devcountp = count;
	return (0);
}
int devclass_get_devices ( devclass_t dc , device_t * * devlistp , int * devcountp ) { int count , i ; device_t * list ; count = devclass_get_count ( dc ) ; list = malloc ( count * sizeof ( device_t ) , M_TEMP , M_NOWAIT | M_ZERO ) ; if ( ! list ) return ( ENOMEM ) ; count = 0 ; for ( i = 0 ; i < dc -> maxunit ; i ++ ) { if ( dc -> devices [ i ] ) { list [ count ] = dc -> devices [ i ] ; count ++ ; } } * devlistp = list ; * devcountp = count ; return ( 0 ) ; }
@brief Get a list of devices in the devclass
 An array containing a list of all the devices in the given devclass
 is allocated and returned in @p *devlistp.
@brief Get a list of devices in the devclass An array containing a list of all the devices in the given devclass is allocated and returned in @p * devlistp .