Skip to content

Correct function devicetree_get_compatible()#71

Open
xypron wants to merge 3 commits into
ubuntu:mainfrom
xypron:compatible
Open

Correct function devicetree_get_compatible()#71
xypron wants to merge 3 commits into
ubuntu:mainfrom
xypron:compatible

Conversation

@xypron
Copy link
Copy Markdown
Contributor

@xypron xypron commented May 14, 2026

  • devicetree_get_compatible() does not correctly detect the end of the device-tree.
  • devicetree_get_compatible() will return a compatible property from a child node if no /compatible property exists

Fix the above and add a test.

xypron added 3 commits May 13, 2026 18:59
devicetree_get_compatible() used struct_off + struct_size as
the loop bound while indexing a uint32_t array. That value is a
byte offset, not a word count, so the parser could walk past the
end of the structure block.

Use size_words as the loop bound so the parser only inspects the
actual structure block.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
devicetree_get_compatible() walked the structure block without
tracking nesting depth, so a child node's compatible property
could be returned when it appeared before the root /compatible
property.

Track begin/end node depth while parsing the structure block and
only accept compatible at level 0 so the function matches the
root node property.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Load one DTB with a root compatible property and one with only
a child compatible property, then verify that
devicetree_get_compatible() returns the root string for the
first fixture and NULL for the second.

Wire the test into make check and extend make clean to remove
generated DTBs under test/data.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant