of/address: Fix WARN when attempting translating non-translatable addresses

The recently added WARN() for deprecated #address-cells and #size-cells
triggered a WARN when of_platform_populate() (which calls
of_address_to_resource()) is used on nodes with non-translatable
addresses. This case is expected to return an error.

Rework the bus matching to allow no match and make the default require
an #address-cells property. That should be safe to do as any platform
missing #address-cells would have a warning already.

Fixes: 045b14ca5c36 ("of: WARN on deprecated #address-cells/#size-cells handling")
Tested-by: Sean Anderson <sean.anderson@linux.dev>
Link: https://lore.kernel.org/r/20250110215030.3637845-2-robh@kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

Changed files
+15 -3
drivers
+15 -3
drivers/of/address.c
··· 340 340 return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3); 341 341 } 342 342 343 + static int of_bus_default_match(struct device_node *np) 344 + { 345 + /* 346 + * Check for presence first since of_bus_n_addr_cells() will warn when 347 + * walking parent nodes. 348 + */ 349 + return of_property_present(np, "#address-cells"); 350 + } 351 + 343 352 /* 344 353 * Array of bus specific translators 345 354 */ ··· 393 384 { 394 385 .name = "default", 395 386 .addresses = "reg", 396 - .match = NULL, 387 + .match = of_bus_default_match, 397 388 .count_cells = of_bus_default_count_cells, 398 389 .map = of_bus_default_map, 399 390 .translate = of_bus_default_translate, ··· 408 399 for (i = 0; i < ARRAY_SIZE(of_busses); i++) 409 400 if (!of_busses[i].match || of_busses[i].match(np)) 410 401 return &of_busses[i]; 411 - BUG(); 412 402 return NULL; 413 403 } 414 404 ··· 529 521 if (parent == NULL) 530 522 return OF_BAD_ADDR; 531 523 bus = of_match_bus(parent); 524 + if (!bus) 525 + return OF_BAD_ADDR; 532 526 533 527 /* Count address cells & copy address locally */ 534 528 bus->count_cells(dev, &na, &ns); ··· 574 564 575 565 /* Get new parent bus and counts */ 576 566 pbus = of_match_bus(parent); 567 + if (!pbus) 568 + return OF_BAD_ADDR; 577 569 pbus->count_cells(dev, &pna, &pns); 578 570 if (!OF_CHECK_COUNTS(pna, pns)) { 579 571 pr_err("Bad cell count for %pOF\n", dev); ··· 715 703 716 704 /* match the parent's bus type */ 717 705 bus = of_match_bus(parent); 718 - if (strcmp(bus->name, "pci") && (bar_no >= 0)) 706 + if (!bus || (strcmp(bus->name, "pci") && (bar_no >= 0))) 719 707 return NULL; 720 708 721 709 /* Get "reg" or "assigned-addresses" property */