Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts/dtc: Update to upstream version v1.6.1-63-g55778a03df61

It's been a while since the last sync and Lee needs commit 73590342fc85
("libfdt: prevent integer overflow in fdt_next_tag").

This adds the following commits from upstream:

55778a03df61 libfdt: tests: add get_next_tag_invalid_prop_len
73590342fc85 libfdt: prevent integer overflow in fdt_next_tag
035fb90d5375 libfdt: add fdt_get_property_by_offset_w helper
98a07006c48d Makefile: fix infinite recursion by dropping non-existent `%.output`
a036cc7b0c10 Makefile: limit make re-execution to avoid infinite spin
c6e92108bcd9 libdtc: remove duplicate judgments
e37c25677dc9 Don't generate erroneous fixups from reference to path
50454658f2b5 libfdt: Don't mask fdt_get_name() returned error
e64a204196c9 manual.txt: Follow README.md and remove Jon
f508c83fe6f0 Update README in MANIFEST.in and setup.py to README.md
c2ccf8a77dd2 Add description of Signed-off-by lines
90b9d9de42ca Split out information for contributors to CONTRIBUTING.md
0ee1d479b23a Remove Jon Loeliger from maintainers list
b33a73c62c1c Convert README to README.md
7ad60734b1c1 Allow static building with meson
fd9b8c96c780 Allow static building with make
fda71da26e7f libfdt: Handle failed get_name() on BEGIN_NODE
c7c7f17a83d5 Fix test script to run also on dash shell
01f23ffe1679 Add missing relref_merge test to meson test list
ed310803ea89 pylibfdt: add FdtRo.get_path()
c001fc01a43e pylibfdt: fix swig build in install
26c54f840d23 tests: add test cases for label-relative path references
ec7986e682cf dtc: introduce label relative path references
651410e54cb9 util: introduce xstrndup helper
4048aed12b81 setup.py: fix out of tree build
ff5afb96d0c0 Handle integer overflow in check_property_phandle_args()
ca7294434309 README: Explain how to add a new API function
c0c2e115f82e Fix a UB when fdt_get_string return null
cd5f69cbc0d4 tests: setprop_inplace: use xstrdup instead of unchecked strdup
a04f69025003 pylibfdt: add Property.as_*int*_array()
83102717d7c4 pylibfdt: add Property.as_stringlist()
d152126bb029 Fix Python crash on getprop deallocation
17739b7ef510 Support 'r' format for printing raw bytes with fdtget
45f3d1a095dd libfdt: overlay: make overlay_get_target() public
c19a4bafa514 libfdt: fix an incorrect integer promotion
1cc41b1c969f pylibfdt: Add packaging metadata
db72398cd437 README: Update pylibfdt install instructions
383e148b70a4 pylibfdt: fix with Python 3.10
23b56cb7e189 pylibfdt: Move setup.py to the top level
69a760747d8d pylibfdt: Split setup.py author name and email
0b106a77dbdc pylibfdt: Use setuptools_scm for the version
c691776ddb26 pylibfdt: Use setuptools instead of distutils
5216f3f1bbb7 libfdt: Add static lib to meson build
4eda2590f481 CI: Cirrus: bump used FreeBSD from 12.1 to 13.0

Link: https://lore.kernel.org/r/20221101181427.1808703-1-robh@kernel.org/
Signed-off-by: Rob Herring <robh@kernel.org>

