diff options
author | Simon Glass <sjg@chromium.org> | 2016-02-11 13:23:25 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2016-03-14 15:34:50 -0600 |
commit | b06750501f5c0eef7fef094f13d2f2e313c60b79 (patch) | |
tree | d0dfd81b292e93e73227e015246382ac4a6f689b /drivers | |
parent | df61a74e6845ec9bdcdd48d2aff5e9c2c6debeaa (diff) | |
download | u-boot-b06750501f5c0eef7fef094f13d2f2e313c60b79.tar.gz |
dm: core: Add uclass_first_device_err() to return a valid device
A common pattern is to call uclass_first_device() and then check if it
actually returns a device. Add a new function which does this, returning
an error if there are no devices in that uclass.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/core/uclass.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 12095e75a4..1141ce1ba3 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -401,6 +401,19 @@ int uclass_first_device(enum uclass_id id, struct udevice **devp) return uclass_get_device_tail(dev, ret, devp); } +int uclass_first_device_err(enum uclass_id id, struct udevice **devp) +{ + int ret; + + ret = uclass_first_device(id, devp); + if (ret) + return ret; + else if (!*devp) + return -ENODEV; + + return 0; +} + int uclass_next_device(struct udevice **devp) { struct udevice *dev = *devp; |