Skip to content

Commit

Permalink
dtb: Filter out types with the wrong length multiple
Browse files Browse the repository at this point in the history
If we have a property which can be a string or non-string type and its
value has empty strings in it, it gets incorrectly decoded a a non-string.
There's not a great way to solve this heuristic. Perhaps we could count
the number of non-zero length strings and pick string type if it is above
some percentage.

For now, when the length is not a multiple that fits the integer types, we
can for sure remove those integer types. If a string property happens to
have a length matching a integer multiple, then there's still a problem.

Signed-off-by: Rob Herring <robh@kernel.org>
  • Loading branch information
robherring committed Mar 8, 2024
1 parent 43f5156 commit 5c8869e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dtschema/dtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ def prop_value(validator, nodename, p):

# Filter out types impossible for the size of the property
if len(prop_types) > 1:
if len(p) % 8:
prop_types -= {'int64', 'uint64', 'int64-array', 'uint64-array'}
if len(p) % 4:
prop_types -= {'int32', 'uint32', 'int32-array', 'uint32-array', 'phandle', 'phandle-array'}
if len(p) % 2:
prop_types -= {'int16', 'uint16', 'int16-array', 'uint16-array'}

if len(p) > 4:
prop_types -= {'int32', 'uint32', 'phandle'}
else:
Expand Down

0 comments on commit 5c8869e

Please sign in to comment.