mirror of
https://github.com/LiBwrt-op/openwrt-6.x.git
synced 2025-12-17 01:06:35 +00:00
kernel: of: avoid some unnecessary bad cell count warnings
This patchset silences some noisy dts false warnings: [ 0.616266] OF: Bad cell count for /spi@1100d000/flash@0/partitions [ 0.622551] OF: Bad cell count for /spi@1100d000/flash@0/partitions Closes: https://github.com/openwrt/openwrt/issues/14701 Signed-off-by: Shiji Yang <yangshiji66@outlook.com> Link: https://github.com/openwrt/openwrt/pull/20942 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
parent
43c48d09ec
commit
b4d7263bc3
@ -0,0 +1,61 @@
|
||||
From 64ee3cf096ac590e7da2ceac1c390546bff5e240 Mon Sep 17 00:00:00 2001
|
||||
From: "Rob Herring (Arm)" <robh@kernel.org>
|
||||
Date: Fri, 8 Nov 2024 13:35:48 -0600
|
||||
Subject: [PATCH] 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>
|
||||
---
|
||||
drivers/of/address.c | 14 +++++++++-----
|
||||
1 file changed, 9 insertions(+), 5 deletions(-)
|
||||
|
||||
--- a/drivers/of/address.c
|
||||
+++ b/drivers/of/address.c
|
||||
@@ -331,7 +331,11 @@ static unsigned int of_bus_isa_get_flags
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -700,16 +704,16 @@ const __be32 *__of_get_address(struct de
|
||||
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]);
|
||||
@ -0,0 +1,85 @@
|
||||
From 6e5773d52f4a2d9c80692245f295069260cff6fc Mon Sep 17 00:00:00 2001
|
||||
From: "Rob Herring (Arm)" <robh@kernel.org>
|
||||
Date: Fri, 10 Jan 2025 15:50:29 -0600
|
||||
Subject: [PATCH] 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: 045b14ca5c36 ("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>
|
||||
---
|
||||
drivers/of/address.c | 18 +++++++++++++++---
|
||||
1 file changed, 15 insertions(+), 3 deletions(-)
|
||||
|
||||
--- a/drivers/of/address.c
|
||||
+++ b/drivers/of/address.c
|
||||
@@ -338,6 +338,15 @@ static int of_bus_default_flags_match(st
|
||||
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
|
||||
*/
|
||||
@@ -382,7 +391,7 @@ static struct of_bus of_busses[] = {
|
||||
{
|
||||
.name = "default",
|
||||
.addresses = "reg",
|
||||
- .match = NULL,
|
||||
+ .match = of_bus_default_match,
|
||||
.count_cells = of_bus_default_count_cells,
|
||||
.map = of_bus_default_map,
|
||||
.translate = of_bus_default_translate,
|
||||
@@ -397,7 +406,6 @@ static struct of_bus *of_match_bus(struc
|
||||
for (i = 0; i < ARRAY_SIZE(of_busses); i++)
|
||||
if (!of_busses[i].match || of_busses[i].match(np))
|
||||
return &of_busses[i];
|
||||
- BUG();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -519,6 +527,8 @@ static u64 __of_translate_address(struct
|
||||
if (parent == NULL)
|
||||
return OF_BAD_ADDR;
|
||||
bus = of_match_bus(parent);
|
||||
+ if (!bus)
|
||||
+ return OF_BAD_ADDR;
|
||||
|
||||
/* Count address cells & copy address locally */
|
||||
bus->count_cells(dev, &na, &ns);
|
||||
@@ -562,6 +572,8 @@ static u64 __of_translate_address(struct
|
||||
|
||||
/* Get new parent bus and counts */
|
||||
pbus = of_match_bus(parent);
|
||||
+ if (!pbus)
|
||||
+ return OF_BAD_ADDR;
|
||||
pbus->count_cells(dev, &pna, &pns);
|
||||
if (!OF_CHECK_COUNTS(pna, pns)) {
|
||||
pr_err("Bad cell count for %pOF\n", dev);
|
||||
@@ -701,7 +713,7 @@ const __be32 *__of_get_address(struct de
|
||||
|
||||
/* match the parent's bus type */
|
||||
bus = of_match_bus(parent);
|
||||
- if (strcmp(bus->name, "pci") && (bar_no >= 0))
|
||||
+ if (!bus || (strcmp(bus->name, "pci") && (bar_no >= 0)))
|
||||
return NULL;
|
||||
|
||||
/* Get "reg" or "assigned-addresses" property */
|
||||
Loading…
Reference in New Issue
Block a user