2020-07-31 10:06:31

by Nicolas Saenz Julienne

[permalink] [raw]
Subject: [PATCH] of: address: Fix parser address/size cells initialization

bus->count_cells() parses cells starting from the node's parent. This is
not good enough for parser_init() which is generally parsing a bus node.

Revert to previous behavior using of_bus_n_*_cells().

Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
Reported-by: Nathan Chancellor <[email protected]>
Signed-off-by: Nicolas Saenz Julienne <[email protected]>
---
drivers/of/address.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 275d764efc77..89822e191956 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -701,11 +701,11 @@ static int parser_init(struct of_pci_range_parser *parser,

parser->node = node;
parser->pna = of_n_addr_cells(node);
+ parser->na = of_bus_n_addr_cells(node);
+ parser->ns = of_bus_n_size_cells(node);
parser->dma = !strcmp(name, "dma-ranges");
parser->bus = of_match_bus(node);

- parser->bus->count_cells(parser->node, &parser->na, &parser->ns);
-
parser->range = of_get_property(node, name, &rlen);
if (parser->range == NULL)
return -ENOENT;
--
2.27.0


2020-07-31 15:04:03

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH] of: address: Fix parser address/size cells initialization

On Fri, Jul 31, 2020 at 4:02 AM Nicolas Saenz Julienne
<[email protected]> wrote:
>
> bus->count_cells() parses cells starting from the node's parent. This is
> not good enough for parser_init() which is generally parsing a bus node.
>
> Revert to previous behavior using of_bus_n_*_cells().
>
> Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> Reported-by: Nathan Chancellor <[email protected]>
> Signed-off-by: Nicolas Saenz Julienne <[email protected]>
> ---
> drivers/of/address.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

We have a unit test for this code, does it fail? If not, adjusting it
to fail or adding a test case would be nice. Either way:

Acked-by: Rob Herring <[email protected]>

2020-07-31 16:01:24

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH] of: address: Fix parser address/size cells initialization

On Fri, Jul 31, 2020 at 12:02:48PM +0200, Nicolas Saenz Julienne wrote:
> bus->count_cells() parses cells starting from the node's parent. This is
> not good enough for parser_init() which is generally parsing a bus node.
>
> Revert to previous behavior using of_bus_n_*_cells().
>
> Fixes: 2f96593ecc37 ("of_address: Add bus type match for pci ranges parser")
> Reported-by: Nathan Chancellor <[email protected]>
> Signed-off-by: Nicolas Saenz Julienne <[email protected]>
> ---
> drivers/of/address.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

applied to mips-next.

Thomas.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]

2020-08-03 14:28:42

by Nicolas Saenz Julienne

[permalink] [raw]
Subject: [PATCH] of: unittest: Use bigger address cells to catch parser regressions

Getting address and size cells for dma-ranges/ranges parsing is tricky
and shouldn't rely on the node's count_cells() method. The function
starts looking for cells on the parent node, as its supposed to work
with device nodes, which doesn't work when input with bus nodes, as
generally done when parsing ranges.

Add test to catch regressions on that specific quirk as developers will
be tempted to edit it out in favor of the default method.

Signed-off-by: Nicolas Saenz Julienne <[email protected]>
---
drivers/of/unittest-data/tests-address.dtsi | 10 +++++-----
drivers/of/unittest.c | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/of/unittest-data/tests-address.dtsi b/drivers/of/unittest-data/tests-address.dtsi
index 3fe5d3987beb..6604a52bf6cb 100644
--- a/drivers/of/unittest-data/tests-address.dtsi
+++ b/drivers/of/unittest-data/tests-address.dtsi
@@ -23,13 +23,13 @@ device@70000000 {
};

bus@80000000 {
- #address-cells = <1>;
- #size-cells = <1>;
- ranges = <0x0 0x80000000 0x100000>;
- dma-ranges = <0x10000000 0x0 0x40000000>;
+ #address-cells = <2>;
+ #size-cells = <2>;
+ ranges = <0x0 0x0 0x80000000 0x0 0x100000>;
+ dma-ranges = <0x1 0x0 0x0 0x20 0x0>;

device@1000 {
- reg = <0x1000 0x1000>;
+ reg = <0x0 0x1000 0x0 0x1000>;
};
};

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 398de04fd19c..9b7e84bdc7d4 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -900,7 +900,7 @@ static void __init of_unittest_parse_dma_ranges(void)
of_unittest_dma_ranges_one("/testcase-data/address-tests/device@70000000",
0x0, 0x20000000, 0x40000000);
of_unittest_dma_ranges_one("/testcase-data/address-tests/bus@80000000/device@1000",
- 0x10000000, 0x20000000, 0x40000000);
+ 0x100000000, 0x20000000, 0x2000000000);
of_unittest_dma_ranges_one("/testcase-data/address-tests/pci@90000000",
0x80000000, 0x20000000, 0x10000000);
}
--
2.28.0



Attachments:
signature.asc (499.00 B)
This is a digitally signed message part

2020-08-03 22:28:26

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH] of: unittest: Use bigger address cells to catch parser regressions

On Mon, Aug 3, 2020 at 8:25 AM Nicolas Saenz Julienne
<[email protected]> wrote:
>
> Getting address and size cells for dma-ranges/ranges parsing is tricky
> and shouldn't rely on the node's count_cells() method. The function
> starts looking for cells on the parent node, as its supposed to work
> with device nodes, which doesn't work when input with bus nodes, as
> generally done when parsing ranges.
>
> Add test to catch regressions on that specific quirk as developers will
> be tempted to edit it out in favor of the default method.
>
> Signed-off-by: Nicolas Saenz Julienne <[email protected]>
> ---
> drivers/of/unittest-data/tests-address.dtsi | 10 +++++-----
> drivers/of/unittest.c | 2 +-
> 2 files changed, 6 insertions(+), 6 deletions(-)

Applied, thanks.

Rob