@@ -255,7 +255,7 @@ static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
255255 child2 ;
256256 child2 = child2 -> next_sibling )
257257 if (streq (child -> name , child2 -> name ))
258- FAIL (c , dti , node , "Duplicate node name" );
258+ FAIL (c , dti , child2 , "Duplicate node name" );
259259}
260260ERROR (duplicate_node_names , check_duplicate_node_names , NULL );
261261
@@ -317,6 +317,11 @@ static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
317317 const char * unitname = get_unitname (node );
318318 struct property * prop = get_property (node , "reg" );
319319
320+ if (get_subnode (node , "__overlay__" )) {
321+ /* HACK: Overlay fragments are a special case */
322+ return ;
323+ }
324+
320325 if (!prop ) {
321326 prop = get_property (node , "ranges" );
322327 if (prop && !prop -> val .len )
@@ -579,6 +584,8 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
579584
580585 phandle = get_node_phandle (dt , refnode );
581586 * ((fdt32_t * )(prop -> val .val + m -> offset )) = cpu_to_fdt32 (phandle );
587+
588+ reference_node (refnode );
582589 }
583590 }
584591}
@@ -609,11 +616,21 @@ static void fixup_path_references(struct check *c, struct dt_info *dti,
609616 path = refnode -> fullpath ;
610617 prop -> val = data_insert_at_marker (prop -> val , m , path ,
611618 strlen (path ) + 1 );
619+
620+ reference_node (refnode );
612621 }
613622 }
614623}
615624ERROR (path_references , fixup_path_references , NULL , & duplicate_node_names );
616625
626+ static void fixup_omit_unused_nodes (struct check * c , struct dt_info * dti ,
627+ struct node * node )
628+ {
629+ if (node -> omit_if_unused && !node -> is_referenced )
630+ delete_node (node );
631+ }
632+ ERROR (omit_unused_nodes , fixup_omit_unused_nodes , NULL , & phandle_references , & path_references );
633+
617634/*
618635 * Semantic checks
619636 */
@@ -1017,6 +1034,36 @@ static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *d
10171034}
10181035WARNING (avoid_unnecessary_addr_size , check_avoid_unnecessary_addr_size , NULL , & avoid_default_addr_size );
10191036
1037+ static void check_unique_unit_address (struct check * c , struct dt_info * dti ,
1038+ struct node * node )
1039+ {
1040+ struct node * childa ;
1041+
1042+ if (node -> addr_cells < 0 || node -> size_cells < 0 )
1043+ return ;
1044+
1045+ if (!node -> children )
1046+ return ;
1047+
1048+ for_each_child (node , childa ) {
1049+ struct node * childb ;
1050+ const char * addr_a = get_unitname (childa );
1051+
1052+ if (!strlen (addr_a ))
1053+ continue ;
1054+
1055+ for_each_child (node , childb ) {
1056+ const char * addr_b = get_unitname (childb );
1057+ if (childa == childb )
1058+ break ;
1059+
1060+ if (streq (addr_a , addr_b ))
1061+ FAIL (c , dti , childb , "duplicate unit-address (also used in node %s)" , childa -> fullpath );
1062+ }
1063+ }
1064+ }
1065+ WARNING (unique_unit_address , check_unique_unit_address , NULL , & avoid_default_addr_size );
1066+
10201067static void check_obsolete_chosen_interrupt_controller (struct check * c ,
10211068 struct dt_info * dti ,
10221069 struct node * node )
@@ -1357,6 +1404,152 @@ static void check_interrupts_property(struct check *c,
13571404}
13581405WARNING (interrupts_property , check_interrupts_property , & phandle_references );
13591406
1407+ static const struct bus_type graph_port_bus = {
1408+ .name = "graph-port" ,
1409+ };
1410+
1411+ static const struct bus_type graph_ports_bus = {
1412+ .name = "graph-ports" ,
1413+ };
1414+
1415+ static void check_graph_nodes (struct check * c , struct dt_info * dti ,
1416+ struct node * node )
1417+ {
1418+ struct node * child ;
1419+
1420+ for_each_child (node , child ) {
1421+ if (!(strprefixeq (child -> name , child -> basenamelen , "endpoint" ) ||
1422+ get_property (child , "remote-endpoint" )))
1423+ continue ;
1424+
1425+ node -> bus = & graph_port_bus ;
1426+
1427+ /* The parent of 'port' nodes can be either 'ports' or a device */
1428+ if (!node -> parent -> bus &&
1429+ (streq (node -> parent -> name , "ports" ) || get_property (node , "reg" )))
1430+ node -> parent -> bus = & graph_ports_bus ;
1431+
1432+ break ;
1433+ }
1434+
1435+ }
1436+ WARNING (graph_nodes , check_graph_nodes , NULL );
1437+
1438+ static void check_graph_child_address (struct check * c , struct dt_info * dti ,
1439+ struct node * node )
1440+ {
1441+ int cnt = 0 ;
1442+ struct node * child ;
1443+
1444+ if (node -> bus != & graph_ports_bus && node -> bus != & graph_port_bus )
1445+ return ;
1446+
1447+ for_each_child (node , child ) {
1448+ struct property * prop = get_property (child , "reg" );
1449+
1450+ /* No error if we have any non-zero unit address */
1451+ if (prop && propval_cell (prop ) != 0 )
1452+ return ;
1453+
1454+ cnt ++ ;
1455+ }
1456+
1457+ if (cnt == 1 && node -> addr_cells != -1 )
1458+ FAIL (c , dti , node , "graph node has single child node '%s', #address-cells/#size-cells are not necessary" ,
1459+ node -> children -> name );
1460+ }
1461+ WARNING (graph_child_address , check_graph_child_address , NULL , & graph_nodes );
1462+
1463+ static void check_graph_reg (struct check * c , struct dt_info * dti ,
1464+ struct node * node )
1465+ {
1466+ char unit_addr [9 ];
1467+ const char * unitname = get_unitname (node );
1468+ struct property * prop ;
1469+
1470+ prop = get_property (node , "reg" );
1471+ if (!prop || !unitname )
1472+ return ;
1473+
1474+ if (!(prop -> val .val && prop -> val .len == sizeof (cell_t ))) {
1475+ FAIL (c , dti , node , "graph node malformed 'reg' property" );
1476+ return ;
1477+ }
1478+
1479+ snprintf (unit_addr , sizeof (unit_addr ), "%x" , propval_cell (prop ));
1480+ if (!streq (unitname , unit_addr ))
1481+ FAIL (c , dti , node , "graph node unit address error, expected \"%s\"" ,
1482+ unit_addr );
1483+
1484+ if (node -> parent -> addr_cells != 1 )
1485+ FAIL_PROP (c , dti , node , get_property (node , "#address-cells" ),
1486+ "graph node '#address-cells' is %d, must be 1" ,
1487+ node -> parent -> addr_cells );
1488+ if (node -> parent -> size_cells != 0 )
1489+ FAIL_PROP (c , dti , node , get_property (node , "#size-cells" ),
1490+ "graph node '#size-cells' is %d, must be 0" ,
1491+ node -> parent -> size_cells );
1492+ }
1493+
1494+ static void check_graph_port (struct check * c , struct dt_info * dti ,
1495+ struct node * node )
1496+ {
1497+ if (node -> bus != & graph_port_bus )
1498+ return ;
1499+
1500+ if (!strprefixeq (node -> name , node -> basenamelen , "port" ))
1501+ FAIL (c , dti , node , "graph port node name should be 'port'" );
1502+
1503+ check_graph_reg (c , dti , node );
1504+ }
1505+ WARNING (graph_port , check_graph_port , NULL , & graph_nodes );
1506+
1507+ static struct node * get_remote_endpoint (struct check * c , struct dt_info * dti ,
1508+ struct node * endpoint )
1509+ {
1510+ int phandle ;
1511+ struct node * node ;
1512+ struct property * prop ;
1513+
1514+ prop = get_property (endpoint , "remote-endpoint" );
1515+ if (!prop )
1516+ return NULL ;
1517+
1518+ phandle = propval_cell (prop );
1519+ /* Give up if this is an overlay with external references */
1520+ if (phandle == 0 || phandle == -1 )
1521+ return NULL ;
1522+
1523+ node = get_node_by_phandle (dti -> dt , phandle );
1524+ if (!node )
1525+ FAIL_PROP (c , dti , endpoint , prop , "graph phandle is not valid" );
1526+
1527+ return node ;
1528+ }
1529+
1530+ static void check_graph_endpoint (struct check * c , struct dt_info * dti ,
1531+ struct node * node )
1532+ {
1533+ struct node * remote_node ;
1534+
1535+ if (!node -> parent || node -> parent -> bus != & graph_port_bus )
1536+ return ;
1537+
1538+ if (!strprefixeq (node -> name , node -> basenamelen , "endpoint" ))
1539+ FAIL (c , dti , node , "graph endpont node name should be 'endpoint'" );
1540+
1541+ check_graph_reg (c , dti , node );
1542+
1543+ remote_node = get_remote_endpoint (c , dti , node );
1544+ if (!remote_node )
1545+ return ;
1546+
1547+ if (get_remote_endpoint (c , dti , remote_node ) != node )
1548+ FAIL (c , dti , node , "graph connection to node '%s' is not bidirectional" ,
1549+ remote_node -> fullpath );
1550+ }
1551+ WARNING (graph_endpoint , check_graph_endpoint , NULL , & graph_nodes );
1552+
13601553static struct check * check_table [] = {
13611554 & duplicate_node_names , & duplicate_property_names ,
13621555 & node_name_chars , & node_name_format , & property_name_chars ,
@@ -1366,6 +1559,7 @@ static struct check *check_table[] = {
13661559
13671560 & explicit_phandles ,
13681561 & phandle_references , & path_references ,
1562+ & omit_unused_nodes ,
13691563
13701564 & address_cells_is_cell , & size_cells_is_cell , & interrupt_cells_is_cell ,
13711565 & device_type_is_string , & model_is_string , & status_is_string ,
@@ -1390,6 +1584,7 @@ static struct check *check_table[] = {
13901584
13911585 & avoid_default_addr_size ,
13921586 & avoid_unnecessary_addr_size ,
1587+ & unique_unit_address ,
13931588 & obsolete_chosen_interrupt_controller ,
13941589 & chosen_node_is_root , & chosen_node_bootargs , & chosen_node_stdout_path ,
13951590
@@ -1416,6 +1611,8 @@ static struct check *check_table[] = {
14161611
14171612 & alias_paths ,
14181613
1614+ & graph_nodes , & graph_child_address , & graph_port , & graph_endpoint ,
1615+
14191616 & always_fail ,
14201617};
14211618
0 commit comments