diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2011-12-12 11:25:58 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2012-01-28 12:29:20 -0500 |
commit | 7aff0fe33033fc75b61446ba29d38b1b1354af9f (patch) | |
tree | 2ddcfaf17ab0d98959478fd5133d1fe08adb8eef /drivers/of/base.c | |
parent | dcd6c92267155e70a94b3927bce681ce74b80d1f (diff) |
of: Add of_property_match_string() to find index into a string list
Add a helper function for finding the index of a string in a string
list property. This helper is useful for bindings that use a separate
*-name property for attaching names to tuples in another property such
as 'reg' or 'gpios'.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of/base.c')
-rw-r--r-- | drivers/of/base.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 133908a6fd8d..13ba72875e25 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -761,6 +761,42 @@ int of_property_read_string_index(struct device_node *np, const char *propname, | |||
761 | } | 761 | } |
762 | EXPORT_SYMBOL_GPL(of_property_read_string_index); | 762 | EXPORT_SYMBOL_GPL(of_property_read_string_index); |
763 | 763 | ||
764 | /** | ||
765 | * of_property_match_string() - Find string in a list and return index | ||
766 | * @np: pointer to node containing string list property | ||
767 | * @propname: string list property name | ||
768 | * @string: pointer to string to search for in string list | ||
769 | * | ||
770 | * This function searches a string list property and returns the index | ||
771 | * of a specific string value. | ||
772 | */ | ||
773 | int of_property_match_string(struct device_node *np, const char *propname, | ||
774 | const char *string) | ||
775 | { | ||
776 | struct property *prop = of_find_property(np, propname, NULL); | ||
777 | size_t l; | ||
778 | int i; | ||
779 | const char *p, *end; | ||
780 | |||
781 | if (!prop) | ||
782 | return -EINVAL; | ||
783 | if (!prop->value) | ||
784 | return -ENODATA; | ||
785 | |||
786 | p = prop->value; | ||
787 | end = p + prop->length; | ||
788 | |||
789 | for (i = 0; p < end; i++, p += l) { | ||
790 | l = strlen(p) + 1; | ||
791 | if (p + l > end) | ||
792 | return -EILSEQ; | ||
793 | pr_debug("comparing %s with %s\n", string, p); | ||
794 | if (strcmp(string, p) == 0) | ||
795 | return i; /* Found it; return index */ | ||
796 | } | ||
797 | return -ENODATA; | ||
798 | } | ||
799 | EXPORT_SYMBOL_GPL(of_property_match_string); | ||
764 | 800 | ||
765 | /** | 801 | /** |
766 | * of_property_count_strings - Find and return the number of strings from a | 802 | * of_property_count_strings - Find and return the number of strings from a |