[Skiboot] [PATCH v2] core/device.c: Fix dt_find_compatible_node
stewart at linux.vnet.ibm.com
Tue Feb 13 19:25:45 AEDT 2018
Alistair Popple <alistair at popple.id.au> writes:
> dt_find_compatible_node() and dt_find_compatible_node_on_chip() are used to
> find device nodes under a parent/root node with a given compatible
> dt_next(root, prev) is used to walk the child nodes of the given parent and
> takes two arguments - root contains the parent node to walk whilst prev
> contains the previous child to search from so that it can be used as an
> iterator over all children nodes.
> The first iteration of dt_find_compatible_node(root, prev) calls
> dt_next(root, root) which is not a well defined operation as prev is
> assumed to be child of the root node. The result is that when a node
> contains no children it will start returning the parent nodes siblings
> until it hits the top of the tree at which point a NULL derefence is
> attempted when looking for the root nodes parent.
> Dereferencing NULL can result in undesirable data exceptions during system
> boot and untimely non-hilarious system crashes. dt_next() should not be
> called with prev == root. Instead we add a check to dt_next() such that
> passing prev = NULL will cause it to start iterating from the first child
> node (if any).
> Also add a unit test for this case to run-device.c.
> Signed-off-by: Alistair Popple <alistair at popple.id.au>
Merged to master as of 55c13bd1231a51e0109eeadc17cbbf46fa649f02
OPAL Architect, IBM.
More information about the Skiboot