diff options
author | Tom Rini <trini@konsulko.com> | 2016-10-14 00:03:33 (GMT) |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-10-14 00:03:33 (GMT) |
commit | 4504062b271bf4d1cf256e4e87e156de6029e088 (patch) | |
tree | a0cac720a2687f2ed4ccf15f473d06bb7c8dcb07 /lib | |
parent | 44afdc4a12b9f6f48338e7975e4f08cfe90dba74 (diff) | |
parent | 42b7600d62ae288a8c12431d232b89b26ec61721 (diff) | |
download | u-boot-fsl-qoriq-4504062b271bf4d1cf256e4e87e156de6029e088.tar.xz |
Merge git://git.denx.de/u-boot-fdt
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fdtdec.c | 4 | ||||
-rw-r--r-- | lib/libfdt/fdt.c | 13 | ||||
-rw-r--r-- | lib/libfdt/fdt_overlay.c | 8 | ||||
-rw-r--r-- | lib/libfdt/fdt_ro.c | 119 | ||||
-rw-r--r-- | lib/libfdt/fdt_rw.c | 4 | ||||
-rw-r--r-- | lib/libfdt/fdt_wip.c | 6 |
6 files changed, 92 insertions, 62 deletions
diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 4defb90..4e619c4 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -836,7 +836,7 @@ int fdtdec_get_child_count(const void *blob, int node) int subnode; int num = 0; - fdt_for_each_subnode(blob, subnode, node) + fdt_for_each_subnode(subnode, blob, node) num++; return num; @@ -1014,7 +1014,7 @@ int fdt_get_named_resource(const void *fdt, int node, const char *property, { int index; - index = fdt_find_string(fdt, node, prop_names, name); + index = fdt_stringlist_search(fdt, node, prop_names, name); if (index < 0) return index; diff --git a/lib/libfdt/fdt.c b/lib/libfdt/fdt.c index 96017a1..2055734 100644 --- a/lib/libfdt/fdt.c +++ b/lib/libfdt/fdt.c @@ -35,18 +35,19 @@ int fdt_check_header(const void *fdt) const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len) { - const char *p; + unsigned absoffset = offset + fdt_off_dt_struct(fdt); + + if ((absoffset < offset) + || ((absoffset + len) < absoffset) + || (absoffset + len) > fdt_totalsize(fdt)) + return NULL; if (fdt_version(fdt) >= 0x11) if (((offset + len) < offset) || ((offset + len) > fdt_size_dt_struct(fdt))) return NULL; - p = _fdt_offset_ptr(fdt, offset); - - if (p + len < p) - return NULL; - return p; + return _fdt_offset_ptr(fdt, offset); } uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) diff --git a/lib/libfdt/fdt_overlay.c b/lib/libfdt/fdt_overlay.c index 40b6d27..d35ceac 100644 --- a/lib/libfdt/fdt_overlay.c +++ b/lib/libfdt/fdt_overlay.c @@ -146,7 +146,7 @@ static int overlay_adjust_node_phandles(void *fdto, int node, if (!found && !ret) return ret; - fdt_for_each_subnode(fdto, child, node) + fdt_for_each_subnode(child, fdto, node) overlay_adjust_node_phandles(fdto, child, delta); return 0; @@ -248,7 +248,7 @@ static int overlay_update_local_node_references(void *fdto, } } - fdt_for_each_subnode(fdto, fixup_child, fixup_node) { + fdt_for_each_subnode(fixup_child, fdto, fixup_node) { const char *fixup_child_name = fdt_get_name(fdto, fixup_child, NULL); int tree_child; @@ -511,7 +511,7 @@ static int overlay_apply_node(void *fdt, int target, return ret; } - fdt_for_each_subnode(fdto, node, fragment) { + fdt_for_each_subnode(node, fdto, fragment) { const char *name = fdt_get_name(fdto, node, NULL); int nnode; int ret; @@ -550,7 +550,7 @@ static int overlay_merge(void *dt, void *dto) { int fragment; - fdt_for_each_subnode(dto, fragment, 0) { + fdt_for_each_subnode(fragment, dto, 0) { int overlay; int target; int ret; diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index 9cc98db..7e894b7 100644 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -60,11 +60,11 @@ uint32_t fdt_get_max_phandle(const void *fdt) return max_phandle; if (offset < 0) - return 0; + return (uint32_t)-1; phandle = fdt_get_phandle(fdt, offset); if (phandle == (uint32_t)-1) - return 0; + continue; if (phandle > max_phandle) max_phandle = phandle; @@ -204,6 +204,11 @@ int fdt_path_offset_namelen(const void *fdt, const char *path, int namelen) return offset; } +int fdt_path_offset(const void *fdt, const char *path) +{ + return fdt_path_offset_namelen(fdt, path, strlen(path)); +} + const char *fdt_get_name(const void *fdt, int nodeoffset, int *len) { const struct fdt_node_header *nh = _fdt_offset_ptr(fdt, nodeoffset); @@ -538,80 +543,104 @@ 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 fdt_stringlist_count(const void *fdt, int nodeoffset, const char *property) { - int length, i, count = 0; - const char *list; + const char *list, *end; + int length, count = 0; - list = fdt_getprop(fdt, node, property, &length); + list = fdt_getprop(fdt, nodeoffset, property, &length); if (!list) - return length; + return -length; + + end = list + length; + + while (list < end) { + length = strnlen(list, end - list) + 1; - for (i = 0; i < length; i++) { - int len = strlen(list); + /* Abort if the last string isn't properly NUL-terminated. */ + if (list + length > end) + return -FDT_ERR_BADVALUE; - list += len + 1; - i += len; + list += length; count++; } return count; } -int fdt_find_string(const void *fdt, int node, const char *property, - const char *string) +int fdt_stringlist_search(const void *fdt, int nodeoffset, const char *property, + const char *string) { + int length, len, idx = 0; const char *list, *end; - int len, index = 0; - list = fdt_getprop(fdt, node, property, &len); + list = fdt_getprop(fdt, nodeoffset, property, &length); if (!list) - return len; + return -length; - end = list + len; - len = strlen(string); + len = strlen(string) + 1; + end = list + length; while (list < end) { - int l = strlen(list); + length = strnlen(list, end - list) + 1; - if (l == len && memcmp(list, string, len) == 0) - return index; + /* Abort if the last string isn't properly NUL-terminated. */ + if (list + length > end) + return -FDT_ERR_BADVALUE; - list += l + 1; - index++; + if (length == len && memcmp(list, string, length) == 0) + return idx; + + list += length; + idx++; } return -FDT_ERR_NOTFOUND; } -int fdt_get_string_index(const void *fdt, int node, const char *property, - int index, const char **output) +const char *fdt_stringlist_get(const void *fdt, int nodeoffset, + const char *property, int idx, + int *lenp) { - const char *list; - int length, i; + const char *list, *end; + int length; - list = fdt_getprop(fdt, node, property, &length); + list = fdt_getprop(fdt, nodeoffset, property, &length); + if (!list) { + if (lenp) + *lenp = length; - for (i = 0; i < length; i++) { - int len = strlen(list); + return NULL; + } - if (index == 0) { - *output = list; - return 0; + 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) { + if (lenp) + *lenp = -FDT_ERR_BADVALUE; + + return NULL; } - list += len + 1; - i += len; - index--; + if (idx == 0) { + if (lenp) + *lenp = length - 1; + + return list; + } + + list += length; + idx--; } - return -FDT_ERR_NOTFOUND; -} + if (lenp) + *lenp = -FDT_ERR_NOTFOUND; -int fdt_get_string(const void *fdt, int node, const char *property, - const char **output) -{ - return fdt_get_string_index(fdt, node, property, 0, output); + return NULL; } int fdt_node_check_compatible(const void *fdt, int nodeoffset, @@ -623,10 +652,8 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset, prop = fdt_getprop(fdt, nodeoffset, "compatible", &len); if (!prop) return len; - if (fdt_stringlist_contains(prop, len, compatible)) - return 0; - else - return 1; + + return !fdt_stringlist_contains(prop, len, compatible); } int fdt_node_offset_by_compatible(const void *fdt, int startoffset, diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c index 47447b2..87d4030 100644 --- a/lib/libfdt/fdt_rw.c +++ b/lib/libfdt/fdt_rw.c @@ -60,6 +60,8 @@ static int _fdt_splice(void *fdt, void *splicepoint, int oldlen, int newlen) if (((p + oldlen) < p) || ((p + oldlen) > end)) return -FDT_ERR_BADOFFSET; + if ((p < (char *)fdt) || ((end - oldlen + newlen) < (char *)fdt)) + return -FDT_ERR_BADOFFSET; if ((end - oldlen + newlen) > ((char *)fdt + fdt_totalsize(fdt))) return -FDT_ERR_NOSPACE; memmove(p + newlen, p + oldlen, end - p - oldlen); @@ -164,7 +166,7 @@ static int _fdt_resize_property(void *fdt, int nodeoffset, const char *name, int err; *prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen); - if (!(*prop)) + if (!*prop) return oldlen; if ((err = _fdt_splice_struct(fdt, (*prop)->data, FDT_TAGALIGN(oldlen), diff --git a/lib/libfdt/fdt_wip.c b/lib/libfdt/fdt_wip.c index 216c512..45fb964 100644 --- a/lib/libfdt/fdt_wip.c +++ b/lib/libfdt/fdt_wip.c @@ -16,7 +16,7 @@ int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, const char *name, int namelen, - uint32_t index, const void *val, + uint32_t idx, const void *val, int len) { void *propval; @@ -27,10 +27,10 @@ int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, if (!propval) return proplen; - if (proplen < (len + index)) + if (proplen < (len + idx)) return -FDT_ERR_NOSPACE; - memcpy(propval + index, val, len); + memcpy((char *)propval + idx, val, len); return 0; } |