Attention is currently required from: Julius Werner, Martin L Roth, Maximilian Brune.
Jakub Czapiga has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/81081?usp=email )
Change subject: lib/device_tree: Add some FDT helper functions ......................................................................
Patch Set 6:
(3 comments)
Patchset:
PS6:
Test failed with exception: Segmentation fault(11) […]
I tested it on my machine and it fails too. There is incorrect memory access in `tests_lib_device_tree-test(tests).test_fdt_find_node_by_path`
1. You should align arrays:
The devicetree blob shall be located at an 8-byte-aligned address. To maintain backwards compatibilty for 32-bit machines, 4-byte alignment is supported by some software, but this is not DTSpec-compliant.
``` uint8_ dtb[] __attribute__((aligned(8))) = ... ```
2. Code segfaults at:
```log [==========] tests_lib_device_tree-test(tests): Running 4 test(s). [ RUN ] test_fdt_find_node_by_path
Program received signal SIGSEGV, Segmentation fault. 0x0000000000401ac0 in fdt_find_multiple_nodes_by_path (blob=blob@entry=0x41d980 <dtb>, path=<optimized out>, path@entry=0x4020ad "/cpus/cpu@*", addrcp=addrcp@entry=0x7fffffffce50, sizecp=sizecp@entry=0x7fffffffce54, results=results@entry=0x7fffffffce58, count_results=count_results@entry=0x7fffffffce4e) at src/lib/device_tree.c:272 272 node_offset = results[(*count_results)++] = off; // save occurrence (gdb) where #0 0x0000000000401ac0 in fdt_find_multiple_nodes_by_path (blob=blob@entry=0x41d980 <dtb>, path=<optimized out>, path@entry=0x4020ad "/cpus/cpu@*", addrcp=addrcp@entry=0x7fffffffce50, sizecp=sizecp@entry=0x7fffffffce54, results=results@entry=0x7fffffffce58, count_results=count_results@entry=0x7fffffffce4e) at src/lib/device_tree.c:272 #1 0x00000000004015a3 in test_fdt_find_node_by_path (state=<optimized out>) at tests/lib/device_tree-test.c:50 #2 0x00007ffff7fbb75d in cmocka_run_one_test_or_fixture () from build/tests/util/cmocka/src/libcmocka.so.0 #3 0x00007ffff7fbba2b in cmocka_run_one_tests () from build/tests/util/cmocka/src/libcmocka.so.0 #4 0x00007ffff7fbbfb1 in _cmocka_run_group_tests () from build/tests/util/cmocka/src/libcmocka.so.0 #5 0x00000000004010ab in main () at tests/lib/device_tree-test.c:97
```
`count_results` reaches absurd numbers in thousands, because you use it without initialization, as was passed from caller.
ALSO please fix checkpatch issues wherever possible. xxd files can be omited.
File src/lib/device_tree.c:
https://review.coreboot.org/c/coreboot/+/81081/comment/4d305d44_016460a1 : PS6, Line 67: size = fdt_next_node_name(blob, offset, &name); `int size = ...`. Let's not multiply code without need.
https://review.coreboot.org/c/coreboot/+/81081/comment/38d9202f_d945ef0d : PS6, Line 272: node_offset = results[(*count_results)++] = off; // save occurrence `count_results` is left uninitialized. More info in another comment.