diff options
author | Thierry Reding <treding@nvidia.com> | 2015-09-29 11:09:07 +0200 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2015-09-30 13:26:18 +1000 |
commit | 8702bd1d3b430c16aaa37056cb24b6d984da48f7 (patch) | |
tree | 493d160bb2e58dc6098d97cc806f1b77af535e7b /libfdt/fdt_ro.c | |
parent | 2218387a8cb9270a688775350a07b02db6d03103 (diff) | |
download | dtc-8702bd1d3b430c16aaa37056cb24b6d984da48f7.zip dtc-8702bd1d3b430c16aaa37056cb24b6d984da48f7.tar.gz dtc-8702bd1d3b430c16aaa37056cb24b6d984da48f7.tar.bz2 |
fdt: Add a function to get the index of a string
The new fdt_stringlist_search() function will look up a given string in
the list contained in the value of a named property of a given device
tree node and return its index.
Signed-off-by: Thierry Reding <treding@nvidia.com>
[Fix some -Wshadow warnings --dwg]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt/fdt_ro.c')
-rw-r--r-- | libfdt/fdt_ro.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 4cde931..2d74c37 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -563,6 +563,36 @@ int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property) return count; } +int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, + const char *string) +{ + int length, len, idx = 0; + const char *list, *end; + + list = fdt_getprop(fdt, nodeoffset, property, &length); + if (!list) + return -length; + + len = strlen(string) + 1; + end = list + length; + + while (list < end) { + length = strnlen(list, end - list) + 1; + + /* Abort if the last string isn't properly NUL-terminated. */ + if (list + length > end) + return -FDT_ERR_BADVALUE; + + if (length == len && memcmp(list, string, length) == 0) + return idx; + + list += length; + idx++; + } + + return -FDT_ERR_NOTFOUND; +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) { |