Skip to content

Commit 64ee3cf

Browse files
committed
of/address: Rework bus matching to avoid warnings
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]>
1 parent 045b14c commit 64ee3cf

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

drivers/of/address.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ static unsigned int of_bus_isa_get_flags(const __be32 *addr)
333333

334334
static int of_bus_default_flags_match(struct device_node *np)
335335
{
336-
return of_bus_n_addr_cells(np) == 3;
336+
/*
337+
* Check for presence first since of_bus_n_addr_cells() will warn when
338+
* walking parent nodes.
339+
*/
340+
return of_property_present(np, "#address-cells") && (of_bus_n_addr_cells(np) == 3);
337341
}
338342

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

704-
bus->count_cells(dev, &na, &ns);
705-
if (!OF_CHECK_ADDR_COUNT(na))
706-
return NULL;
707-
708708
/* Get "reg" or "assigned-addresses" property */
709709
prop = of_get_property(dev, bus->addresses, &psize);
710710
if (prop == NULL)
711711
return NULL;
712712
psize /= 4;
713713

714+
bus->count_cells(dev, &na, &ns);
715+
if (!OF_CHECK_ADDR_COUNT(na))
716+
return NULL;
717+
714718
onesize = na + ns;
715719
for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {
716720
u32 val = be32_to_cpu(prop[0]);

0 commit comments

Comments
 (0)