aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/libfdt
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
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')
-rw-r--r--scripts/dtc/libfdt/fdt.c13
-rw-r--r--scripts/dtc/libfdt/fdt_ro.c100
-rw-r--r--scripts/dtc/libfdt/fdt_rw.c2
-rw-r--r--scripts/dtc/libfdt/libfdt.h73
4 files changed, 179 insertions, 9 deletions
diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c
index 2ce6a44179de..22286a1aaeaf 100644
--- a/scripts/dtc/libfdt/fdt.c
+++ b/scripts/dtc/libfdt/fdt.c
@@ -76,18 +76,19 @@ int fdt_check_header(const void *fdt)
76 76
77const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) 77const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
78{ 78{
79 const char *p; 79 unsigned absoffset = offset + fdt_off_dt_struct(fdt);
80
81 if ((absoffset < offset)
82 || ((absoffset + len) < absoffset)
83 || (absoffset + len) > fdt_totalsize(fdt))
84 return NULL;
80 85
81 if (fdt_version(fdt) >= 0x11) 86 if (fdt_version(fdt) >= 0x11)
82 if (((offset + len) < offset) 87 if (((offset + len) < offset)
83 || ((offset + len) > fdt_size_dt_struct(fdt))) 88 || ((offset + len) > fdt_size_dt_struct(fdt)))
84 return NULL; 89 return NULL;
85 90
86 p = _fdt_offset_ptr(fdt, offset); 91 return _fdt_offset_ptr(fdt, offset);
87
88 if (p + len < p)
89 return NULL;
90 return p;
91} 92}
92 93
93uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) 94uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
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{
diff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/libfdt/fdt_rw.c
index 70adec6c371b..8be02b1f68f3 100644
--- a/scripts/dtc/libfdt/fdt_rw.c
+++ b/scripts/dtc/libfdt/fdt_rw.c
@@ -101,6 +101,8 @@ static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen)
101 101
102 if (((p + oldlen) < p) || ((p + oldlen) > end)) 102 if (((p + oldlen) < p) || ((p + oldlen) > end))
103 return -FDT_ERR_BADOFFSET; 103 return -FDT_ERR_BADOFFSET;
104 if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt))
105 return -FDT_ERR_BADOFFSET;
104 if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt))) 106 if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt)))
105 return -FDT_ERR_NOSPACE; 107 return -FDT_ERR_NOSPACE;
106 memmove(p + newlen, p + oldlen, end - p - oldlen); 108 memmove(p + newlen, p + oldlen, end - p - oldlen);
diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h
index ea35ac3c9be4..59ca33976e56 100644
--- a/scripts/dtc/libfdt/libfdt.h
+++ b/scripts/dtc/libfdt/libfdt.h
@@ -121,7 +121,12 @@
121 /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells 121 /* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells
122 * or similar property with a bad format or value */ 122 * or similar property with a bad format or value */
123 123
124#define FDT_ERR_MAX 14 124#define FDT_ERR_BADVALUE 15
125 /* FDT_ERR_BADVALUE: Device tree has a property with an unexpected
126 * value. For example: a property expected to contain a string list
127 * is not NUL-terminated within the length of its value. */
128
129#define FDT_ERR_MAX 15
125 130
126/**********************************************************************/ 131/**********************************************************************/
127/* Low-level functions (you probably don't need these) */ 132/* Low-level functions (you probably don't need these) */
@@ -457,8 +462,8 @@ const struct fdt_property *fdt_get_property_by_offset(const void *fdt,
457 * @namelen: number of characters of name to consider 462 * @namelen: number of characters of name to consider
458 * @lenp: pointer to an integer variable (will be overwritten) or NULL 463 * @lenp: pointer to an integer variable (will be overwritten) or NULL
459 * 464 *
460 * Identical to fdt_get_property_namelen(), but only examine the first 465 * Identical to fdt_get_property(), but only examine the first namelen
461 * namelen characters of name for matching the property name. 466 * characters of name for matching the property name.
462 */ 467 */
463const struct fdt_property *fdt_get_property_namelen(const void *fdt, 468const struct fdt_property *fdt_get_property_namelen(const void *fdt,
464 int nodeoffset, 469 int nodeoffset,
@@ -868,6 +873,68 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
868 */ 873 */
869int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); 874int fdt_stringlist_contains(const char *strlist, int listlen, const char *str);
870 875
876/**
877 * fdt_stringlist_count - count the number of strings in a string list
878 * @fdt: pointer to the device tree blob
879 * @nodeoffset: offset of a tree node
880 * @property: name of the property containing the string list
881 * @return:
882 * the number of strings in the given property
883 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
884 * -FDT_ERR_NOTFOUND if the property does not exist
885 */
886int fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property);
887
888/**
889 * fdt_stringlist_search - find a string in a string list and return its index
890 * @fdt: pointer to the device tree blob
891 * @nodeoffset: offset of a tree node
892 * @property: name of the property containing the string list
893 * @string: string to look up in the string list
894 *
895 * Note that it is possible for this function to succeed on property values
896 * that are not NUL-terminated. That's because the function will stop after
897 * finding the first occurrence of @string. This can for example happen with
898 * small-valued cell properties, such as #address-cells, when searching for
899 * the empty string.
900 *
901 * @return:
902 * the index of the string in the list of strings
903 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
904 * -FDT_ERR_NOTFOUND if the property does not exist or does not contain
905 * the given string
906 */
907int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property,
908 const char *string);
909
910/**
911 * fdt_stringlist_get() - obtain the string at a given index in a string list
912 * @fdt: pointer to the device tree blob
913 * @nodeoffset: offset of a tree node
914 * @property: name of the property containing the string list
915 * @index: index of the string to return
916 * @lenp: return location for the string length or an error code on failure
917 *
918 * Note that this will successfully extract strings from properties with
919 * non-NUL-terminated values. For example on small-valued cell properties
920 * this function will return the empty string.
921 *
922 * If non-NULL, the length of the string (on success) or a negative error-code
923 * (on failure) will be stored in the integer pointer to by lenp.
924 *
925 * @return:
926 * A pointer to the string at the given index in the string list or NULL on
927 * failure. On success the length of the string will be stored in the memory
928 * location pointed to by the lenp parameter, if non-NULL. On failure one of
929 * the following negative error codes will be returned in the lenp parameter
930 * (if non-NULL):
931 * -FDT_ERR_BADVALUE if the property value is not NUL-terminated
932 * -FDT_ERR_NOTFOUND if the property does not exist
933 */
934const char *fdt_stringlist_get(const void *fdt, int nodeoffset,
935 const char *property, int index,
936 int *lenp);
937
871/**********************************************************************/ 938/**********************************************************************/
872/* Read-only functions (addressing related) */ 939/* Read-only functions (addressing related) */
873/**********************************************************************/ 940/**********************************************************************/