Added empty node name check

The Devicetree specification states that a node name shall be of form
`node-name@unit-address` and that the `node-name` component cannot be
empty.

However, the `dtc` parser considers a node name as a non-empty
sequences of the allowed characters plus the @ character, and
unit-address extraction is processed after parsing.

This has the side effect of considering an empty name plus an address
as a valid node name (e.g. `@0`).  I've added the node_name_not_empty
check, verifying that the `node->basenamelen` is not zero (unless it's
the root node).

Signed-off-by: Mattia Maldini <mattia512maldini@gmail.com>
[dwg: Re-wrap commit message]
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Maldus512 2026-01-14 14:24:05 +01:00 committed by David Gibson
parent 14dd76b967
commit 7c78c8542d

View file

@ -340,6 +340,14 @@ static void check_node_name_format(struct check *c, struct dt_info *dti,
}
ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
static void check_node_name_not_empty(struct check *c, struct dt_info *dti,
struct node *node)
{
if (node->basenamelen == 0 && node->parent != NULL)
FAIL(c, dti, node, "Empty node name");
}
ERROR(node_name_not_empty, check_node_name_not_empty, NULL, &node_name_chars);
static void check_node_name_vs_property_name(struct check *c,
struct dt_info *dti,
struct node *node)
@ -1899,7 +1907,7 @@ WARNING(graph_endpoint, check_graph_endpoint, NULL, &graph_nodes);
static struct check *check_table[] = {
&duplicate_node_names, &duplicate_property_names,
&node_name_chars, &node_name_format, &property_name_chars,
&node_name_chars, &node_name_format, &node_name_not_empty, &property_name_chars,
&name_is_string, &name_properties, &node_name_vs_property_name,
&duplicate_label,