1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007.
10 #define TRACE(c, ...) \
12 fprintf(stderr, "=== %s: ", (c)->name); \
13 fprintf(stderr, __VA_ARGS__); \
14 fprintf(stderr, "\n"); \
17 #define TRACE(c, fmt, ...) do { } while (0)
29 typedef void (*check_fn)(struct check *c, struct dt_info *dti, struct node *node);
36 enum checkstatus status;
39 struct check **prereq;
42 #define CHECK_ENTRY(nm_, fn_, d_, w_, e_, ...) \
43 static struct check *nm_##_prereqs[] = { __VA_ARGS__ }; \
44 static struct check nm_ = { \
50 .status = UNCHECKED, \
51 .num_prereqs = ARRAY_SIZE(nm_##_prereqs), \
52 .prereq = nm_##_prereqs, \
54 #define WARNING(nm_, fn_, d_, ...) \
55 CHECK_ENTRY(nm_, fn_, d_, true, false, __VA_ARGS__)
56 #define ERROR(nm_, fn_, d_, ...) \
57 CHECK_ENTRY(nm_, fn_, d_, false, true, __VA_ARGS__)
58 #define CHECK(nm_, fn_, d_, ...) \
59 CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__)
61 static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
63 struct property *prop,
68 struct srcpos *pos = NULL;
71 if (!(c->warn && (quiet < 1)) && !(c->error && (quiet < 2)))
74 if (prop && prop->srcpos)
76 else if (node && node->srcpos)
80 file_str = srcpos_string(pos);
81 xasprintf(&str, "%s", file_str);
83 } else if (streq(dti->outname, "-")) {
84 xasprintf(&str, "<stdout>");
86 xasprintf(&str, "%s", dti->outname);
89 xasprintf_append(&str, ": %s (%s): ",
90 (c->error) ? "ERROR" : "Warning", c->name);
94 xasprintf_append(&str, "%s:%s: ", node->fullpath, prop->name);
96 xasprintf_append(&str, "%s: ", node->fullpath);
100 xavsprintf_append(&str, fmt, ap);
103 xasprintf_append(&str, "\n");
110 file_str = srcpos_string(pos);
111 xasprintf_append(&str, " also defined at %s\n", file_str);
119 #define FAIL(c, dti, node, ...) \
121 TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
122 (c)->status = FAILED; \
123 check_msg((c), dti, node, NULL, __VA_ARGS__); \
126 #define FAIL_PROP(c, dti, node, prop, ...) \
128 TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \
129 (c)->status = FAILED; \
130 check_msg((c), dti, node, prop, __VA_ARGS__); \
134 static void check_nodes_props(struct check *c, struct dt_info *dti, struct node *node)
138 TRACE(c, "%s", node->fullpath);
142 for_each_child(node, child)
143 check_nodes_props(c, dti, child);
146 static bool run_check(struct check *c, struct dt_info *dti)
148 struct node *dt = dti->dt;
152 assert(!c->inprogress);
154 if (c->status != UNCHECKED)
157 c->inprogress = true;
159 for (i = 0; i < c->num_prereqs; i++) {
160 struct check *prq = c->prereq[i];
161 error = error || run_check(prq, dti);
162 if (prq->status != PASSED) {
164 check_msg(c, dti, NULL, NULL, "Failed prerequisite '%s'",
169 if (c->status != UNCHECKED)
172 check_nodes_props(c, dti, dt);
174 if (c->status == UNCHECKED)
177 TRACE(c, "\tCompleted, status %d", c->status);
180 c->inprogress = false;
181 if ((c->status != PASSED) && (c->error))
187 * Utility check functions
190 /* A check which always fails, for testing purposes only */
191 static inline void check_always_fail(struct check *c, struct dt_info *dti,
194 FAIL(c, dti, node, "always_fail check");
196 CHECK(always_fail, check_always_fail, NULL);
198 static void check_is_string(struct check *c, struct dt_info *dti,
201 struct property *prop;
202 char *propname = c->data;
204 prop = get_property(node, propname);
206 return; /* Not present, assumed ok */
208 if (!data_is_one_string(prop->val))
209 FAIL_PROP(c, dti, node, prop, "property is not a string");
211 #define WARNING_IF_NOT_STRING(nm, propname) \
212 WARNING(nm, check_is_string, (propname))
213 #define ERROR_IF_NOT_STRING(nm, propname) \
214 ERROR(nm, check_is_string, (propname))
216 static void check_is_string_list(struct check *c, struct dt_info *dti,
220 struct property *prop;
221 char *propname = c->data;
224 prop = get_property(node, propname);
226 return; /* Not present, assumed ok */
231 l = strnlen(str, rem);
233 FAIL_PROP(c, dti, node, prop, "property is not a string list");
240 #define WARNING_IF_NOT_STRING_LIST(nm, propname) \
241 WARNING(nm, check_is_string_list, (propname))
242 #define ERROR_IF_NOT_STRING_LIST(nm, propname) \
243 ERROR(nm, check_is_string_list, (propname))
245 static void check_is_cell(struct check *c, struct dt_info *dti,
248 struct property *prop;
249 char *propname = c->data;
251 prop = get_property(node, propname);
253 return; /* Not present, assumed ok */
255 if (prop->val.len != sizeof(cell_t))
256 FAIL_PROP(c, dti, node, prop, "property is not a single cell");
258 #define WARNING_IF_NOT_CELL(nm, propname) \
259 WARNING(nm, check_is_cell, (propname))
260 #define ERROR_IF_NOT_CELL(nm, propname) \
261 ERROR(nm, check_is_cell, (propname))
264 * Structural check functions
267 static void check_duplicate_node_names(struct check *c, struct dt_info *dti,
270 struct node *child, *child2;
272 for_each_child(node, child)
273 for (child2 = child->next_sibling;
275 child2 = child2->next_sibling)
276 if (streq(child->name, child2->name))
277 FAIL(c, dti, child2, "Duplicate node name");
279 ERROR(duplicate_node_names, check_duplicate_node_names, NULL);
281 static void check_duplicate_property_names(struct check *c, struct dt_info *dti,
284 struct property *prop, *prop2;
286 for_each_property(node, prop) {
287 for (prop2 = prop->next; prop2; prop2 = prop2->next) {
290 if (streq(prop->name, prop2->name))
291 FAIL_PROP(c, dti, node, prop, "Duplicate property name");
295 ERROR(duplicate_property_names, check_duplicate_property_names, NULL);
297 #define LOWERCASE "abcdefghijklmnopqrstuvwxyz"
298 #define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
299 #define DIGITS "0123456789"
300 #define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-"
301 #define PROPNODECHARSSTRICT LOWERCASE UPPERCASE DIGITS ",-"
303 static void check_node_name_chars(struct check *c, struct dt_info *dti,
306 int n = strspn(node->name, c->data);
308 if (n < strlen(node->name))
309 FAIL(c, dti, node, "Bad character '%c' in node name",
312 ERROR(node_name_chars, check_node_name_chars, PROPNODECHARS "@");
314 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
317 int n = strspn(node->name, c->data);
319 if (n < node->basenamelen)
320 FAIL(c, dti, node, "Character '%c' not recommended in node name",
323 CHECK(node_name_chars_strict, check_node_name_chars_strict, PROPNODECHARSSTRICT);
325 static void check_node_name_format(struct check *c, struct dt_info *dti,
328 if (strchr(get_unitname(node), '@'))
329 FAIL(c, dti, node, "multiple '@' characters in node name");
331 ERROR(node_name_format, check_node_name_format, NULL, &node_name_chars);
333 static void check_unit_address_vs_reg(struct check *c, struct dt_info *dti,
336 const char *unitname = get_unitname(node);
337 struct property *prop = get_property(node, "reg");
339 if (get_subnode(node, "__overlay__")) {
340 /* HACK: Overlay fragments are a special case */
345 prop = get_property(node, "ranges");
346 if (prop && !prop->val.len)
352 FAIL(c, dti, node, "node has a reg or ranges property, but no unit name");
355 FAIL(c, dti, node, "node has a unit name, but no reg or ranges property");
358 WARNING(unit_address_vs_reg, check_unit_address_vs_reg, NULL);
360 static void check_property_name_chars(struct check *c, struct dt_info *dti,
363 struct property *prop;
365 for_each_property(node, prop) {
366 int n = strspn(prop->name, c->data);
368 if (n < strlen(prop->name))
369 FAIL_PROP(c, dti, node, prop, "Bad character '%c' in property name",
373 ERROR(property_name_chars, check_property_name_chars, PROPNODECHARS);
375 static void check_property_name_chars_strict(struct check *c,
379 struct property *prop;
381 for_each_property(node, prop) {
382 const char *name = prop->name;
383 int n = strspn(name, c->data);
385 if (n == strlen(prop->name))
388 /* Certain names are whitelisted */
389 if (streq(name, "device_type"))
393 * # is only allowed at the beginning of property names not counting
396 if (name[n] == '#' && ((n == 0) || (name[n-1] == ','))) {
398 n = strspn(name, c->data);
400 if (n < strlen(name))
401 FAIL_PROP(c, dti, node, prop, "Character '%c' not recommended in property name",
405 CHECK(property_name_chars_strict, check_property_name_chars_strict, PROPNODECHARSSTRICT);
407 #define DESCLABEL_FMT "%s%s%s%s%s"
408 #define DESCLABEL_ARGS(node,prop,mark) \
409 ((mark) ? "value of " : ""), \
410 ((prop) ? "'" : ""), \
411 ((prop) ? (prop)->name : ""), \
412 ((prop) ? "' in " : ""), (node)->fullpath
414 static void check_duplicate_label(struct check *c, struct dt_info *dti,
415 const char *label, struct node *node,
416 struct property *prop, struct marker *mark)
418 struct node *dt = dti->dt;
419 struct node *othernode = NULL;
420 struct property *otherprop = NULL;
421 struct marker *othermark = NULL;
423 othernode = get_node_by_label(dt, label);
426 otherprop = get_property_by_label(dt, label, &othernode);
428 othermark = get_marker_label(dt, label, &othernode,
434 if ((othernode != node) || (otherprop != prop) || (othermark != mark))
435 FAIL(c, dti, node, "Duplicate label '%s' on " DESCLABEL_FMT
436 " and " DESCLABEL_FMT,
437 label, DESCLABEL_ARGS(node, prop, mark),
438 DESCLABEL_ARGS(othernode, otherprop, othermark));
441 static void check_duplicate_label_node(struct check *c, struct dt_info *dti,
445 struct property *prop;
447 for_each_label(node->labels, l)
448 check_duplicate_label(c, dti, l->label, node, NULL, NULL);
450 for_each_property(node, prop) {
451 struct marker *m = prop->val.markers;
453 for_each_label(prop->labels, l)
454 check_duplicate_label(c, dti, l->label, node, prop, NULL);
456 for_each_marker_of_type(m, LABEL)
457 check_duplicate_label(c, dti, m->ref, node, prop, m);
460 ERROR(duplicate_label, check_duplicate_label_node, NULL);
462 static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
463 struct node *node, const char *propname)
465 struct node *root = dti->dt;
466 struct property *prop;
470 prop = get_property(node, propname);
474 if (prop->val.len != sizeof(cell_t)) {
475 FAIL_PROP(c, dti, node, prop, "bad length (%d) %s property",
476 prop->val.len, prop->name);
480 m = prop->val.markers;
481 for_each_marker_of_type(m, REF_PHANDLE) {
482 assert(m->offset == 0);
483 if (node != get_node_by_ref(root, m->ref))
484 /* "Set this node's phandle equal to some
485 * other node's phandle". That's nonsensical
486 * by construction. */ {
487 FAIL(c, dti, node, "%s is a reference to another node",
490 /* But setting this node's phandle equal to its own
491 * phandle is allowed - that means allocate a unique
492 * phandle for this node, even if it's not otherwise
493 * referenced. The value will be filled in later, so
494 * we treat it as having no phandle data for now. */
498 phandle = propval_cell(prop);
500 if ((phandle == 0) || (phandle == -1)) {
501 FAIL_PROP(c, dti, node, prop, "bad value (0x%x) in %s property",
502 phandle, prop->name);
509 static void check_explicit_phandles(struct check *c, struct dt_info *dti,
512 struct node *root = dti->dt;
514 cell_t phandle, linux_phandle;
516 /* Nothing should have assigned phandles yet */
517 assert(!node->phandle);
519 phandle = check_phandle_prop(c, dti, node, "phandle");
521 linux_phandle = check_phandle_prop(c, dti, node, "linux,phandle");
523 if (!phandle && !linux_phandle)
524 /* No valid phandles; nothing further to check */
527 if (linux_phandle && phandle && (phandle != linux_phandle))
528 FAIL(c, dti, node, "mismatching 'phandle' and 'linux,phandle'"
531 if (linux_phandle && !phandle)
532 phandle = linux_phandle;
534 other = get_node_by_phandle(root, phandle);
535 if (other && (other != node)) {
536 FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)",
537 phandle, other->fullpath);
541 node->phandle = phandle;
543 ERROR(explicit_phandles, check_explicit_phandles, NULL);
545 static void check_name_properties(struct check *c, struct dt_info *dti,
548 struct property **pp, *prop = NULL;
550 for (pp = &node->proplist; *pp; pp = &((*pp)->next))
551 if (streq((*pp)->name, "name")) {
557 return; /* No name property, that's fine */
559 if ((prop->val.len != node->basenamelen+1)
560 || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) {
561 FAIL(c, dti, node, "\"name\" property is incorrect (\"%s\" instead"
562 " of base node name)", prop->val.val);
564 /* The name property is correct, and therefore redundant.
568 data_free(prop->val);
572 ERROR_IF_NOT_STRING(name_is_string, "name");
573 ERROR(name_properties, check_name_properties, NULL, &name_is_string);
576 * Reference fixup functions
579 static void fixup_phandle_references(struct check *c, struct dt_info *dti,
582 struct node *dt = dti->dt;
583 struct property *prop;
585 for_each_property(node, prop) {
586 struct marker *m = prop->val.markers;
587 struct node *refnode;
590 for_each_marker_of_type(m, REF_PHANDLE) {
591 assert(m->offset + sizeof(cell_t) <= prop->val.len);
593 refnode = get_node_by_ref(dt, m->ref);
595 if (!(dti->dtsflags & DTSF_PLUGIN))
596 FAIL(c, dti, node, "Reference to non-existent node or "
597 "label \"%s\"\n", m->ref);
598 else /* mark the entry as unresolved */
599 *((fdt32_t *)(prop->val.val + m->offset)) =
600 cpu_to_fdt32(0xffffffff);
604 phandle = get_node_phandle(dt, refnode);
605 *((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
607 reference_node(refnode);
611 ERROR(phandle_references, fixup_phandle_references, NULL,
612 &duplicate_node_names, &explicit_phandles);
614 static void fixup_path_references(struct check *c, struct dt_info *dti,
617 struct node *dt = dti->dt;
618 struct property *prop;
620 for_each_property(node, prop) {
621 struct marker *m = prop->val.markers;
622 struct node *refnode;
625 for_each_marker_of_type(m, REF_PATH) {
626 assert(m->offset <= prop->val.len);
628 refnode = get_node_by_ref(dt, m->ref);
630 FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n",
635 path = refnode->fullpath;
636 prop->val = data_insert_at_marker(prop->val, m, path,
639 reference_node(refnode);
643 ERROR(path_references, fixup_path_references, NULL, &duplicate_node_names);
645 static void fixup_omit_unused_nodes(struct check *c, struct dt_info *dti,
648 if (generate_symbols && node->labels)
650 if (node->omit_if_unused && !node->is_referenced)
653 ERROR(omit_unused_nodes, fixup_omit_unused_nodes, NULL, &phandle_references, &path_references);
658 WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells");
659 WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells");
660 WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells");
662 WARNING_IF_NOT_STRING(device_type_is_string, "device_type");
663 WARNING_IF_NOT_STRING(model_is_string, "model");
664 WARNING_IF_NOT_STRING(status_is_string, "status");
665 WARNING_IF_NOT_STRING(label_is_string, "label");
667 WARNING_IF_NOT_STRING_LIST(compatible_is_string_list, "compatible");
669 static void check_names_is_string_list(struct check *c, struct dt_info *dti,
672 struct property *prop;
674 for_each_property(node, prop) {
675 const char *s = strrchr(prop->name, '-');
676 if (!s || !streq(s, "-names"))
679 c->data = prop->name;
680 check_is_string_list(c, dti, node);
683 WARNING(names_is_string_list, check_names_is_string_list, NULL);
685 static void check_alias_paths(struct check *c, struct dt_info *dti,
688 struct property *prop;
690 if (!streq(node->name, "aliases"))
693 for_each_property(node, prop) {
694 if (streq(prop->name, "phandle")
695 || streq(prop->name, "linux,phandle")) {
699 if (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val)) {
700 FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
704 if (strspn(prop->name, LOWERCASE DIGITS "-") != strlen(prop->name))
705 FAIL(c, dti, node, "aliases property name must include only lowercase and '-'");
708 WARNING(alias_paths, check_alias_paths, NULL);
710 static void fixup_addr_size_cells(struct check *c, struct dt_info *dti,
713 struct property *prop;
715 node->addr_cells = -1;
716 node->size_cells = -1;
718 prop = get_property(node, "#address-cells");
720 node->addr_cells = propval_cell(prop);
722 prop = get_property(node, "#size-cells");
724 node->size_cells = propval_cell(prop);
726 WARNING(addr_size_cells, fixup_addr_size_cells, NULL,
727 &address_cells_is_cell, &size_cells_is_cell);
729 #define node_addr_cells(n) \
730 (((n)->addr_cells == -1) ? 2 : (n)->addr_cells)
731 #define node_size_cells(n) \
732 (((n)->size_cells == -1) ? 1 : (n)->size_cells)
734 static void check_reg_format(struct check *c, struct dt_info *dti,
737 struct property *prop;
738 int addr_cells, size_cells, entrylen;
740 prop = get_property(node, "reg");
742 return; /* No "reg", that's fine */
745 FAIL(c, dti, node, "Root node has a \"reg\" property");
749 if (prop->val.len == 0)
750 FAIL_PROP(c, dti, node, prop, "property is empty");
752 addr_cells = node_addr_cells(node->parent);
753 size_cells = node_size_cells(node->parent);
754 entrylen = (addr_cells + size_cells) * sizeof(cell_t);
756 if (!entrylen || (prop->val.len % entrylen) != 0)
757 FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) "
758 "(#address-cells == %d, #size-cells == %d)",
759 prop->val.len, addr_cells, size_cells);
761 WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);
763 static void check_ranges_format(struct check *c, struct dt_info *dti,
766 struct property *prop;
767 int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen;
768 const char *ranges = c->data;
770 prop = get_property(node, ranges);
775 FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property",
780 p_addr_cells = node_addr_cells(node->parent);
781 p_size_cells = node_size_cells(node->parent);
782 c_addr_cells = node_addr_cells(node);
783 c_size_cells = node_size_cells(node);
784 entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t);
786 if (prop->val.len == 0) {
787 if (p_addr_cells != c_addr_cells)
788 FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
789 "#address-cells (%d) differs from %s (%d)",
790 ranges, c_addr_cells, node->parent->fullpath,
792 if (p_size_cells != c_size_cells)
793 FAIL_PROP(c, dti, node, prop, "empty \"%s\" property but its "
794 "#size-cells (%d) differs from %s (%d)",
795 ranges, c_size_cells, node->parent->fullpath,
797 } else if ((prop->val.len % entrylen) != 0) {
798 FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
799 "(parent #address-cells == %d, child #address-cells == %d, "
800 "#size-cells == %d)", ranges, prop->val.len,
801 p_addr_cells, c_addr_cells, c_size_cells);
804 WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
805 WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
807 static const struct bus_type pci_bus = {
811 static void check_pci_bridge(struct check *c, struct dt_info *dti, struct node *node)
813 struct property *prop;
816 prop = get_property(node, "device_type");
817 if (!prop || !streq(prop->val.val, "pci"))
820 node->bus = &pci_bus;
822 if (!strprefixeq(node->name, node->basenamelen, "pci") &&
823 !strprefixeq(node->name, node->basenamelen, "pcie"))
824 FAIL(c, dti, node, "node name is not \"pci\" or \"pcie\"");
826 prop = get_property(node, "ranges");
828 FAIL(c, dti, node, "missing ranges for PCI bridge (or not a bridge)");
830 if (node_addr_cells(node) != 3)
831 FAIL(c, dti, node, "incorrect #address-cells for PCI bridge");
832 if (node_size_cells(node) != 2)
833 FAIL(c, dti, node, "incorrect #size-cells for PCI bridge");
835 prop = get_property(node, "bus-range");
839 if (prop->val.len != (sizeof(cell_t) * 2)) {
840 FAIL_PROP(c, dti, node, prop, "value must be 2 cells");
843 cells = (cell_t *)prop->val.val;
844 if (fdt32_to_cpu(cells[0]) > fdt32_to_cpu(cells[1]))
845 FAIL_PROP(c, dti, node, prop, "1st cell must be less than or equal to 2nd cell");
846 if (fdt32_to_cpu(cells[1]) > 0xff)
847 FAIL_PROP(c, dti, node, prop, "maximum bus number must be less than 256");
849 WARNING(pci_bridge, check_pci_bridge, NULL,
850 &device_type_is_string, &addr_size_cells);
852 static void check_pci_device_bus_num(struct check *c, struct dt_info *dti, struct node *node)
854 struct property *prop;
855 unsigned int bus_num, min_bus, max_bus;
858 if (!node->parent || (node->parent->bus != &pci_bus))
861 prop = get_property(node, "reg");
865 cells = (cell_t *)prop->val.val;
866 bus_num = (fdt32_to_cpu(cells[0]) & 0x00ff0000) >> 16;
868 prop = get_property(node->parent, "bus-range");
870 min_bus = max_bus = 0;
872 cells = (cell_t *)prop->val.val;
873 min_bus = fdt32_to_cpu(cells[0]);
874 max_bus = fdt32_to_cpu(cells[0]);
876 if ((bus_num < min_bus) || (bus_num > max_bus))
877 FAIL_PROP(c, dti, node, prop, "PCI bus number %d out of range, expected (%d - %d)",
878 bus_num, min_bus, max_bus);
880 WARNING(pci_device_bus_num, check_pci_device_bus_num, NULL, ®_format, &pci_bridge);
882 static void check_pci_device_reg(struct check *c, struct dt_info *dti, struct node *node)
884 struct property *prop;
885 const char *unitname = get_unitname(node);
887 unsigned int dev, func, reg;
890 if (!node->parent || (node->parent->bus != &pci_bus))
893 prop = get_property(node, "reg");
897 cells = (cell_t *)prop->val.val;
898 if (cells[1] || cells[2])
899 FAIL_PROP(c, dti, node, prop, "PCI reg config space address cells 2 and 3 must be 0");
901 reg = fdt32_to_cpu(cells[0]);
902 dev = (reg & 0xf800) >> 11;
903 func = (reg & 0x700) >> 8;
905 if (reg & 0xff000000)
906 FAIL_PROP(c, dti, node, prop, "PCI reg address is not configuration space");
907 if (reg & 0x000000ff)
908 FAIL_PROP(c, dti, node, prop, "PCI reg config space address register number must be 0");
911 snprintf(unit_addr, sizeof(unit_addr), "%x", dev);
912 if (streq(unitname, unit_addr))
916 snprintf(unit_addr, sizeof(unit_addr), "%x,%x", dev, func);
917 if (streq(unitname, unit_addr))
920 FAIL(c, dti, node, "PCI unit address format error, expected \"%s\"",
923 WARNING(pci_device_reg, check_pci_device_reg, NULL, ®_format, &pci_bridge);
925 static const struct bus_type simple_bus = {
926 .name = "simple-bus",
929 static bool node_is_compatible(struct node *node, const char *compat)
931 struct property *prop;
932 const char *str, *end;
934 prop = get_property(node, "compatible");
938 for (str = prop->val.val, end = str + prop->val.len; str < end;
939 str += strnlen(str, end - str) + 1) {
940 if (streq(str, compat))
946 static void check_simple_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
948 if (node_is_compatible(node, "simple-bus"))
949 node->bus = &simple_bus;
951 WARNING(simple_bus_bridge, check_simple_bus_bridge, NULL,
952 &addr_size_cells, &compatible_is_string_list);
954 static void check_simple_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
956 struct property *prop;
957 const char *unitname = get_unitname(node);
961 cell_t *cells = NULL;
963 if (!node->parent || (node->parent->bus != &simple_bus))
966 prop = get_property(node, "reg");
968 cells = (cell_t *)prop->val.val;
970 prop = get_property(node, "ranges");
971 if (prop && prop->val.len)
972 /* skip of child address */
973 cells = ((cell_t *)prop->val.val) + node_addr_cells(node);
977 if (node->parent->parent && !(node->bus == &simple_bus))
978 FAIL(c, dti, node, "missing or empty reg/ranges property");
982 size = node_addr_cells(node->parent);
984 reg = (reg << 32) | fdt32_to_cpu(*(cells++));
986 snprintf(unit_addr, sizeof(unit_addr), "%"PRIx64, reg);
987 if (!streq(unitname, unit_addr))
988 FAIL(c, dti, node, "simple-bus unit address format error, expected \"%s\"",
991 WARNING(simple_bus_reg, check_simple_bus_reg, NULL, ®_format, &simple_bus_bridge);
993 static const struct bus_type i2c_bus = {
997 static void check_i2c_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
999 if (strprefixeq(node->name, node->basenamelen, "i2c-bus") ||
1000 strprefixeq(node->name, node->basenamelen, "i2c-arb")) {
1001 node->bus = &i2c_bus;
1002 } else if (strprefixeq(node->name, node->basenamelen, "i2c")) {
1004 for_each_child(node, child) {
1005 if (strprefixeq(child->name, node->basenamelen, "i2c-bus"))
1008 node->bus = &i2c_bus;
1012 if (!node->children)
1015 if (node_addr_cells(node) != 1)
1016 FAIL(c, dti, node, "incorrect #address-cells for I2C bus");
1017 if (node_size_cells(node) != 0)
1018 FAIL(c, dti, node, "incorrect #size-cells for I2C bus");
1021 WARNING(i2c_bus_bridge, check_i2c_bus_bridge, NULL, &addr_size_cells);
1023 #define I2C_OWN_SLAVE_ADDRESS (1U << 30)
1024 #define I2C_TEN_BIT_ADDRESS (1U << 31)
1026 static void check_i2c_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
1028 struct property *prop;
1029 const char *unitname = get_unitname(node);
1033 cell_t *cells = NULL;
1035 if (!node->parent || (node->parent->bus != &i2c_bus))
1038 prop = get_property(node, "reg");
1040 cells = (cell_t *)prop->val.val;
1043 FAIL(c, dti, node, "missing or empty reg property");
1047 reg = fdt32_to_cpu(*cells);
1048 /* Ignore I2C_OWN_SLAVE_ADDRESS */
1049 reg &= ~I2C_OWN_SLAVE_ADDRESS;
1050 snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
1051 if (!streq(unitname, unit_addr))
1052 FAIL(c, dti, node, "I2C bus unit address format error, expected \"%s\"",
1055 for (len = prop->val.len; len > 0; len -= 4) {
1056 reg = fdt32_to_cpu(*(cells++));
1057 /* Ignore I2C_OWN_SLAVE_ADDRESS */
1058 reg &= ~I2C_OWN_SLAVE_ADDRESS;
1060 if ((reg & I2C_TEN_BIT_ADDRESS) && ((reg & ~I2C_TEN_BIT_ADDRESS) > 0x3ff))
1061 FAIL_PROP(c, dti, node, prop, "I2C address must be less than 10-bits, got \"0x%x\"",
1063 else if (reg > 0x7f)
1064 FAIL_PROP(c, dti, node, prop, "I2C address must be less than 7-bits, got \"0x%x\". Set I2C_TEN_BIT_ADDRESS for 10 bit addresses or fix the property",
1068 WARNING(i2c_bus_reg, check_i2c_bus_reg, NULL, ®_format, &i2c_bus_bridge);
1070 static const struct bus_type spi_bus = {
1074 static void check_spi_bus_bridge(struct check *c, struct dt_info *dti, struct node *node)
1076 int spi_addr_cells = 1;
1078 if (strprefixeq(node->name, node->basenamelen, "spi")) {
1079 node->bus = &spi_bus;
1081 /* Try to detect SPI buses which don't have proper node name */
1084 if (node_addr_cells(node) != 1 || node_size_cells(node) != 0)
1087 for_each_child(node, child) {
1088 struct property *prop;
1089 for_each_property(child, prop) {
1090 if (strprefixeq(prop->name, 4, "spi-")) {
1091 node->bus = &spi_bus;
1095 if (node->bus == &spi_bus)
1099 if (node->bus == &spi_bus && get_property(node, "reg"))
1100 FAIL(c, dti, node, "node name for SPI buses should be 'spi'");
1102 if (node->bus != &spi_bus || !node->children)
1105 if (get_property(node, "spi-slave"))
1107 if (node_addr_cells(node) != spi_addr_cells)
1108 FAIL(c, dti, node, "incorrect #address-cells for SPI bus");
1109 if (node_size_cells(node) != 0)
1110 FAIL(c, dti, node, "incorrect #size-cells for SPI bus");
1113 WARNING(spi_bus_bridge, check_spi_bus_bridge, NULL, &addr_size_cells);
1115 static void check_spi_bus_reg(struct check *c, struct dt_info *dti, struct node *node)
1117 struct property *prop;
1118 const char *unitname = get_unitname(node);
1121 cell_t *cells = NULL;
1123 if (!node->parent || (node->parent->bus != &spi_bus))
1126 if (get_property(node->parent, "spi-slave"))
1129 prop = get_property(node, "reg");
1131 cells = (cell_t *)prop->val.val;
1134 FAIL(c, dti, node, "missing or empty reg property");
1138 reg = fdt32_to_cpu(*cells);
1139 snprintf(unit_addr, sizeof(unit_addr), "%x", reg);
1140 if (!streq(unitname, unit_addr))
1141 FAIL(c, dti, node, "SPI bus unit address format error, expected \"%s\"",
1144 WARNING(spi_bus_reg, check_spi_bus_reg, NULL, ®_format, &spi_bus_bridge);
1146 static void check_unit_address_format(struct check *c, struct dt_info *dti,
1149 const char *unitname = get_unitname(node);
1151 if (node->parent && node->parent->bus)
1157 if (!strncmp(unitname, "0x", 2)) {
1158 FAIL(c, dti, node, "unit name should not have leading \"0x\"");
1159 /* skip over 0x for next test */
1162 if (unitname[0] == '0' && isxdigit(unitname[1]))
1163 FAIL(c, dti, node, "unit name should not have leading 0s");
1165 WARNING(unit_address_format, check_unit_address_format, NULL,
1166 &node_name_format, &pci_bridge, &simple_bus_bridge);
1171 static void check_avoid_default_addr_size(struct check *c, struct dt_info *dti,
1174 struct property *reg, *ranges;
1177 return; /* Ignore root node */
1179 reg = get_property(node, "reg");
1180 ranges = get_property(node, "ranges");
1182 if (!reg && !ranges)
1185 if (node->parent->addr_cells == -1)
1186 FAIL(c, dti, node, "Relying on default #address-cells value");
1188 if (node->parent->size_cells == -1)
1189 FAIL(c, dti, node, "Relying on default #size-cells value");
1191 WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
1194 static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti,
1197 struct property *prop;
1199 bool has_reg = false;
1201 if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
1204 if (get_property(node, "ranges") || !node->children)
1207 for_each_child(node, child) {
1208 prop = get_property(child, "reg");
1214 FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\" or child \"reg\" property");
1216 WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
1218 static bool node_is_disabled(struct node *node)
1220 struct property *prop;
1222 prop = get_property(node, "status");
1224 char *str = prop->val.val;
1225 if (streq("disabled", str))
1232 static void check_unique_unit_address_common(struct check *c,
1233 struct dt_info *dti,
1237 struct node *childa;
1239 if (node->addr_cells < 0 || node->size_cells < 0)
1242 if (!node->children)
1245 for_each_child(node, childa) {
1246 struct node *childb;
1247 const char *addr_a = get_unitname(childa);
1249 if (!strlen(addr_a))
1252 if (disable_check && node_is_disabled(childa))
1255 for_each_child(node, childb) {
1256 const char *addr_b = get_unitname(childb);
1257 if (childa == childb)
1260 if (disable_check && node_is_disabled(childb))
1263 if (streq(addr_a, addr_b))
1264 FAIL(c, dti, childb, "duplicate unit-address (also used in node %s)", childa->fullpath);
1269 static void check_unique_unit_address(struct check *c, struct dt_info *dti,
1272 check_unique_unit_address_common(c, dti, node, false);
1274 WARNING(unique_unit_address, check_unique_unit_address, NULL, &avoid_default_addr_size);
1276 static void check_unique_unit_address_if_enabled(struct check *c, struct dt_info *dti,
1279 check_unique_unit_address_common(c, dti, node, true);
1281 CHECK_ENTRY(unique_unit_address_if_enabled, check_unique_unit_address_if_enabled,
1282 NULL, false, false, &avoid_default_addr_size);
1284 static void check_obsolete_chosen_interrupt_controller(struct check *c,
1285 struct dt_info *dti,
1288 struct node *dt = dti->dt;
1289 struct node *chosen;
1290 struct property *prop;
1296 chosen = get_node_by_path(dt, "/chosen");
1300 prop = get_property(chosen, "interrupt-controller");
1302 FAIL_PROP(c, dti, node, prop,
1303 "/chosen has obsolete \"interrupt-controller\" property");
1305 WARNING(obsolete_chosen_interrupt_controller,
1306 check_obsolete_chosen_interrupt_controller, NULL);
1308 static void check_chosen_node_is_root(struct check *c, struct dt_info *dti,
1311 if (!streq(node->name, "chosen"))
1314 if (node->parent != dti->dt)
1315 FAIL(c, dti, node, "chosen node must be at root node");
1317 WARNING(chosen_node_is_root, check_chosen_node_is_root, NULL);
1319 static void check_chosen_node_bootargs(struct check *c, struct dt_info *dti,
1322 struct property *prop;
1324 if (!streq(node->name, "chosen"))
1327 prop = get_property(node, "bootargs");
1331 c->data = prop->name;
1332 check_is_string(c, dti, node);
1334 WARNING(chosen_node_bootargs, check_chosen_node_bootargs, NULL);
1336 static void check_chosen_node_stdout_path(struct check *c, struct dt_info *dti,
1339 struct property *prop;
1341 if (!streq(node->name, "chosen"))
1344 prop = get_property(node, "stdout-path");
1346 prop = get_property(node, "linux,stdout-path");
1349 FAIL_PROP(c, dti, node, prop, "Use 'stdout-path' instead");
1352 c->data = prop->name;
1353 check_is_string(c, dti, node);
1355 WARNING(chosen_node_stdout_path, check_chosen_node_stdout_path, NULL);
1358 const char *prop_name;
1359 const char *cell_name;
1363 static void check_property_phandle_args(struct check *c,
1364 struct dt_info *dti,
1366 struct property *prop,
1367 const struct provider *provider)
1369 struct node *root = dti->dt;
1370 int cell, cellsize = 0;
1372 if (prop->val.len % sizeof(cell_t)) {
1373 FAIL_PROP(c, dti, node, prop,
1374 "property size (%d) is invalid, expected multiple of %zu",
1375 prop->val.len, sizeof(cell_t));
1379 for (cell = 0; cell < prop->val.len / sizeof(cell_t); cell += cellsize + 1) {
1380 struct node *provider_node;
1381 struct property *cellprop;
1384 phandle = propval_cell_n(prop, cell);
1386 * Some bindings use a cell value 0 or -1 to skip over optional
1387 * entries when each index position has a specific definition.
1389 if (phandle == 0 || phandle == -1) {
1390 /* Give up if this is an overlay with external references */
1391 if (dti->dtsflags & DTSF_PLUGIN)
1398 /* If we have markers, verify the current cell is a phandle */
1399 if (prop->val.markers) {
1400 struct marker *m = prop->val.markers;
1401 for_each_marker_of_type(m, REF_PHANDLE) {
1402 if (m->offset == (cell * sizeof(cell_t)))
1406 FAIL_PROP(c, dti, node, prop,
1407 "cell %d is not a phandle reference",
1411 provider_node = get_node_by_phandle(root, phandle);
1412 if (!provider_node) {
1413 FAIL_PROP(c, dti, node, prop,
1414 "Could not get phandle node for (cell %d)",
1419 cellprop = get_property(provider_node, provider->cell_name);
1421 cellsize = propval_cell(cellprop);
1422 } else if (provider->optional) {
1425 FAIL(c, dti, node, "Missing property '%s' in node %s or bad phandle (referred from %s[%d])",
1426 provider->cell_name,
1427 provider_node->fullpath,
1432 if (prop->val.len < ((cell + cellsize + 1) * sizeof(cell_t))) {
1433 FAIL_PROP(c, dti, node, prop,
1434 "property size (%d) too small for cell size %d",
1435 prop->val.len, cellsize);
1440 static void check_provider_cells_property(struct check *c,
1441 struct dt_info *dti,
1444 struct provider *provider = c->data;
1445 struct property *prop;
1447 prop = get_property(node, provider->prop_name);
1451 check_property_phandle_args(c, dti, node, prop, provider);
1453 #define WARNING_PROPERTY_PHANDLE_CELLS(nm, propname, cells_name, ...) \
1454 static struct provider nm##_provider = { (propname), (cells_name), __VA_ARGS__ }; \
1455 WARNING(nm##_property, check_provider_cells_property, &nm##_provider, &phandle_references);
1457 WARNING_PROPERTY_PHANDLE_CELLS(clocks, "clocks", "#clock-cells");
1458 WARNING_PROPERTY_PHANDLE_CELLS(cooling_device, "cooling-device", "#cooling-cells");
1459 WARNING_PROPERTY_PHANDLE_CELLS(dmas, "dmas", "#dma-cells");
1460 WARNING_PROPERTY_PHANDLE_CELLS(hwlocks, "hwlocks", "#hwlock-cells");
1461 WARNING_PROPERTY_PHANDLE_CELLS(interrupts_extended, "interrupts-extended", "#interrupt-cells");
1462 WARNING_PROPERTY_PHANDLE_CELLS(io_channels, "io-channels", "#io-channel-cells");
1463 WARNING_PROPERTY_PHANDLE_CELLS(iommus, "iommus", "#iommu-cells");
1464 WARNING_PROPERTY_PHANDLE_CELLS(mboxes, "mboxes", "#mbox-cells");
1465 WARNING_PROPERTY_PHANDLE_CELLS(msi_parent, "msi-parent", "#msi-cells", true);
1466 WARNING_PROPERTY_PHANDLE_CELLS(mux_controls, "mux-controls", "#mux-control-cells");
1467 WARNING_PROPERTY_PHANDLE_CELLS(phys, "phys", "#phy-cells");
1468 WARNING_PROPERTY_PHANDLE_CELLS(power_domains, "power-domains", "#power-domain-cells");
1469 WARNING_PROPERTY_PHANDLE_CELLS(pwms, "pwms", "#pwm-cells");
1470 WARNING_PROPERTY_PHANDLE_CELLS(resets, "resets", "#reset-cells");
1471 WARNING_PROPERTY_PHANDLE_CELLS(sound_dai, "sound-dai", "#sound-dai-cells");
1472 WARNING_PROPERTY_PHANDLE_CELLS(thermal_sensors, "thermal-sensors", "#thermal-sensor-cells");
1474 static bool prop_is_gpio(struct property *prop)
1479 * *-gpios and *-gpio can appear in property names,
1480 * so skip over any false matches (only one known ATM)
1482 if (strstr(prop->name, "nr-gpio"))
1485 str = strrchr(prop->name, '-');
1490 if (!(streq(str, "gpios") || streq(str, "gpio")))
1496 static void check_gpios_property(struct check *c,
1497 struct dt_info *dti,
1500 struct property *prop;
1502 /* Skip GPIO hog nodes which have 'gpios' property */
1503 if (get_property(node, "gpio-hog"))
1506 for_each_property(node, prop) {
1507 struct provider provider;
1509 if (!prop_is_gpio(prop))
1512 provider.prop_name = prop->name;
1513 provider.cell_name = "#gpio-cells";
1514 provider.optional = false;
1515 check_property_phandle_args(c, dti, node, prop, &provider);
1519 WARNING(gpios_property, check_gpios_property, NULL, &phandle_references);
1521 static void check_deprecated_gpio_property(struct check *c,
1522 struct dt_info *dti,
1525 struct property *prop;
1527 for_each_property(node, prop) {
1530 if (!prop_is_gpio(prop))
1533 str = strstr(prop->name, "gpio");
1534 if (!streq(str, "gpio"))
1537 FAIL_PROP(c, dti, node, prop,
1538 "'[*-]gpio' is deprecated, use '[*-]gpios' instead");
1542 CHECK(deprecated_gpio_property, check_deprecated_gpio_property, NULL);
1544 static bool node_is_interrupt_provider(struct node *node)
1546 struct property *prop;
1548 prop = get_property(node, "interrupt-controller");
1552 prop = get_property(node, "interrupt-map");
1559 static void check_interrupt_provider(struct check *c,
1560 struct dt_info *dti,
1563 struct property *prop;
1565 if (!node_is_interrupt_provider(node))
1568 prop = get_property(node, "#interrupt-cells");
1571 "Missing #interrupt-cells in interrupt provider");
1573 prop = get_property(node, "#address-cells");
1576 "Missing #address-cells in interrupt provider");
1578 WARNING(interrupt_provider, check_interrupt_provider, NULL);
1580 static void check_interrupts_property(struct check *c,
1581 struct dt_info *dti,
1584 struct node *root = dti->dt;
1585 struct node *irq_node = NULL, *parent = node;
1586 struct property *irq_prop, *prop = NULL;
1587 int irq_cells, phandle;
1589 irq_prop = get_property(node, "interrupts");
1593 if (irq_prop->val.len % sizeof(cell_t))
1594 FAIL_PROP(c, dti, node, irq_prop, "size (%d) is invalid, expected multiple of %zu",
1595 irq_prop->val.len, sizeof(cell_t));
1597 while (parent && !prop) {
1598 if (parent != node && node_is_interrupt_provider(parent)) {
1603 prop = get_property(parent, "interrupt-parent");
1605 phandle = propval_cell(prop);
1606 if ((phandle == 0) || (phandle == -1)) {
1607 /* Give up if this is an overlay with
1608 * external references */
1609 if (dti->dtsflags & DTSF_PLUGIN)
1611 FAIL_PROP(c, dti, parent, prop, "Invalid phandle");
1615 irq_node = get_node_by_phandle(root, phandle);
1617 FAIL_PROP(c, dti, parent, prop, "Bad phandle");
1620 if (!node_is_interrupt_provider(irq_node))
1621 FAIL(c, dti, irq_node,
1622 "Missing interrupt-controller or interrupt-map property");
1627 parent = parent->parent;
1631 FAIL(c, dti, node, "Missing interrupt-parent");
1635 prop = get_property(irq_node, "#interrupt-cells");
1637 /* We warn about that already in another test. */
1641 irq_cells = propval_cell(prop);
1642 if (irq_prop->val.len % (irq_cells * sizeof(cell_t))) {
1643 FAIL_PROP(c, dti, node, prop,
1644 "size is (%d), expected multiple of %d",
1645 irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)));
1648 WARNING(interrupts_property, check_interrupts_property, &phandle_references);
1650 static const struct bus_type graph_port_bus = {
1651 .name = "graph-port",
1654 static const struct bus_type graph_ports_bus = {
1655 .name = "graph-ports",
1658 static void check_graph_nodes(struct check *c, struct dt_info *dti,
1663 for_each_child(node, child) {
1664 if (!(strprefixeq(child->name, child->basenamelen, "endpoint") ||
1665 get_property(child, "remote-endpoint")))
1668 node->bus = &graph_port_bus;
1670 /* The parent of 'port' nodes can be either 'ports' or a device */
1671 if (!node->parent->bus &&
1672 (streq(node->parent->name, "ports") || get_property(node, "reg")))
1673 node->parent->bus = &graph_ports_bus;
1679 WARNING(graph_nodes, check_graph_nodes, NULL);
1681 static void check_graph_child_address(struct check *c, struct dt_info *dti,
1687 if (node->bus != &graph_ports_bus && node->bus != &graph_port_bus)
1690 for_each_child(node, child) {
1691 struct property *prop = get_property(child, "reg");
1693 /* No error if we have any non-zero unit address */
1694 if (prop && propval_cell(prop) != 0)
1700 if (cnt == 1 && node->addr_cells != -1)
1701 FAIL(c, dti, node, "graph node has single child node '%s', #address-cells/#size-cells are not necessary",
1702 node->children->name);
1704 WARNING(graph_child_address, check_graph_child_address, NULL, &graph_nodes);
1706 static void check_graph_reg(struct check *c, struct dt_info *dti,
1710 const char *unitname = get_unitname(node);
1711 struct property *prop;
1713 prop = get_property(node, "reg");
1714 if (!prop || !unitname)
1717 if (!(prop->val.val && prop->val.len == sizeof(cell_t))) {
1718 FAIL(c, dti, node, "graph node malformed 'reg' property");
1722 snprintf(unit_addr, sizeof(unit_addr), "%x", propval_cell(prop));
1723 if (!streq(unitname, unit_addr))
1724 FAIL(c, dti, node, "graph node unit address error, expected \"%s\"",
1727 if (node->parent->addr_cells != 1)
1728 FAIL_PROP(c, dti, node, get_property(node, "#address-cells"),
1729 "graph node '#address-cells' is %d, must be 1",
1730 node->parent->addr_cells);
1731 if (node->parent->size_cells != 0)
1732 FAIL_PROP(c, dti, node, get_property(node, "#size-cells"),
1733 "graph node '#size-cells' is %d, must be 0",
1734 node->parent->size_cells);
1737 static void check_graph_port(struct check *c, struct dt_info *dti,
1740 if (node->bus != &graph_port_bus)
1743 if (!strprefixeq(node->name, node->basenamelen, "port"))
1744 FAIL(c, dti, node, "graph port node name should be 'port'");
1746 check_graph_reg(c, dti, node);
1748 WARNING(graph_port, check_graph_port, NULL, &graph_nodes);
1750 static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
1751 struct node *endpoint)
1755 struct property *prop;
1757 prop = get_property(endpoint, "remote-endpoint");
1761 phandle = propval_cell(prop);
1762 /* Give up if this is an overlay with external references */
1763 if (phandle == 0 || phandle == -1)
1766 node = get_node_by_phandle(dti->dt, phandle);
1768 FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid");
1773 static void check_graph_endpoint(struct check *c, struct dt_info *dti,
1776 struct node *remote_node;
1778 if (!node->parent || node->parent->bus != &graph_port_bus)
1781 if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
1782 FAIL(c, dti, node, "graph endpoint node name should be 'endpoint'");
1784 check_graph_reg(c, dti, node);
1786 remote_node = get_remote_endpoint(c, dti, node);
1790 if (get_remote_endpoint(c, dti, remote_node) != node)
1791 FAIL(c, dti, node, "graph connection to node '%s' is not bidirectional",
1792 remote_node->fullpath);
1794 WARNING(graph_endpoint, check_graph_endpoint, NULL, &graph_nodes);
1796 static struct check *check_table[] = {
1797 &duplicate_node_names, &duplicate_property_names,
1798 &node_name_chars, &node_name_format, &property_name_chars,
1799 &name_is_string, &name_properties,
1804 &phandle_references, &path_references,
1807 &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell,
1808 &device_type_is_string, &model_is_string, &status_is_string,
1811 &compatible_is_string_list, &names_is_string_list,
1813 &property_name_chars_strict,
1814 &node_name_chars_strict,
1816 &addr_size_cells, ®_format, &ranges_format, &dma_ranges_format,
1818 &unit_address_vs_reg,
1819 &unit_address_format,
1823 &pci_device_bus_num,
1834 &avoid_default_addr_size,
1835 &avoid_unnecessary_addr_size,
1836 &unique_unit_address,
1837 &unique_unit_address_if_enabled,
1838 &obsolete_chosen_interrupt_controller,
1839 &chosen_node_is_root, &chosen_node_bootargs, &chosen_node_stdout_path,
1842 &cooling_device_property,
1845 &interrupts_extended_property,
1846 &io_channels_property,
1849 &msi_parent_property,
1850 &mux_controls_property,
1852 &power_domains_property,
1855 &sound_dai_property,
1856 &thermal_sensors_property,
1858 &deprecated_gpio_property,
1860 &interrupts_property,
1861 &interrupt_provider,
1865 &graph_nodes, &graph_child_address, &graph_port, &graph_endpoint,
1870 static void enable_warning_error(struct check *c, bool warn, bool error)
1874 /* Raising level, also raise it for prereqs */
1875 if ((warn && !c->warn) || (error && !c->error))
1876 for (i = 0; i < c->num_prereqs; i++)
1877 enable_warning_error(c->prereq[i], warn, error);
1879 c->warn = c->warn || warn;
1880 c->error = c->error || error;
1883 static void disable_warning_error(struct check *c, bool warn, bool error)
1887 /* Lowering level, also lower it for things this is the prereq
1889 if ((warn && c->warn) || (error && c->error)) {
1890 for (i = 0; i < ARRAY_SIZE(check_table); i++) {
1891 struct check *cc = check_table[i];
1894 for (j = 0; j < cc->num_prereqs; j++)
1895 if (cc->prereq[j] == c)
1896 disable_warning_error(cc, warn, error);
1900 c->warn = c->warn && !warn;
1901 c->error = c->error && !error;
1904 void parse_checks_option(bool warn, bool error, const char *arg)
1907 const char *name = arg;
1910 if ((strncmp(arg, "no-", 3) == 0)
1911 || (strncmp(arg, "no_", 3) == 0)) {
1916 for (i = 0; i < ARRAY_SIZE(check_table); i++) {
1917 struct check *c = check_table[i];
1919 if (streq(c->name, name)) {
1921 enable_warning_error(c, warn, error);
1923 disable_warning_error(c, warn, error);
1928 die("Unrecognized check name \"%s\"\n", name);
1931 void process_checks(bool force, struct dt_info *dti)
1936 for (i = 0; i < ARRAY_SIZE(check_table); i++) {
1937 struct check *c = check_table[i];
1939 if (c->warn || c->error)
1940 error = error || run_check(c, dti);
1945 fprintf(stderr, "ERROR: Input tree has errors, aborting "
1946 "(use -f to force output)\n");
1948 } else if (quiet < 3) {
1949 fprintf(stderr, "Warning: Input tree has errors, "