Skip to content

Commit

Permalink
of/address: Rework bus matching to avoid warnings
Browse files Browse the repository at this point in the history
With warnings added for deprecated #address-cells/#size-cells handling,
the DT address handling code causes warnings when used on nodes with no
address. This happens frequently with calls to of_platform_populate() as
it is perfectly acceptable to have devices without a 'reg' property. The
desired behavior is to just silently return an error when retrieving an
address.

The warnings can be avoided by checking for "#address-cells" presence
first and checking for an address property before fetching
"#address-cells" and "#size-cells".

Reported-by: Marek Szyprowski <[email protected]>
Reported-by: Steven Price <[email protected]>
Tested-by: Marek Szyprowski <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Rob Herring (Arm) <[email protected]>
  • Loading branch information
robherring committed Nov 8, 2024
1 parent 045b14c commit 64ee3cf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions drivers/of/address.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ static unsigned int of_bus_isa_get_flags(const __be32 *addr)

static int of_bus_default_flags_match(struct device_node *np)
{
return of_bus_n_addr_cells(np) == 3;
/*
* Check for presence first since of_bus_n_addr_cells() will warn when
* walking parent nodes.
*/
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
}

/*
Expand Down Expand Up @@ -701,16 +705,16 @@ const __be32 *__of_get_address(struct device_node *dev, int index, int bar_no,
if (strcmp(bus->name, "pci") && (bar_no >= 0))
return NULL;

bus->count_cells(dev, &na, &ns);
if (!OF_CHECK_ADDR_COUNT(na))
return NULL;

/* Get "reg" or "assigned-addresses" property */
prop = of_get_property(dev, bus->addresses, &psize);
if (prop == NULL)
return NULL;
psize /= 4;

bus->count_cells(dev, &na, &ns);
if (!OF_CHECK_ADDR_COUNT(na))
return NULL;

onesize = na + ns;
for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {
u32 val = be32_to_cpu(prop[0]);
Expand Down

0 comments on commit 64ee3cf

Please sign in to comment.