Skip to content

Commit 6e5773d

Browse files
committed
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: 045b14c ("of: WARN on deprecated #address-cells/#size-cells handling") Tested-by: Sean Anderson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent 4474806 commit 6e5773d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

drivers/of/address.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ static int of_bus_default_flags_match(struct device_node *np)
340340
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
341341
}
342342

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+
343352
/*
344353
* Array of bus specific translators
345354
*/
@@ -384,7 +393,7 @@ static const struct of_bus of_busses[] = {
384393
{
385394
.name = "default",
386395
.addresses = "reg",
387-
.match = NULL,
396+
.match = of_bus_default_match,
388397
.count_cells = of_bus_default_count_cells,
389398
.map = of_bus_default_map,
390399
.translate = of_bus_default_translate,
@@ -399,7 +408,6 @@ static const struct of_bus *of_match_bus(struct device_node *np)
399408
for (i = 0; i < ARRAY_SIZE(of_busses); i++)
400409
if (!of_busses[i].match || of_busses[i].match(np))
401410
return &of_busses[i];
402-
BUG();
403411
return NULL;
404412
}
405413

@@ -521,6 +529,8 @@ static u64 __of_translate_address(struct device_node *node,
521529
if (parent == NULL)
522530
return OF_BAD_ADDR;
523531
bus = of_match_bus(parent);
532+
if (!bus)
533+
return OF_BAD_ADDR;
524534

525535
/* Count address cells & copy address locally */
526536
bus->count_cells(dev, &na, &ns);
@@ -564,6 +574,8 @@ static u64 __of_translate_address(struct device_node *node,
564574

565575
/* Get new parent bus and counts */
566576
pbus = of_match_bus(parent);
577+
if (!pbus)
578+
return OF_BAD_ADDR;
567579
pbus->count_cells(dev, &pna, &pns);
568580
if (!OF_CHECK_COUNTS(pna, pns)) {
569581
pr_err("Bad cell count for %pOF\n", dev);
@@ -703,7 +715,7 @@ const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
703715

704716
/* match the parent's bus type */
705717
bus = of_match_bus(parent);
706-
if (strcmp(bus->name, "pci") && (bar_no >= 0))
718+
if (!bus || (strcmp(bus->name, "pci") && (bar_no >= 0)))
707719
return NULL;
708720

709721
/* Get "reg" or "assigned-addresses" property */

0 commit comments

Comments
 (0)