diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-03-14 10:10:25 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-03-14 10:10:25 +0100 |
commit | 26dc1bf751724540716a4a17a80f7605ebf61b3a (patch) | |
tree | abdbff429227f48dfd0855dac8ad6381ee8b9ac1 /drivers/base/driver.c | |
parent | d8ef1573dfc3475d4f5dffa37cb4444b5d6f21eb (diff) | |
parent | 79d2a2d4a4608fd0ca9f1eeb06e4aee0fb095f19 (diff) | |
download | barebox-26dc1bf751724540716a4a17a80f7605ebf61b3a.tar.gz barebox-26dc1bf751724540716a4a17a80f7605ebf61b3a.tar.xz |
Merge branch 'for-next/stm32'
Diffstat (limited to 'drivers/base/driver.c')
-rw-r--r-- | drivers/base/driver.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 2347b5c71f..303ca061ce 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -619,3 +619,31 @@ int dev_err_probe(const struct device_d *dev, int err, const char *fmt, ...) return err; } EXPORT_SYMBOL_GPL(dev_err_probe); + +/* + * device_find_child - device iterator for locating a particular device. + * @parent: parent struct device_d + * @match: Callback function to check device + * @data: Data to pass to match function + * + * The callback should return 0 if the device doesn't match and non-zero + * if it does. If the callback returns non-zero and a reference to the + * current device can be obtained, this function will return to the caller + * and not iterate over any more devices. + */ +struct device_d *device_find_child(struct device_d *parent, void *data, + int (*match)(struct device_d *dev, void *data)) +{ + struct device_d *child; + + if (!parent) + return NULL; + + list_for_each_entry(child, &parent->children, sibling) { + if (match(child, data)) + return child; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(device_find_child); |