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>
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user