summaryrefslogtreecommitdiffstats
path: root/drivers/of/base.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r--drivers/of/base.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ff85450d5683..8a2a55c65e5d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -886,6 +886,38 @@ struct device_node *of_find_node_by_phandle(phandle handle)
886EXPORT_SYMBOL(of_find_node_by_phandle); 886EXPORT_SYMBOL(of_find_node_by_phandle);
887 887
888/** 888/**
889 * of_property_count_elems_of_size - Count the number of elements in a property
890 *
891 * @np: device node from which the property value is to be read.
892 * @propname: name of the property to be searched.
893 * @elem_size: size of the individual element
894 *
895 * Search for a property in a device node and count the number of elements of
896 * size elem_size in it. Returns number of elements on sucess, -EINVAL if the
897 * property does not exist or its length does not match a multiple of elem_size
898 * and -ENODATA if the property does not have a value.
899 */
900int of_property_count_elems_of_size(const struct device_node *np,
901 const char *propname, int elem_size)
902{
903 struct property *prop = of_find_property(np, propname, NULL);
904
905 if (!prop)
906 return -EINVAL;
907 if (!prop->value)
908 return -ENODATA;
909
910 if (prop->length % elem_size != 0) {
911 pr_err("size of %s in node %s is not a multiple of %d\n",
912 propname, np->full_name, elem_size);
913 return -EINVAL;
914 }
915
916 return prop->length / elem_size;
917}
918EXPORT_SYMBOL_GPL(of_property_count_elems_of_size);
919
920/**
889 * of_find_property_value_of_size 921 * of_find_property_value_of_size
890 * 922 *
891 * @np: device node from which the property value is to be read. 923 * @np: device node from which the property value is to be read.