mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-12-04 05:58:57 +00:00
Update device_find_child(9) to return the first matching child if unit
is set to -1. Reviewed by: dfr, imp
This commit is contained in:
parent
78e21ab011
commit
5b68bf38ab
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=141531
@ -28,7 +28,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd June 16, 1998
|
||||
.Dd February 8, 2005
|
||||
.Dt DEVICE_FIND_CHILD 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -38,14 +38,21 @@
|
||||
.In sys/param.h
|
||||
.In sys/bus.h
|
||||
.Ft device_t
|
||||
.Fn device_find_child "device_t dev" "const char* name" "int unit"
|
||||
.Fn device_find_child "device_t dev" "const char *classname" "int unit"
|
||||
.Sh DESCRIPTION
|
||||
This function looks for a specific child of
|
||||
.Dv dev .
|
||||
with the given
|
||||
.Fa name
|
||||
.Fa classname
|
||||
and
|
||||
.Fa unit .
|
||||
If
|
||||
.Fa unit
|
||||
is -1, it returns the first child of
|
||||
.Dv dev
|
||||
with a matching
|
||||
.Fa classname
|
||||
(that is, the one with the lowest unit.)
|
||||
.Sh RETURN VALUES
|
||||
If it exists, the child device is returned, otherwise NULL.
|
||||
.Sh SEE ALSO
|
||||
|
@ -1576,8 +1576,10 @@ device_delete_child(device_t dev, device_t child)
|
||||
* devices which have @p dev as a parent.
|
||||
*
|
||||
* @param dev the parent device to search
|
||||
* @param unit the unit number to search for
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
@ -1591,9 +1593,17 @@ device_find_child(device_t dev, const char *classname, int unit)
|
||||
if (!dc)
|
||||
return (NULL);
|
||||
|
||||
child = devclass_get_device(dc, unit);
|
||||
if (child && child->parent == dev)
|
||||
return (child);
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user