* @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
| 2013 | * NULL if there is no such device |
| 2014 | */ |
| 2015 | device_t |
| 2016 | device_find_child(device_t dev, const char *classname, int unit) |
| 2017 | { |
| 2018 | devclass_t dc; |
| 2019 | device_t child; |
| 2020 | |
| 2021 | dc = devclass_find(classname); |
| 2022 | if (!dc) |
| 2023 | return (NULL); |
| 2024 | |
| 2025 | if (unit != -1) { |
| 2026 | child = devclass_get_device(dc, unit); |
| 2027 | if (child && child->parent == dev) |
| 2028 | return (child); |
| 2029 | } else { |
| 2030 | for (unit = 0; unit < devclass_get_maxunit(dc); unit++) { |
| 2031 | child = devclass_get_device(dc, unit); |
| 2032 | if (child && child->parent == dev) |
| 2033 | return (child); |
| 2034 | } |
| 2035 | } |
| 2036 | return (NULL); |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * @internal |
no test coverage detected