From 1f3055aa36655cce731dcc8f33a21b011cec14eb Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Mon, 20 Apr 2020 17:59:50 -0700 Subject: device: Add helper function to find matching device on bus This change adds a helper function dev_find_matching_device_on_bus() which scans all the child devices on the given bus and calls a match function provided by the caller. It returns the first device that the match function returns true for, else NULL if no such device is found. Change-Id: I2e3332c0a175ab995c523f078f29a9f498f17931 Signed-off-by: Furquan Shaikh Reviewed-on: https://review.coreboot.org/c/coreboot/+/40543 Reviewed-by: Aaron Durbin Reviewed-by: Tim Wawrzynczak Tested-by: build bot (Jenkins) --- src/device/device_const.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/device') diff --git a/src/device/device_const.c b/src/device/device_const.c index de404dc0d1..add253b511 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -70,6 +70,19 @@ DEVTREE_CONST struct device *dev_find_path( return result; } +DEVTREE_CONST struct device *dev_find_matching_device_on_bus(const struct bus *bus, + match_device_fn fn) +{ + DEVTREE_CONST struct device *child = NULL; + + while ((child = dev_bus_each_child(bus, child)) != NULL) { + if (fn(child)) + break; + } + + return child; +} + /** * Given a device pointer, find the next PCI device. * -- cgit v1.2.3