mirror of https://github.com/torvalds/linux.git
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: 045b14ca5c ("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>
This commit is contained in:
parent
44748065ed
commit
6e5773d52f
|
|
@ -340,6 +340,15 @@ static int of_bus_default_flags_match(struct device_node *np)
|
||||||
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
|
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int of_bus_default_match(struct device_node *np)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Check for presence first since of_bus_n_addr_cells() will warn when
|
||||||
|
* walking parent nodes.
|
||||||
|
*/
|
||||||
|
return of_property_present(np, "#address-cells");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Array of bus specific translators
|
* Array of bus specific translators
|
||||||
*/
|
*/
|
||||||
|
|
@ -384,7 +393,7 @@ static const struct of_bus of_busses[] = {
|
||||||
{
|
{
|
||||||
.name = "default",
|
.name = "default",
|
||||||
.addresses = "reg",
|
.addresses = "reg",
|
||||||
.match = NULL,
|
.match = of_bus_default_match,
|
||||||
.count_cells = of_bus_default_count_cells,
|
.count_cells = of_bus_default_count_cells,
|
||||||
.map = of_bus_default_map,
|
.map = of_bus_default_map,
|
||||||
.translate = of_bus_default_translate,
|
.translate = of_bus_default_translate,
|
||||||
|
|
@ -399,7 +408,6 @@ static const struct of_bus *of_match_bus(struct device_node *np)
|
||||||
for (i = 0; i < ARRAY_SIZE(of_busses); i++)
|
for (i = 0; i < ARRAY_SIZE(of_busses); i++)
|
||||||
if (!of_busses[i].match || of_busses[i].match(np))
|
if (!of_busses[i].match || of_busses[i].match(np))
|
||||||
return &of_busses[i];
|
return &of_busses[i];
|
||||||
BUG();
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -521,6 +529,8 @@ static u64 __of_translate_address(struct device_node *node,
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
return OF_BAD_ADDR;
|
return OF_BAD_ADDR;
|
||||||
bus = of_match_bus(parent);
|
bus = of_match_bus(parent);
|
||||||
|
if (!bus)
|
||||||
|
return OF_BAD_ADDR;
|
||||||
|
|
||||||
/* Count address cells & copy address locally */
|
/* Count address cells & copy address locally */
|
||||||
bus->count_cells(dev, &na, &ns);
|
bus->count_cells(dev, &na, &ns);
|
||||||
|
|
@ -564,6 +574,8 @@ static u64 __of_translate_address(struct device_node *node,
|
||||||
|
|
||||||
/* Get new parent bus and counts */
|
/* Get new parent bus and counts */
|
||||||
pbus = of_match_bus(parent);
|
pbus = of_match_bus(parent);
|
||||||
|
if (!pbus)
|
||||||
|
return OF_BAD_ADDR;
|
||||||
pbus->count_cells(dev, &pna, &pns);
|
pbus->count_cells(dev, &pna, &pns);
|
||||||
if (!OF_CHECK_COUNTS(pna, pns)) {
|
if (!OF_CHECK_COUNTS(pna, pns)) {
|
||||||
pr_err("Bad cell count for %pOF\n", dev);
|
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,
|
||||||
|
|
||||||
/* match the parent's bus type */
|
/* match the parent's bus type */
|
||||||
bus = of_match_bus(parent);
|
bus = of_match_bus(parent);
|
||||||
if (strcmp(bus->name, "pci") && (bar_no >= 0))
|
if (!bus || (strcmp(bus->name, "pci") && (bar_no >= 0)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Get "reg" or "assigned-addresses" property */
|
/* Get "reg" or "assigned-addresses" property */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue