checks.c revision 238742
1/* 2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2007. 3 * 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 * USA 19 */ 20 21#include "dtc.h" 22 23#ifdef TRACE_CHECKS 24#define TRACE(c, ...) \ 25 do { \ 26 fprintf(stderr, "=== %s: ", (c)->name); \ 27 fprintf(stderr, __VA_ARGS__); \ 28 fprintf(stderr, "\n"); \ 29 } while (0) 30#else 31#define TRACE(c, fmt, ...) do { } while (0) 32#endif 33 34enum checkstatus { 35 UNCHECKED = 0, 36 PREREQ, 37 PASSED, 38 FAILED, 39}; 40 41struct check; 42 43typedef void (*tree_check_fn)(struct check *c, struct node *dt); 44typedef void (*node_check_fn)(struct check *c, struct node *dt, struct node *node); 45typedef void (*prop_check_fn)(struct check *c, struct node *dt, 46 struct node *node, struct property *prop); 47 48struct check { 49 const char *name; 50 tree_check_fn tree_fn; 51 node_check_fn node_fn; 52 prop_check_fn prop_fn; 53 void *data; 54 bool warn, error; 55 enum checkstatus status; 56 int inprogress; 57 int num_prereqs; 58 struct check **prereq; 59}; 60 61#define CHECK_ENTRY(nm, tfn, nfn, pfn, d, w, e, ...) \ 62 static struct check *nm##_prereqs[] = { __VA_ARGS__ }; \ 63 static struct check nm = { \ 64 .name = #nm, \ 65 .tree_fn = (tfn), \ 66 .node_fn = (nfn), \ 67 .prop_fn = (pfn), \ 68 .data = (d), \ 69 .warn = (w), \ 70 .error = (e), \ 71 .status = UNCHECKED, \ 72 .num_prereqs = ARRAY_SIZE(nm##_prereqs), \ 73 .prereq = nm##_prereqs, \ 74 }; 75#define WARNING(nm, tfn, nfn, pfn, d, ...) \ 76 CHECK_ENTRY(nm, tfn, nfn, pfn, d, true, false, __VA_ARGS__) 77#define ERROR(nm, tfn, nfn, pfn, d, ...) \ 78 CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, true, __VA_ARGS__) 79#define CHECK(nm, tfn, nfn, pfn, d, ...) \ 80 CHECK_ENTRY(nm, tfn, nfn, pfn, d, false, false, __VA_ARGS__) 81 82#define TREE_WARNING(nm, d, ...) \ 83 WARNING(nm, check_##nm, NULL, NULL, d, __VA_ARGS__) 84#define TREE_ERROR(nm, d, ...) \ 85 ERROR(nm, check_##nm, NULL, NULL, d, __VA_ARGS__) 86#define TREE_CHECK(nm, d, ...) \ 87 CHECK(nm, check_##nm, NULL, NULL, d, __VA_ARGS__) 88#define NODE_WARNING(nm, d, ...) \ 89 WARNING(nm, NULL, check_##nm, NULL, d, __VA_ARGS__) 90#define NODE_ERROR(nm, d, ...) \ 91 ERROR(nm, NULL, check_##nm, NULL, d, __VA_ARGS__) 92#define NODE_CHECK(nm, d, ...) \ 93 CHECK(nm, NULL, check_##nm, NULL, d, __VA_ARGS__) 94#define PROP_WARNING(nm, d, ...) \ 95 WARNING(nm, NULL, NULL, check_##nm, d, __VA_ARGS__) 96#define PROP_ERROR(nm, d, ...) \ 97 ERROR(nm, NULL, NULL, check_##nm, d, __VA_ARGS__) 98#define PROP_CHECK(nm, d, ...) \ 99 CHECK(nm, NULL, NULL, check_##nm, d, __VA_ARGS__) 100 101#ifdef __GNUC__ 102static inline void check_msg(struct check *c, const char *fmt, ...) __attribute__((format (printf, 2, 3))); 103#endif 104static inline void check_msg(struct check *c, const char *fmt, ...) 105{ 106 va_list ap; 107 va_start(ap, fmt); 108 109 if ((c->warn && (quiet < 1)) 110 || (c->error && (quiet < 2))) { 111 fprintf(stderr, "%s (%s): ", 112 (c->error) ? "ERROR" : "Warning", c->name); 113 vfprintf(stderr, fmt, ap); 114 fprintf(stderr, "\n"); 115 } 116} 117 118#define FAIL(c, ...) \ 119 do { \ 120 TRACE((c), "\t\tFAILED at %s:%d", __FILE__, __LINE__); \ 121 (c)->status = FAILED; \ 122 check_msg((c), __VA_ARGS__); \ 123 } while (0) 124 125static void check_nodes_props(struct check *c, struct node *dt, struct node *node) 126{ 127 struct node *child; 128 struct property *prop; 129 130 TRACE(c, "%s", node->fullpath); 131 if (c->node_fn) 132 c->node_fn(c, dt, node); 133 134 if (c->prop_fn) 135 for_each_property(node, prop) { 136 TRACE(c, "%s\t'%s'", node->fullpath, prop->name); 137 c->prop_fn(c, dt, node, prop); 138 } 139 140 for_each_child(node, child) 141 check_nodes_props(c, dt, child); 142} 143 144static int run_check(struct check *c, struct node *dt) 145{ 146 int error = 0; 147 int i; 148 149 assert(!c->inprogress); 150 151 if (c->status != UNCHECKED) 152 goto out; 153 154 c->inprogress = 1; 155 156 for (i = 0; i < c->num_prereqs; i++) { 157 struct check *prq = c->prereq[i]; 158 error |= run_check(prq, dt); 159 if (prq->status != PASSED) { 160 c->status = PREREQ; 161 check_msg(c, "Failed prerequisite '%s'", 162 c->prereq[i]->name); 163 } 164 } 165 166 if (c->status != UNCHECKED) 167 goto out; 168 169 if (c->node_fn || c->prop_fn) 170 check_nodes_props(c, dt, dt); 171 172 if (c->tree_fn) 173 c->tree_fn(c, dt); 174 if (c->status == UNCHECKED) 175 c->status = PASSED; 176 177 TRACE(c, "\tCompleted, status %d", c->status); 178 179out: 180 c->inprogress = 0; 181 if ((c->status != PASSED) && (c->error)) 182 error = 1; 183 return error; 184} 185 186/* 187 * Utility check functions 188 */ 189 190/* A check which always fails, for testing purposes only */ 191static inline void check_always_fail(struct check *c, struct node *dt) 192{ 193 FAIL(c, "always_fail check"); 194} 195TREE_CHECK(always_fail, NULL); 196 197static void check_is_string(struct check *c, struct node *root, 198 struct node *node) 199{ 200 struct property *prop; 201 char *propname = c->data; 202 203 prop = get_property(node, propname); 204 if (!prop) 205 return; /* Not present, assumed ok */ 206 207 if (!data_is_one_string(prop->val)) 208 FAIL(c, "\"%s\" property in %s is not a string", 209 propname, node->fullpath); 210} 211#define WARNING_IF_NOT_STRING(nm, propname) \ 212 WARNING(nm, NULL, check_is_string, NULL, (propname)) 213#define ERROR_IF_NOT_STRING(nm, propname) \ 214 ERROR(nm, NULL, check_is_string, NULL, (propname)) 215 216static void check_is_cell(struct check *c, struct node *root, 217 struct node *node) 218{ 219 struct property *prop; 220 char *propname = c->data; 221 222 prop = get_property(node, propname); 223 if (!prop) 224 return; /* Not present, assumed ok */ 225 226 if (prop->val.len != sizeof(cell_t)) 227 FAIL(c, "\"%s\" property in %s is not a single cell", 228 propname, node->fullpath); 229} 230#define WARNING_IF_NOT_CELL(nm, propname) \ 231 WARNING(nm, NULL, check_is_cell, NULL, (propname)) 232#define ERROR_IF_NOT_CELL(nm, propname) \ 233 ERROR(nm, NULL, check_is_cell, NULL, (propname)) 234 235/* 236 * Structural check functions 237 */ 238 239static void check_duplicate_node_names(struct check *c, struct node *dt, 240 struct node *node) 241{ 242 struct node *child, *child2; 243 244 for_each_child(node, child) 245 for (child2 = child->next_sibling; 246 child2; 247 child2 = child2->next_sibling) 248 if (streq(child->name, child2->name)) 249 FAIL(c, "Duplicate node name %s", 250 child->fullpath); 251} 252NODE_ERROR(duplicate_node_names, NULL); 253 254static void check_duplicate_property_names(struct check *c, struct node *dt, 255 struct node *node) 256{ 257 struct property *prop, *prop2; 258 259 for_each_property(node, prop) 260 for (prop2 = prop->next; prop2; prop2 = prop2->next) 261 if (streq(prop->name, prop2->name)) 262 FAIL(c, "Duplicate property name %s in %s", 263 prop->name, node->fullpath); 264} 265NODE_ERROR(duplicate_property_names, NULL); 266 267#define LOWERCASE "abcdefghijklmnopqrstuvwxyz" 268#define UPPERCASE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 269#define DIGITS "0123456789" 270#define PROPNODECHARS LOWERCASE UPPERCASE DIGITS ",._+*#?-" 271 272static void check_node_name_chars(struct check *c, struct node *dt, 273 struct node *node) 274{ 275 int n = strspn(node->name, c->data); 276 277 if (n < strlen(node->name)) 278 FAIL(c, "Bad character '%c' in node %s", 279 node->name[n], node->fullpath); 280} 281NODE_ERROR(node_name_chars, PROPNODECHARS "@"); 282 283static void check_node_name_format(struct check *c, struct node *dt, 284 struct node *node) 285{ 286 if (strchr(get_unitname(node), '@')) 287 FAIL(c, "Node %s has multiple '@' characters in name", 288 node->fullpath); 289} 290NODE_ERROR(node_name_format, NULL, &node_name_chars); 291 292static void check_property_name_chars(struct check *c, struct node *dt, 293 struct node *node, struct property *prop) 294{ 295 int n = strspn(prop->name, c->data); 296 297 if (n < strlen(prop->name)) 298 FAIL(c, "Bad character '%c' in property name \"%s\", node %s", 299 prop->name[n], prop->name, node->fullpath); 300} 301PROP_ERROR(property_name_chars, PROPNODECHARS); 302 303#define DESCLABEL_FMT "%s%s%s%s%s" 304#define DESCLABEL_ARGS(node,prop,mark) \ 305 ((mark) ? "value of " : ""), \ 306 ((prop) ? "'" : ""), \ 307 ((prop) ? (prop)->name : ""), \ 308 ((prop) ? "' in " : ""), (node)->fullpath 309 310static void check_duplicate_label(struct check *c, struct node *dt, 311 const char *label, struct node *node, 312 struct property *prop, struct marker *mark) 313{ 314 struct node *othernode = NULL; 315 struct property *otherprop = NULL; 316 struct marker *othermark = NULL; 317 318 othernode = get_node_by_label(dt, label); 319 320 if (!othernode) 321 otherprop = get_property_by_label(dt, label, &othernode); 322 if (!othernode) 323 othermark = get_marker_label(dt, label, &othernode, 324 &otherprop); 325 326 if (!othernode) 327 return; 328 329 if ((othernode != node) || (otherprop != prop) || (othermark != mark)) 330 FAIL(c, "Duplicate label '%s' on " DESCLABEL_FMT 331 " and " DESCLABEL_FMT, 332 label, DESCLABEL_ARGS(node, prop, mark), 333 DESCLABEL_ARGS(othernode, otherprop, othermark)); 334} 335 336static void check_duplicate_label_node(struct check *c, struct node *dt, 337 struct node *node) 338{ 339 struct label *l; 340 341 for_each_label(node->labels, l) 342 check_duplicate_label(c, dt, l->label, node, NULL, NULL); 343} 344static void check_duplicate_label_prop(struct check *c, struct node *dt, 345 struct node *node, struct property *prop) 346{ 347 struct marker *m = prop->val.markers; 348 struct label *l; 349 350 for_each_label(prop->labels, l) 351 check_duplicate_label(c, dt, l->label, node, prop, NULL); 352 353 for_each_marker_of_type(m, LABEL) 354 check_duplicate_label(c, dt, m->ref, node, prop, m); 355} 356ERROR(duplicate_label, NULL, check_duplicate_label_node, 357 check_duplicate_label_prop, NULL); 358 359static void check_explicit_phandles(struct check *c, struct node *root, 360 struct node *node, struct property *prop) 361{ 362 struct marker *m; 363 struct node *other; 364 cell_t phandle; 365 366 if (!streq(prop->name, "phandle") 367 && !streq(prop->name, "linux,phandle")) 368 return; 369 370 if (prop->val.len != sizeof(cell_t)) { 371 FAIL(c, "%s has bad length (%d) %s property", 372 node->fullpath, prop->val.len, prop->name); 373 return; 374 } 375 376 m = prop->val.markers; 377 for_each_marker_of_type(m, REF_PHANDLE) { 378 assert(m->offset == 0); 379 if (node != get_node_by_ref(root, m->ref)) 380 /* "Set this node's phandle equal to some 381 * other node's phandle". That's nonsensical 382 * by construction. */ { 383 FAIL(c, "%s in %s is a reference to another node", 384 prop->name, node->fullpath); 385 return; 386 } 387 /* But setting this node's phandle equal to its own 388 * phandle is allowed - that means allocate a unique 389 * phandle for this node, even if it's not otherwise 390 * referenced. The value will be filled in later, so 391 * no further checking for now. */ 392 return; 393 } 394 395 phandle = propval_cell(prop); 396 397 if ((phandle == 0) || (phandle == -1)) { 398 FAIL(c, "%s has bad value (0x%x) in %s property", 399 node->fullpath, phandle, prop->name); 400 return; 401 } 402 403 if (node->phandle && (node->phandle != phandle)) 404 FAIL(c, "%s has %s property which replaces existing phandle information", 405 node->fullpath, prop->name); 406 407 other = get_node_by_phandle(root, phandle); 408 if (other && (other != node)) { 409 FAIL(c, "%s has duplicated phandle 0x%x (seen before at %s)", 410 node->fullpath, phandle, other->fullpath); 411 return; 412 } 413 414 node->phandle = phandle; 415} 416PROP_ERROR(explicit_phandles, NULL); 417 418static void check_name_properties(struct check *c, struct node *root, 419 struct node *node) 420{ 421 struct property **pp, *prop = NULL; 422 423 for (pp = &node->proplist; *pp; pp = &((*pp)->next)) 424 if (streq((*pp)->name, "name")) { 425 prop = *pp; 426 break; 427 } 428 429 if (!prop) 430 return; /* No name property, that's fine */ 431 432 if ((prop->val.len != node->basenamelen+1) 433 || (memcmp(prop->val.val, node->name, node->basenamelen) != 0)) { 434 FAIL(c, "\"name\" property in %s is incorrect (\"%s\" instead" 435 " of base node name)", node->fullpath, prop->val.val); 436 } else { 437 /* The name property is correct, and therefore redundant. 438 * Delete it */ 439 *pp = prop->next; 440 free(prop->name); 441 data_free(prop->val); 442 free(prop); 443 } 444} 445ERROR_IF_NOT_STRING(name_is_string, "name"); 446NODE_ERROR(name_properties, NULL, &name_is_string); 447 448/* 449 * Reference fixup functions 450 */ 451 452static void fixup_phandle_references(struct check *c, struct node *dt, 453 struct node *node, struct property *prop) 454{ 455 struct marker *m = prop->val.markers; 456 struct node *refnode; 457 cell_t phandle; 458 459 for_each_marker_of_type(m, REF_PHANDLE) { 460 assert(m->offset + sizeof(cell_t) <= prop->val.len); 461 462 refnode = get_node_by_ref(dt, m->ref); 463 if (! refnode) { 464 FAIL(c, "Reference to non-existent node or label \"%s\"\n", 465 m->ref); 466 continue; 467 } 468 469 phandle = get_node_phandle(dt, refnode); 470 *((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle); 471 } 472} 473ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL, 474 &duplicate_node_names, &explicit_phandles); 475 476static void fixup_path_references(struct check *c, struct node *dt, 477 struct node *node, struct property *prop) 478{ 479 struct marker *m = prop->val.markers; 480 struct node *refnode; 481 char *path; 482 483 for_each_marker_of_type(m, REF_PATH) { 484 assert(m->offset <= prop->val.len); 485 486 refnode = get_node_by_ref(dt, m->ref); 487 if (!refnode) { 488 FAIL(c, "Reference to non-existent node or label \"%s\"\n", 489 m->ref); 490 continue; 491 } 492 493 path = refnode->fullpath; 494 prop->val = data_insert_at_marker(prop->val, m, path, 495 strlen(path) + 1); 496 } 497} 498ERROR(path_references, NULL, NULL, fixup_path_references, NULL, 499 &duplicate_node_names); 500 501/* 502 * Semantic checks 503 */ 504WARNING_IF_NOT_CELL(address_cells_is_cell, "#address-cells"); 505WARNING_IF_NOT_CELL(size_cells_is_cell, "#size-cells"); 506WARNING_IF_NOT_CELL(interrupt_cells_is_cell, "#interrupt-cells"); 507 508WARNING_IF_NOT_STRING(device_type_is_string, "device_type"); 509WARNING_IF_NOT_STRING(model_is_string, "model"); 510WARNING_IF_NOT_STRING(status_is_string, "status"); 511 512static void fixup_addr_size_cells(struct check *c, struct node *dt, 513 struct node *node) 514{ 515 struct property *prop; 516 517 node->addr_cells = -1; 518 node->size_cells = -1; 519 520 prop = get_property(node, "#address-cells"); 521 if (prop) 522 node->addr_cells = propval_cell(prop); 523 524 prop = get_property(node, "#size-cells"); 525 if (prop) 526 node->size_cells = propval_cell(prop); 527} 528WARNING(addr_size_cells, NULL, fixup_addr_size_cells, NULL, NULL, 529 &address_cells_is_cell, &size_cells_is_cell); 530 531#define node_addr_cells(n) \ 532 (((n)->addr_cells == -1) ? 2 : (n)->addr_cells) 533#define node_size_cells(n) \ 534 (((n)->size_cells == -1) ? 1 : (n)->size_cells) 535 536static void check_reg_format(struct check *c, struct node *dt, 537 struct node *node) 538{ 539 struct property *prop; 540 int addr_cells, size_cells, entrylen; 541 542 prop = get_property(node, "reg"); 543 if (!prop) 544 return; /* No "reg", that's fine */ 545 546 if (!node->parent) { 547 FAIL(c, "Root node has a \"reg\" property"); 548 return; 549 } 550 551 if (prop->val.len == 0) 552 FAIL(c, "\"reg\" property in %s is empty", node->fullpath); 553 554 addr_cells = node_addr_cells(node->parent); 555 size_cells = node_size_cells(node->parent); 556 entrylen = (addr_cells + size_cells) * sizeof(cell_t); 557 558 if ((prop->val.len % entrylen) != 0) 559 FAIL(c, "\"reg\" property in %s has invalid length (%d bytes) " 560 "(#address-cells == %d, #size-cells == %d)", 561 node->fullpath, prop->val.len, addr_cells, size_cells); 562} 563NODE_WARNING(reg_format, NULL, &addr_size_cells); 564 565static void check_ranges_format(struct check *c, struct node *dt, 566 struct node *node) 567{ 568 struct property *prop; 569 int c_addr_cells, p_addr_cells, c_size_cells, p_size_cells, entrylen; 570 571 prop = get_property(node, "ranges"); 572 if (!prop) 573 return; 574 575 if (!node->parent) { 576 FAIL(c, "Root node has a \"ranges\" property"); 577 return; 578 } 579 580 p_addr_cells = node_addr_cells(node->parent); 581 p_size_cells = node_size_cells(node->parent); 582 c_addr_cells = node_addr_cells(node); 583 c_size_cells = node_size_cells(node); 584 entrylen = (p_addr_cells + c_addr_cells + c_size_cells) * sizeof(cell_t); 585 586 if (prop->val.len == 0) { 587 if (p_addr_cells != c_addr_cells) 588 FAIL(c, "%s has empty \"ranges\" property but its " 589 "#address-cells (%d) differs from %s (%d)", 590 node->fullpath, c_addr_cells, node->parent->fullpath, 591 p_addr_cells); 592 if (p_size_cells != c_size_cells) 593 FAIL(c, "%s has empty \"ranges\" property but its " 594 "#size-cells (%d) differs from %s (%d)", 595 node->fullpath, c_size_cells, node->parent->fullpath, 596 p_size_cells); 597 } else if ((prop->val.len % entrylen) != 0) { 598 FAIL(c, "\"ranges\" property in %s has invalid length (%d bytes) " 599 "(parent #address-cells == %d, child #address-cells == %d, " 600 "#size-cells == %d)", node->fullpath, prop->val.len, 601 p_addr_cells, c_addr_cells, c_size_cells); 602 } 603} 604NODE_WARNING(ranges_format, NULL, &addr_size_cells); 605 606/* 607 * Style checks 608 */ 609static void check_avoid_default_addr_size(struct check *c, struct node *dt, 610 struct node *node) 611{ 612 struct property *reg, *ranges; 613 614 if (!node->parent) 615 return; /* Ignore root node */ 616 617 reg = get_property(node, "reg"); 618 ranges = get_property(node, "ranges"); 619 620 if (!reg && !ranges) 621 return; 622 623 if ((node->parent->addr_cells == -1)) 624 FAIL(c, "Relying on default #address-cells value for %s", 625 node->fullpath); 626 627 if ((node->parent->size_cells == -1)) 628 FAIL(c, "Relying on default #size-cells value for %s", 629 node->fullpath); 630} 631NODE_WARNING(avoid_default_addr_size, NULL, &addr_size_cells); 632 633static void check_obsolete_chosen_interrupt_controller(struct check *c, 634 struct node *dt) 635{ 636 struct node *chosen; 637 struct property *prop; 638 639 chosen = get_node_by_path(dt, "/chosen"); 640 if (!chosen) 641 return; 642 643 prop = get_property(chosen, "interrupt-controller"); 644 if (prop) 645 FAIL(c, "/chosen has obsolete \"interrupt-controller\" " 646 "property"); 647} 648TREE_WARNING(obsolete_chosen_interrupt_controller, NULL); 649 650static struct check *check_table[] = { 651 &duplicate_node_names, &duplicate_property_names, 652 &node_name_chars, &node_name_format, &property_name_chars, 653 &name_is_string, &name_properties, 654 655 &duplicate_label, 656 657 &explicit_phandles, 658 &phandle_references, &path_references, 659 660 &address_cells_is_cell, &size_cells_is_cell, &interrupt_cells_is_cell, 661 &device_type_is_string, &model_is_string, &status_is_string, 662 663 &addr_size_cells, ®_format, &ranges_format, 664 665 &avoid_default_addr_size, 666 &obsolete_chosen_interrupt_controller, 667 668 &always_fail, 669}; 670 671static void enable_warning_error(struct check *c, bool warn, bool error) 672{ 673 int i; 674 675 /* Raising level, also raise it for prereqs */ 676 if ((warn && !c->warn) || (error && !c->error)) 677 for (i = 0; i < c->num_prereqs; i++) 678 enable_warning_error(c->prereq[i], warn, error); 679 680 c->warn = c->warn || warn; 681 c->error = c->error || error; 682} 683 684static void disable_warning_error(struct check *c, bool warn, bool error) 685{ 686 int i; 687 688 /* Lowering level, also lower it for things this is the prereq 689 * for */ 690 if ((warn && c->warn) || (error && c->error)) { 691 for (i = 0; i < ARRAY_SIZE(check_table); i++) { 692 struct check *cc = check_table[i]; 693 int j; 694 695 for (j = 0; j < cc->num_prereqs; j++) 696 if (cc->prereq[j] == c) 697 disable_warning_error(cc, warn, error); 698 } 699 } 700 701 c->warn = c->warn && !warn; 702 c->error = c->error && !error; 703} 704 705void parse_checks_option(bool warn, bool error, const char *optarg) 706{ 707 int i; 708 const char *name = optarg; 709 bool enable = true; 710 711 if ((strncmp(optarg, "no-", 3) == 0) 712 || (strncmp(optarg, "no_", 3) == 0)) { 713 name = optarg + 3; 714 enable = false; 715 } 716 717 for (i = 0; i < ARRAY_SIZE(check_table); i++) { 718 struct check *c = check_table[i]; 719 720 if (streq(c->name, name)) { 721 if (enable) 722 enable_warning_error(c, warn, error); 723 else 724 disable_warning_error(c, warn, error); 725 return; 726 } 727 } 728 729 die("Unrecognized check name \"%s\"\n", name); 730} 731 732void process_checks(int force, struct boot_info *bi) 733{ 734 struct node *dt = bi->dt; 735 int i; 736 int error = 0; 737 738 for (i = 0; i < ARRAY_SIZE(check_table); i++) { 739 struct check *c = check_table[i]; 740 741 if (c->warn || c->error) 742 error = error || run_check(c, dt); 743 } 744 745 if (error) { 746 if (!force) { 747 fprintf(stderr, "ERROR: Input tree has errors, aborting " 748 "(use -f to force output)\n"); 749 exit(2); 750 } else if (quiet < 3) { 751 fprintf(stderr, "Warning: Input tree has errors, " 752 "output forced\n"); 753 } 754 } 755} 756