Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <m.szyprowski@samsung.com>
Reported-by: Steven Price <steven.price@arm.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20241108193547.2647986-2-robh@kernel.org
Signed-off-by: Rob Herring (Arm) <robh@kernel.org>

+9 -5
+9 -5
drivers/of/address.c
··· 333 333 334 334 static int of_bus_default_flags_match(struct device_node *np) 335 335 { 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); 337 341 } 338 342 339 343 /* ··· 705 701 if (strcmp(bus->name, "pci") && (bar_no >= 0)) 706 702 return NULL; 707 703 708 - bus->count_cells(dev, &na, &ns); 709 - if (!OF_CHECK_ADDR_COUNT(na)) 710 - return NULL; 711 - 712 704 /* Get "reg" or "assigned-addresses" property */ 713 705 prop = of_get_property(dev, bus->addresses, &psize); 714 706 if (prop == NULL) 715 707 return NULL; 716 708 psize /= 4; 709 + 710 + bus->count_cells(dev, &na, &ns); 711 + if (!OF_CHECK_ADDR_COUNT(na)) 712 + return NULL; 717 713 718 714 onesize = na + ns; 719 715 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {