diff options
author | njl <njl@FreeBSD.org> | 2005-02-08 18:00:29 +0000 |
---|---|---|
committer | njl <njl@FreeBSD.org> | 2005-02-08 18:00:29 +0000 |
commit | 21180427d3fde15a1feaea08b7c49ba07bece76d (patch) | |
tree | eabb3eaa2bb422d1749b6ccc5da2ff8787ba0121 /sys/kern | |
parent | e90b04ef14b93b89e8bbedc0bb3c35add6bf90c0 (diff) | |
download | FreeBSD-src-21180427d3fde15a1feaea08b7c49ba07bece76d.zip FreeBSD-src-21180427d3fde15a1feaea08b7c49ba07bece76d.tar.gz |
Update device_find_child(9) to return the first matching child if unit
is set to -1.
Reviewed by: dfr, imp
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/subr_bus.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 58d4a67..b63b926 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -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); } |