diff options
author | Rob Herring <robh@kernel.org> | 2018-03-06 18:49:15 -0600 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2018-03-07 14:32:28 +1100 |
commit | 2347c96edcbea4cf59f47430a0de14d4fdedb0af (patch) | |
tree | 1bc952a9d92cec3c00deb3ce61e7a2dbd9509f75 | |
parent | 8f1b35f88395adea01ce1100c5faa27dacbc8410 (diff) | |
download | device-tree-compiler-2347c96edcbea4cf59f47430a0de14d4fdedb0af.tar.gz |
checks: add a check for duplicate unit-addresses of child nodes
Child nodes with the same unit-address (and different node names) are
either an error or just bad DT design. Typical errors are the unit-address
is just wrong (i.e. doesn't match reg value) or multiple children using the
same overlapping area. Overlapping regions are considered an error in new
bindings, but do exist in some existing trees. This check should flag
most but not all of those errors. Finding all cases would require doing
address translations and creating a full map of address spaces.
Mixing more than one address/number space at a level is bad design. It only
works if both spaces can use the same #address-cells and #size-cells sizes.
It also complicates parsing have a mixture of types of child nodes. The
best practice in this case is adding child container nodes for each
address/number space or using additional address bits/cells to encode
different address spaces.
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | checks.c | 31 | ||||
-rwxr-xr-x | tests/run_tests.sh | 1 | ||||
-rw-r--r-- | tests/unit-addr-unique.dts | 14 |
3 files changed, 46 insertions, 0 deletions
@@ -1023,6 +1023,36 @@ static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *d } WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size); +static void check_unique_unit_address(struct check *c, struct dt_info *dti, + struct node *node) +{ + struct node *childa; + + if (node->addr_cells < 0 || node->size_cells < 0) + return; + + if (!node->children) + return; + + for_each_child(node, childa) { + struct node *childb; + const char *addr_a = get_unitname(childa); + + if (!strlen(addr_a)) + continue; + + for_each_child(node, childb) { + const char *addr_b = get_unitname(childb); + if (childa == childb) + break; + + if (streq(addr_a, addr_b)) + FAIL(c, dti, childb, "duplicate unit-address (also used in node %s)", childa->fullpath); + } + } +} +WARNING(unique_unit_address, check_unique_unit_address, NULL, &avoid_default_addr_size); + static void check_obsolete_chosen_interrupt_controller(struct check *c, struct dt_info *dti, struct node *node) @@ -1396,6 +1426,7 @@ static struct check *check_table[] = { &avoid_default_addr_size, &avoid_unnecessary_addr_size, + &unique_unit_address, &obsolete_chosen_interrupt_controller, &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path, diff --git a/tests/run_tests.sh b/tests/run_tests.sh index c2ce1e6..8d66d59 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -596,6 +596,7 @@ dtc_tests () { check_tests unit-addr-without-reg.dts unit_address_vs_reg check_tests unit-addr-leading-0x.dts unit_address_format check_tests unit-addr-leading-0s.dts unit_address_format + check_tests unit-addr-unique.dts unique_unit_address check_tests bad-phandle-cells.dts interrupts_extended_property check_tests bad-gpio.dts gpios_property run_sh_test dtc-checkfails.sh deprecated_gpio_property -- -Wdeprecated_gpio_property -I dts -O dtb bad-gpio.dts diff --git a/tests/unit-addr-unique.dts b/tests/unit-addr-unique.dts new file mode 100644 index 0000000..7cc650b --- /dev/null +++ b/tests/unit-addr-unique.dts @@ -0,0 +1,14 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <0>; + + foo@1 { + reg = <1>; + }; + + bar@1 { + reg = <1>; + }; +}; |