diff options
Diffstat (limited to 'drivers/of/base.c')
-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 89e888a78899..1b95a405628f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -904,6 +904,38 @@ struct device_node *of_find_node_by_phandle(phandle handle) | |||
904 | EXPORT_SYMBOL(of_find_node_by_phandle); | 904 | EXPORT_SYMBOL(of_find_node_by_phandle); |
905 | 905 | ||
906 | /** | 906 | /** |
907 | * of_property_count_elems_of_size - Count the number of elements in a property | ||
908 | * | ||
909 | * @np: device node from which the property value is to be read. | ||
910 | * @propname: name of the property to be searched. | ||
911 | * @elem_size: size of the individual element | ||
912 | * | ||
913 | * Search for a property in a device node and count the number of elements of | ||
914 | * size elem_size in it. Returns number of elements on sucess, -EINVAL if the | ||
915 | * property does not exist or its length does not match a multiple of elem_size | ||
916 | * and -ENODATA if the property does not have a value. | ||
917 | */ | ||
918 | int of_property_count_elems_of_size(const struct device_node *np, | ||
919 | const char *propname, int elem_size) | ||
920 | { | ||
921 | struct property *prop = of_find_property(np, propname, NULL); | ||
922 | |||
923 | if (!prop) | ||
924 | return -EINVAL; | ||
925 | if (!prop->value) | ||
926 | return -ENODATA; | ||
927 | |||
928 | if (prop->length % elem_size != 0) { | ||
929 | pr_err("size of %s in node %s is not a multiple of %d\n", | ||
930 | propname, np->full_name, elem_size); | ||
931 | return -EINVAL; | ||
932 | } | ||
933 | |||
934 | return prop->length / elem_size; | ||
935 | } | ||
936 | EXPORT_SYMBOL_GPL(of_property_count_elems_of_size); | ||
937 | |||
938 | /** | ||
907 | * of_find_property_value_of_size | 939 | * of_find_property_value_of_size |
908 | * | 940 | * |
909 | * @np: device node from which the property value is to be read. | 941 | * @np: device node from which the property value is to be read. |