summaryrefslogtreecommitdiff
path: root/drivers/core/uclass.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2024-10-19 09:21:49 -0600
committerTom Rini <trini@konsulko.com>2024-11-03 21:27:12 -0600
commit79b3e9d25b3f96fdf66f9d7dc6a14fdce9a15f93 (patch)
tree60492674ad4706c755befa65e5ccfe9250a17c86 /drivers/core/uclass.c
parent2ca32cbb837ff0a1e906a99c518a03852e1d24e8 (diff)
dm: core: Add a function to see if a device exists
All the uclass functions for finding a device end up creating a uclass if it doesn't exist. Add a function which instead returns NULL in this case. This is useful when in the 'unbind' path, since we don't want to undo any unbinding which has already happened. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core/uclass.c')
-rw-r--r--drivers/core/uclass.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 7ae0884a75e..f846a35d6b2 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -304,6 +304,17 @@ int uclass_find_device_by_name(enum uclass_id id, const char *name,
return uclass_find_device_by_namelen(id, name, strlen(name), devp);
}
+struct udevice *uclass_try_first_device(enum uclass_id id)
+{
+ struct uclass *uc;
+
+ uc = uclass_find(id);
+ if (!uc || list_empty(&uc->dev_head))
+ return NULL;
+
+ return list_first_entry(&uc->dev_head, struct udevice, uclass_node);
+}
+
int uclass_find_next_free_seq(struct uclass *uc)
{
struct udevice *dev;