From 44bb89cafd3d96b8df0f324b652c7bf804b38c05 Mon Sep 17 00:00:00 2001 From: Johannes Beisswenger Date: Fri, 14 Apr 2023 14:17:38 +0200 Subject: checks: Fix segmentation fault in check_graph_node Dts files which contain an 'endpoint' node as a direct child of the root node cause a segmentation fault inside check_graph_node(). This type of error can easily happen when a 'remote-endpoint' property is accidentally placed outside the corresponding endpoint and port nodes. Example with 'endpoint' node: /dts-v1/; / { endpoint {}; }; Example with remote-endpoint property: /dts-v1/; / { foo { remote-endpoint = <0xdeadbeef>; }; }; Signed-off-by: Johannes Beisswenger Signed-off-by: David Gibson --- checks.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/checks.c b/checks.c index 16bc7f6..8ed7a60 100644 --- a/checks.c +++ b/checks.c @@ -1767,6 +1767,11 @@ static void check_graph_nodes(struct check *c, struct dt_info *dti, get_property(child, "remote-endpoint"))) continue; + /* The root node cannot be a port */ + if (!node->parent) { + FAIL(c, dti, node, "root node contains endpoint node '%s', potentially misplaced remote-endpoint property", child->name); + continue; + } node->bus = &graph_port_bus; /* The parent of 'port' nodes can be either 'ports' or a device */ -- cgit v1.2.1