diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-03-30 16:57:16 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-03-31 09:48:34 +0200 |
commit | 35dd94be1eac9b44bc00b849522b15569b9d083a (patch) | |
tree | 2fae07bb9bcbe0f34a2f3ec6af2939d17f2eec86 /drivers | |
parent | c5e8deaeebd5e223fc77df6aa8daa25f5b7f3ea9 (diff) | |
download | barebox-35dd94be1eac9b44bc00b849522b15569b9d083a.tar.gz barebox-35dd94be1eac9b44bc00b849522b15569b9d083a.tar.xz |
of: introduce of_property_count_elems_of_size
Import the Linux helper, so code using it may be more easily ported.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/base.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 9ede052274..158ebe8bcc 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -739,6 +739,38 @@ int of_property_read_u32_index(const struct device_node *np, EXPORT_SYMBOL_GPL(of_property_read_u32_index); /** + * of_property_count_elems_of_size - Count the number of elements in a property + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @elem_size: size of the individual element + * + * Search for a property in a device node and count the number of elements of + * size elem_size in it. Returns number of elements on sucess, -EINVAL if the + * property does not exist or its length does not match a multiple of elem_size + * and -ENODATA if the property does not have a value. + */ +int of_property_count_elems_of_size(const struct device_node *np, + const char *propname, int elem_size) +{ + struct property *prop = of_find_property(np, propname, NULL); + + if (!prop) + return -EINVAL; + if (!prop->value) + return -ENODATA; + + if (prop->length % elem_size != 0) { + pr_err("size of %s in node %pOF is not a multiple of %d\n", + propname, np, elem_size); + return -EINVAL; + } + + return prop->length / elem_size; +} +EXPORT_SYMBOL_GPL(of_property_count_elems_of_size); + +/** * of_property_read_u8_array - Find and read an array of u8 from a property. * * @np: device node from which the property value is to be read. |