devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of: address: Fix parser address/size cells initialization
@ 2020-07-31 10:02 Nicolas Saenz Julienne
  2020-07-31 15:03 ` Rob Herring
  2020-07-31 15:45 ` [PATCH] of: address: Fix parser address/size cells initialization Thomas Bogendoerfer
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Saenz Julienne @ 2020-07-31 10:02 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand, Jiaxun Yang, Thomas Bogendoerfer
  Cc: linux-rpi-kernel, Nicolas Saenz Julienne, Nathan Chancellor,
	devicetree, linux-kernel

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 <natechancellor@gmail.com>
Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: address: Fix parser address/size cells initialization
  2020-07-31 10:02 [PATCH] of: address: Fix parser address/size cells initialization Nicolas Saenz Julienne
@ 2020-07-31 15:03 ` Rob Herring
  2020-08-03 14:25   ` [PATCH] of: unittest: Use bigger address cells to catch parser regressions Nicolas Saenz Julienne
  2020-07-31 15:45 ` [PATCH] of: address: Fix parser address/size cells initialization Thomas Bogendoerfer
  1 sibling, 1 reply; 5+ messages in thread
From: Rob Herring @ 2020-07-31 15:03 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: Frank Rowand, Jiaxun Yang, Thomas Bogendoerfer,
	moderated list:BROADCOM BCM2835 ARM ARCHITECTURE,
	Nathan Chancellor, devicetree, linux-kernel

On Fri, Jul 31, 2020 at 4:02 AM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> 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 <natechancellor@gmail.com>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  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 <robh@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: address: Fix parser address/size cells initialization
  2020-07-31 10:02 [PATCH] of: address: Fix parser address/size cells initialization Nicolas Saenz Julienne
  2020-07-31 15:03 ` Rob Herring
@ 2020-07-31 15:45 ` Thomas Bogendoerfer
  1 sibling, 0 replies; 5+ messages in thread
From: Thomas Bogendoerfer @ 2020-07-31 15:45 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: Rob Herring, Frank Rowand, Jiaxun Yang, linux-rpi-kernel,
	Nathan Chancellor, devicetree, linux-kernel

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 <natechancellor@gmail.com>
> Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
> ---
>  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 ]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] of: unittest: Use bigger address cells to catch parser regressions
  2020-07-31 15:03 ` Rob Herring
@ 2020-08-03 14:25   ` Nicolas Saenz Julienne
  2020-08-03 22:27     ` Rob Herring
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Saenz Julienne @ 2020-08-03 14:25 UTC (permalink / raw)
  To: Rob Herring
  Cc: Frank Rowand, Jiaxun Yang, Thomas Bogendoerfer,
	moderated list:BROADCOM BCM2835 ARM ARCHITECTURE,
	Nathan Chancellor, devicetree, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2063 bytes --]

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 <nsaenzjulienne@suse.de>
---
 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



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] of: unittest: Use bigger address cells to catch parser regressions
  2020-08-03 14:25   ` [PATCH] of: unittest: Use bigger address cells to catch parser regressions Nicolas Saenz Julienne
@ 2020-08-03 22:27     ` Rob Herring
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2020-08-03 22:27 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: Frank Rowand, Jiaxun Yang, Thomas Bogendoerfer,
	moderated list:BROADCOM BCM2835 ARM ARCHITECTURE,
	Nathan Chancellor, devicetree, linux-kernel

On Mon, Aug 3, 2020 at 8:25 AM Nicolas Saenz Julienne
<nsaenzjulienne@suse.de> 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 <nsaenzjulienne@suse.de>
> ---
>  drivers/of/unittest-data/tests-address.dtsi | 10 +++++-----
>  drivers/of/unittest.c                       |  2 +-
>  2 files changed, 6 insertions(+), 6 deletions(-)

Applied, thanks.

Rob

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-03 22:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 10:02 [PATCH] of: address: Fix parser address/size cells initialization Nicolas Saenz Julienne
2020-07-31 15:03 ` Rob Herring
2020-08-03 14:25   ` [PATCH] of: unittest: Use bigger address cells to catch parser regressions Nicolas Saenz Julienne
2020-08-03 22:27     ` Rob Herring
2020-07-31 15:45 ` [PATCH] of: address: Fix parser address/size cells initialization Thomas Bogendoerfer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).