From: Thierry Reding Date: Tue, 26 Aug 2014 15:33:50 +0000 (+0200) Subject: fdt: Add a function to count strings X-Git-Tag: submit/tizen/20160318.071304~193 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52ab9a2a2630ffd17f557e461768ae40e531f857;p=profile%2Fcommon%2Fplatform%2Fkernel%2Fu-boot-artik.git fdt: Add a function to count strings Given a device tree node and a property name, the fdt_count_strings() function counts the number of strings found in the property value. Signed-off-by: Thierry Reding Acked-by: Simon Glass --- diff --git a/include/libfdt.h b/include/libfdt.h index 765d84f5e..6a5b3466f 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -852,6 +852,15 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset, */ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); +/** + * fdt_count_strings - count the number of strings in a string list + * @fdt: pointer to the device tree blob + * @node: offset of the node + * @property: name of the property containing the string list + * @return: the number of strings in the given property + */ +int fdt_count_strings(const void *fdt, int node, const char *property); + /**********************************************************************/ /* Write-in-place functions */ /**********************************************************************/ diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index b65f4e23a..71b8d4fc1 100644 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -536,6 +536,26 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str) return 0; } +int fdt_count_strings(const void *fdt, int node, const char *property) +{ + int length, i, count = 0; + const char *list; + + list = fdt_getprop(fdt, node, property, &length); + if (!list) + return -length; + + for (i = 0; i < length; i++) { + int len = strlen(list); + + list += len + 1; + i += len; + count++; + } + + return count; +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) {