+124 -48
+9 -6
scripts/dtc/checks.c
··· 1382 1382 }; 1383 1383 1384 1384 static void check_property_phandle_args(struct check *c, 1385 - struct dt_info *dti, 1386 - struct node *node, 1387 - struct property *prop, 1388 - const struct provider *provider) 1385 + struct dt_info *dti, 1386 + struct node *node, 1387 + struct property *prop, 1388 + const struct provider *provider) 1389 1389 { 1390 1390 struct node *root = dti->dt; 1391 1391 unsigned int cell, cellsize = 0; ··· 1401 1401 struct node *provider_node; 1402 1402 struct property *cellprop; 1403 1403 cell_t phandle; 1404 + unsigned int expected; 1404 1405 1405 1406 phandle = propval_cell_n(prop, cell); 1406 1407 /* ··· 1451 1450 break; 1452 1451 } 1453 1452 1454 - if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) { 1453 + expected = (cell + cellsize + 1) * sizeof(cell_t); 1454 + if ((expected <= cell) || prop->val.len < expected) { 1455 1455 FAIL_PROP(c, dti, node, prop, 1456 - "property size (%d) too small for cell size %d", 1456 + "property size (%d) too small for cell size %u", 1457 1457 prop->val.len, cellsize); 1458 + break; 1458 1459 } 1459 1460 } 1460 1461 }
+1 -1
scripts/dtc/dtc-lexer.l
··· 200 200 return DT_LABEL_REF; 201 201 } 202 202 203 - <*>"&{/"{PATHCHAR}*\} { /* new-style path reference */ 203 + <*>"&{"{PATHCHAR}*\} { /* new-style path reference */ 204 204 yytext[yyleng-1] = '\0'; 205 205 DPRINT("Ref: %s\n", yytext+2); 206 206 yylval.labelref = xstrdup(yytext+2);
+13
scripts/dtc/dtc-parser.y
··· 23 23 24 24 extern struct dt_info *parser_output; 25 25 extern bool treesource_error; 26 + 27 + static bool is_ref_relative(const char *ref) 28 + { 29 + return ref[0] != '/' && strchr(&ref[1], '/'); 30 + } 31 + 26 32 %} 27 33 28 34 %union { ··· 175 169 */ 176 170 if (!($<flags>-1 & DTSF_PLUGIN)) 177 171 ERROR(&@2, "Label or path %s not found", $1); 172 + else if (is_ref_relative($1)) 173 + ERROR(&@2, "Label-relative reference %s not supported in plugin", $1); 178 174 $$ = add_orphan_node( 179 175 name_node(build_node(NULL, NULL, NULL), 180 176 ""), ··· 185 177 | devicetree DT_LABEL dt_ref nodedef 186 178 { 187 179 struct node *target = get_node_by_ref($1, $3); 180 + 181 + if (($<flags>-1 & DTSF_PLUGIN) && is_ref_relative($3)) 182 + ERROR(&@2, "Label-relative reference %s not supported in plugin", $3); 188 183 189 184 if (target) { 190 185 add_label(&target->labels, $2); ··· 204 193 * so $-1 is what we want (plugindecl) 205 194 */ 206 195 if ($<flags>-1 & DTSF_PLUGIN) { 196 + if (is_ref_relative($2)) 197 + ERROR(&@2, "Label-relative reference %s not supported in plugin", $2); 207 198 add_orphan_node($1, $3, $2); 208 199 } else { 209 200 struct node *target = get_node_by_ref($1, $2);
+12 -8
scripts/dtc/libfdt/fdt.c
··· 106 106 } 107 107 hdrsize = fdt_header_size(fdt); 108 108 if (!can_assume(VALID_DTB)) { 109 - 110 109 if ((fdt_totalsize(fdt) < hdrsize) 111 110 || (fdt_totalsize(fdt) > INT_MAX)) 112 111 return -FDT_ERR_TRUNCATED; ··· 114 115 if (!check_off_(hdrsize, fdt_totalsize(fdt), 115 116 fdt_off_mem_rsvmap(fdt))) 116 117 return -FDT_ERR_TRUNCATED; 117 - } 118 118 119 - if (!can_assume(VALID_DTB)) { 120 119 /* Bounds check structure block */ 121 120 if (!can_assume(LATEST) && fdt_version(fdt) < 17) { 122 121 if (!check_off_(hdrsize, fdt_totalsize(fdt), ··· 162 165 uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset) 163 166 { 164 167 const fdt32_t *tagp, *lenp; 165 - uint32_t tag; 168 + uint32_t tag, len, sum; 166 169 int offset = startoffset; 167 170 const char *p; 168 171 ··· 188 191 lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp)); 189 192 if (!can_assume(VALID_DTB) && !lenp) 190 193 return FDT_END; /* premature end */ 194 + 195 + len = fdt32_to_cpu(*lenp); 196 + sum = len + offset; 197 + if (!can_assume(VALID_DTB) && 198 + (INT_MAX <= sum || sum < (uint32_t) offset)) 199 + return FDT_END; /* premature end */ 200 + 191 201 /* skip-name offset, length and value */ 192 - offset += sizeof(struct fdt_property) - FDT_TAGSIZE 193 - + fdt32_to_cpu(*lenp); 202 + offset += sizeof(struct fdt_property) - FDT_TAGSIZE + len; 203 + 194 204 if (!can_assume(LATEST) && 195 - fdt_version(fdt) < 0x10 && fdt32_to_cpu(*lenp) >= 8 && 196 - ((offset - fdt32_to_cpu(*lenp)) % 8) != 0) 205 + fdt_version(fdt) < 0x10 && len >= 8 && 206 + ((offset - len) % 8) != 0) 197 207 offset += 4; 198 208 break; 199 209
+2 -2
scripts/dtc/libfdt/fdt.h
··· 35 35 36 36 struct fdt_node_header { 37 37 fdt32_t tag; 38 - char name[]; 38 + char name[0]; 39 39 }; 40 40 41 41 struct fdt_property { 42 42 fdt32_t tag; 43 43 fdt32_t len; 44 44 fdt32_t nameoff; 45 - char data[]; 45 + char data[0]; 46 46 }; 47 47 48 48 #endif /* !__ASSEMBLY */
+1 -1
scripts/dtc/libfdt/fdt_addresses.c
··· 73 73 /* check validity of address */ 74 74 prop = data; 75 75 if (addr_cells == 1) { 76 - if ((addr > UINT32_MAX) || ((UINT32_MAX + 1 - addr) < size)) 76 + if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size)) 77 77 return -FDT_ERR_BADVALUE; 78 78 79 79 fdt32_st(prop, (uint32_t)addr);
+7 -22
scripts/dtc/libfdt/fdt_overlay.c
··· 40 40 return fdt32_to_cpu(*val); 41 41 } 42 42 43 - /** 44 - * overlay_get_target - retrieves the offset of a fragment's target 45 - * @fdt: Base device tree blob 46 - * @fdto: Device tree overlay blob 47 - * @fragment: node offset of the fragment in the overlay 48 - * @pathp: pointer which receives the path of the target (or NULL) 49 - * 50 - * overlay_get_target() retrieves the target offset in the base 51 - * device tree of a fragment, no matter how the actual targeting is 52 - * done (through a phandle or a path) 53 - * 54 - * returns: 55 - * the targeted node offset in the base device tree 56 - * Negative error code on error 57 - */ 58 - static int overlay_get_target(const void *fdt, const void *fdto, 59 - int fragment, char const **pathp) 43 + int fdt_overlay_target_offset(const void *fdt, const void *fdto, 44 + int fragment_offset, char const **pathp) 60 45 { 61 46 uint32_t phandle; 62 47 const char *path = NULL; 63 48 int path_len = 0, ret; 64 49 65 50 /* Try first to do a phandle based lookup */ 66 - phandle = overlay_get_target_phandle(fdto, fragment); 51 + phandle = overlay_get_target_phandle(fdto, fragment_offset); 67 52 if (phandle == (uint32_t)-1) 68 53 return -FDT_ERR_BADPHANDLE; 69 54 70 55 /* no phandle, try path */ 71 56 if (!phandle) { 72 57 /* And then a path based lookup */ 73 - path = fdt_getprop(fdto, fragment, "target-path", &path_len); 58 + path = fdt_getprop(fdto, fragment_offset, "target-path", &path_len); 74 59 if (path) 75 60 ret = fdt_path_offset(fdt, path); 76 61 else ··· 621 636 if (overlay < 0) 622 637 return overlay; 623 638 624 - target = overlay_get_target(fdt, fdto, fragment, NULL); 639 + target = fdt_overlay_target_offset(fdt, fdto, fragment, NULL); 625 640 if (target < 0) 626 641 return target; 627 642 ··· 764 779 return -FDT_ERR_BADOVERLAY; 765 780 766 781 /* get the target of the fragment */ 767 - ret = overlay_get_target(fdt, fdto, fragment, &target_path); 782 + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); 768 783 if (ret < 0) 769 784 return ret; 770 785 target = ret; ··· 786 801 787 802 if (!target_path) { 788 803 /* again in case setprop_placeholder changed it */ 789 - ret = overlay_get_target(fdt, fdto, fragment, &target_path); 804 + ret = fdt_overlay_target_offset(fdt, fdto, fragment, &target_path); 790 805 if (ret < 0) 791 806 return ret; 792 807 target = ret;
+1 -1
scripts/dtc/libfdt/fdt_ro.c
··· 481 481 if (!can_assume(VALID_INPUT)) { 482 482 name = fdt_get_string(fdt, fdt32_ld_(&prop->nameoff), 483 483 &namelen); 484 + *namep = name; 484 485 if (!name) { 485 486 if (lenp) 486 487 *lenp = namelen; 487 488 return NULL; 488 489 } 489 - *namep = name; 490 490 } else { 491 491 *namep = fdt_string(fdt, fdt32_ld_(&prop->nameoff)); 492 492 }
+25
scripts/dtc/libfdt/libfdt.h
··· 660 660 const struct fdt_property *fdt_get_property_by_offset(const void *fdt, 661 661 int offset, 662 662 int *lenp); 663 + static inline struct fdt_property *fdt_get_property_by_offset_w(void *fdt, 664 + int offset, 665 + int *lenp) 666 + { 667 + return (struct fdt_property *)(uintptr_t) 668 + fdt_get_property_by_offset(fdt, offset, lenp); 669 + } 663 670 664 671 /** 665 672 * fdt_get_property_namelen - find a property based on substring ··· 2122 2115 * -FDT_ERR_TRUNCATED, standard meanings 2123 2116 */ 2124 2117 int fdt_overlay_apply(void *fdt, void *fdto); 2118 + 2119 + /** 2120 + * fdt_overlay_target_offset - retrieves the offset of a fragment's target 2121 + * @fdt: Base device tree blob 2122 + * @fdto: Device tree overlay blob 2123 + * @fragment_offset: node offset of the fragment in the overlay 2124 + * @pathp: pointer which receives the path of the target (or NULL) 2125 + * 2126 + * fdt_overlay_target_offset() retrieves the target offset in the base 2127 + * device tree of a fragment, no matter how the actual targeting is 2128 + * done (through a phandle or a path) 2129 + * 2130 + * returns: 2131 + * the targeted node offset in the base device tree 2132 + * Negative error code on error 2133 + */ 2134 + int fdt_overlay_target_offset(const void *fdt, const void *fdto, 2135 + int fragment_offset, char const **pathp); 2125 2136 2126 2137 /**********************************************************************/ 2127 2138 /* Debugging / informational functions */
+36 -3
scripts/dtc/livetree.c
··· 581 581 582 582 struct node *get_node_by_ref(struct node *tree, const char *ref) 583 583 { 584 + struct node *target = tree; 585 + const char *label = NULL, *path = NULL; 586 + 584 587 if (streq(ref, "/")) 585 588 return tree; 586 - else if (ref[0] == '/') 587 - return get_node_by_path(tree, ref); 589 + 590 + if (ref[0] == '/') 591 + path = ref; 588 592 else 589 - return get_node_by_label(tree, ref); 593 + label = ref; 594 + 595 + if (label) { 596 + const char *slash = strchr(label, '/'); 597 + char *buf = NULL; 598 + 599 + if (slash) { 600 + buf = xstrndup(label, slash - label); 601 + label = buf; 602 + path = slash + 1; 603 + } 604 + 605 + target = get_node_by_label(tree, label); 606 + 607 + free(buf); 608 + 609 + if (!target) 610 + return NULL; 611 + } 612 + 613 + if (path) 614 + target = get_node_by_path(target, path); 615 + 616 + return target; 590 617 } 591 618 592 619 cell_t get_node_phandle(struct node *root, struct node *node) ··· 918 891 919 892 /* m->ref can only be a REF_PHANDLE, but check anyway */ 920 893 assert(m->type == REF_PHANDLE); 894 + 895 + /* The format only permits fixups for references to label, not 896 + * references to path */ 897 + if (strchr(m->ref, '/')) 898 + die("Can't generate fixup for reference to path &{%s}\n", 899 + m->ref); 921 900 922 901 /* there shouldn't be any ':' in the arguments */ 923 902 if (strchr(node->fullpath, ':') || strchr(prop->name, ':'))
+13 -2
scripts/dtc/util.c
··· 33 33 return d; 34 34 } 35 35 36 + char *xstrndup(const char *s, size_t n) 37 + { 38 + size_t len = strnlen(s, n) + 1; 39 + char *d = xmalloc(len); 40 + 41 + memcpy(d, s, len - 1); 42 + d[len - 1] = '\0'; 43 + 44 + return d; 45 + } 46 + 36 47 int xavsprintf_append(char **strp, const char *fmt, va_list ap) 37 48 { 38 49 int n, size = 0; /* start with 128 bytes */ ··· 364 353 } 365 354 366 355 /* we should now have a type */ 367 - if ((*fmt == '\0') || !strchr("iuxs", *fmt)) 356 + if ((*fmt == '\0') || !strchr("iuxsr", *fmt)) 368 357 return -1; 369 358 370 359 /* convert qualifier (bhL) to byte size */ 371 - if (*fmt != 's') 360 + if (*fmt != 's' && *fmt != 'r') 372 361 *size = qualifier == 'b' ? 1 : 373 362 qualifier == 'h' ? 2 : 374 363 qualifier == 'l' ? 4 : -1;
+3 -1
scripts/dtc/util.h
··· 61 61 } 62 62 63 63 extern char *xstrdup(const char *s); 64 + extern char *xstrndup(const char *s, size_t len); 64 65 65 66 extern int PRINTF(2, 3) xasprintf(char **strp, const char *fmt, ...); 66 67 extern int PRINTF(2, 3) xasprintf_append(char **strp, const char *fmt, ...); ··· 144 143 * i signed integer 145 144 * u unsigned integer 146 145 * x hex 146 + * r raw 147 147 * 148 148 * TODO: Implement ll modifier (8 bytes) 149 149 * TODO: Implement o type (octal) ··· 162 160 */ 163 161 164 162 #define USAGE_TYPE_MSG \ 165 - "<type>\ts=string, i=int, u=unsigned, x=hex\n" \ 163 + "<type>\ts=string, i=int, u=unsigned, x=hex, r=raw\n" \ 166 164 "\tOptional modifier prefix:\n" \ 167 165 "\t\thh or b=byte, h=2 byte, l=4 byte (default)"; 168 166
+1 -1
scripts/dtc/version_gen.h
··· 1 - #define DTC_VERSION "DTC 1.6.1-g0a3a9d34" 1 + #define DTC_VERSION "DTC 1.6.1-g55778a03"