aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/libfdt/fdt_ro.c
diff options
context:
space:
mode:
authorRob Herring <robh@kernel.org>2016-01-26 10:04:11 -0500
committerRob Herring <robh@kernel.org>2016-02-11 20:45:09 -0500
commit91feabc2e2240ee80dc8ac08103cb83f497e4d12 (patch)
tree8bd53e02910f0d15b3516d7af298b03b19ca5dac /scripts/dtc/libfdt/fdt_ro.c
parent76df69806b7fafea013e2f4f82b0bd54498f3406 (diff)
scripts/dtc: Update to upstream commit b06e55c88b9b
Sync to upstream dtc commit b06e55c88b9b ("Prevent crash on modulo by zero"). This adds the following commits from upstream: b06e55c Prevent crash on modulo by zero b433450 Fix some bugs in processing of line directives d728ad5 Fix crash on nul character in string escape sequence 1ab2205 Gracefully handle bad octal literals 1937095 Prevent crash on division by zero d0b3ab0 libfdt: Fix undefined behaviour in fdt_offset_ptr() d4c7c25 libfdt: check for potential overrun in _fdt_splice() f58799b libfdt: Add some missing symbols to version.lds af9f26d Remove duplicated -Werror in dtc Makefile 604e61e fdt: Add functions to retrieve strings 8702bd1 fdt: Add a function to get the index of a string 2218387 fdt: Add a function to count strings 554fde2 libfdt: fix comment block of fdt_get_property_namelen() e5e6df7 fdtdump: Fix bug printing bytestrings with negative values 067829e Remove redundant fdtdump test code 897a429 Move fdt_path_offset alias tests to right tests section 2d1417c Add simple .travis.yml f6dbc6c guess output file format 5e78dff guess input file format based on file content or file name 8b927bf tests: convert `echo -n` to `printf` 64c46b0 Fix crash with poorly defined #size-cells Cc: Grant Likely <grant.likely@linaro.org> Tested-by: Frank Rowand <frank.rowand@sonymobile.com> Reviewed-by: Frank Rowand <frank.rowand@sonymobile.com> Signed-off-by: Rob Herring <robh@kernel.org>
Diffstat (limited to 'scripts/dtc/libfdt/fdt_ro.c')
-rw-r--r--scripts/dtc/libfdt/fdt_ro.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c
index a65e4b5b72b6..e5b313682007 100644
--- a/scripts/dtc/libfdt/fdt_ro.c
+++ b/scripts/dtc/libfdt/fdt_ro.c
@@ -538,6 +538,106 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str)
538 return 0; 538 return 0;
539} 539}
540 540
541int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property)
542{
543 const char *list, *end;
544 int length, count = 0;
545
546 list = fdt_getprop(fdt, nodeoffset, property, &length);
547 if (!list)
548 return -length;
549
550 end = list + length;
551
552 while (list < end) {
553 length = strnlen(list, end - list) + 1;
554
555 /* Abort if the last string isn't properly NUL-terminated. */
556 if (list + length > end)
557 return -FDT_ERR_BADVALUE;
558
559 list += length;
560 count++;
561 }
562
563 return count;
564}
565
566int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
567 const char *string)
568{
569 int length, len, idx = 0;
570 const char *list, *end;
571
572 list = fdt_getprop(fdt, nodeoffset, property, &length);
573 if (!list)
574 return -length;
575
576 len = strlen(string) + 1;
577 end = list + length;
578
579 while (list < end) {
580 length = strnlen(list, end - list) + 1;
581
582 /* Abort if the last string isn't properly NUL-terminated. */
583 if (list + length > end)
584 return -FDT_ERR_BADVALUE;
585
586 if (length == len && memcmp(list, string, length) == 0)
587 return idx;
588
589 list += length;
590 idx++;
591 }
592
593 return -FDT_ERR_NOTFOUND;
594}
595
596const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
597 const char *property, int idx,
598 int *lenp)
599{
600 const char *list, *end;
601 int length;
602
603 list = fdt_getprop(fdt, nodeoffset, property, &length);
604 if (!list) {
605 if (lenp)
606 *lenp = length;
607
608 return NULL;
609 }
610
611 end = list + length;
612
613 while (list < end) {
614 length = strnlen(list, end - list) + 1;
615
616 /* Abort if the last string isn't properly NUL-terminated. */
617 if (list + length > end) {
618 if (lenp)
619 *lenp = -FDT_ERR_BADVALUE;
620
621 return NULL;
622 }
623
624 if (idx == 0) {
625 if (lenp)
626 *lenp = length - 1;
627
628 return list;
629 }
630
631 list += length;
632 idx--;
633 }
634
635 if (lenp)
636 *lenp = -FDT_ERR_NOTFOUND;
637
638 return NULL;
639}
640
541int fdt_node_check_compatible(const void *fdt, int nodeoffset, 641int fdt_node_check_compatible(const void *fdt, int nodeoffset,
542 const char *compatible) 642 const char *compatible)
543{ 643{