From: Simon Glass Date: Mon, 27 Jan 2020 15:49:36 +0000 (-0700) Subject: dm: core: Use const where possible in device.h X-Git-Tag: submit/tizen_6.0/20211217.073345~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a15a5b0d0be462ed915b1d5d4b104025b9170840;p=platform%2Fkernel%2Fu-boot.git dm: core: Use const where possible in device.h Update this header file to use const devices where possible, to permit callers to also use const. Change-Id: I9c0bcba75fee845672234a29dfa7723b61f6bc39 Signed-off-by: Simon Glass --- diff --git a/drivers/core/device.c b/drivers/core/device.c index ace2b1d617..228f99eeb5 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -597,6 +597,17 @@ int device_get_child(const struct udevice *parent, int index, return -ENODEV; } +int device_get_child_count(const struct udevice *parent) +{ + struct udevice *dev; + int count = 0; + + list_for_each_entry(dev, &parent->child_head, sibling_node) + count++; + + return count; +} + int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq, bool find_req_seq, struct udevice **devp) { diff --git a/include/dm/device.h b/include/dm/device.h index 3deee4e151..1e6bd615d1 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -411,6 +411,15 @@ const char *dev_get_uclass_name(const struct udevice *dev); int device_get_child(const struct udevice *parent, int index, struct udevice **devp); +/** + * device_get_child_count() - Get the available child count of a device + * + * Returns the number of children to a device. + * + * @parent: Parent device to check + */ +int device_get_child_count(const struct udevice *parent); + /** * device_find_child_by_seq() - Find a child device based on a sequence *