All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/dtc: dma-ranges is a multiple of 3 cells
@ 2022-07-08 17:03 Ben Dooks
  2022-07-08 21:46 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Ben Dooks @ 2022-07-08 17:03 UTC (permalink / raw)
  To: devicetree, frowand.list
  Cc: linux-kernel, robh+dt, Sudip Mukherjee, Jude Onyenegecha, Ben Dooks

The dma-ranges property is a set 3 cells of #address-size, so don't treat
it like the ranges property when generating warnings.

Signed-off-by: Ben Dooks <ben.dooks@sifive.com>
---
 scripts/dtc/checks.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
index 781ba1129a8e..791b93e8e02a 100644
--- a/scripts/dtc/checks.c
+++ b/scripts/dtc/checks.c
@@ -823,7 +823,36 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
 	}
 }
 WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
-WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
+
+static void check_dma_ranges_format(struct check *c, struct dt_info *dti,
+				struct node *node)
+{
+	struct property *prop;
+	int c_size_cells, p_size_cells, entrylen;
+	const char *ranges = c->data;
+
+	prop = get_property(node, ranges);
+	if (!prop)
+		return;
+
+	if (!node->parent) {
+		FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property",
+			  ranges);
+		return;
+	}
+
+	c_size_cells = node_size_cells(node);
+	p_size_cells = node_size_cells(node->parent);
+	entrylen = (p_size_cells + 2 * c_size_cells) * sizeof(cell_t);
+
+	if (!is_multiple_of(prop->val.len, entrylen)) {
+		FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
+			  "(parent #address-cells == %d, "
+			  "child #address-cells == %d)", ranges, prop->val.len,
+			  p_size_cells, c_size_cells);
+	}
+}
+WARNING(dma_ranges_format, check_dma_ranges_format, "dma-ranges", &addr_size_cells);
 
 static const struct bus_type pci_bus = {
 	.name = "PCI",
-- 
2.35.1


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

* Re: [PATCH] scripts/dtc: dma-ranges is a multiple of 3 cells
  2022-07-08 17:03 [PATCH] scripts/dtc: dma-ranges is a multiple of 3 cells Ben Dooks
@ 2022-07-08 21:46 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2022-07-08 21:46 UTC (permalink / raw)
  To: Ben Dooks
  Cc: devicetree, Frank Rowand, linux-kernel, Sudip Mukherjee,
	Jude Onyenegecha

On Fri, Jul 8, 2022 at 11:04 AM Ben Dooks <ben.dooks@sifive.com> wrote:
>
> The dma-ranges property is a set 3 cells of #address-size, so don't treat
> it like the ranges property when generating warnings.

Uhh, no it is not. It's the same as 'ranges'.

Also, we don't take patches against the copy of dtc in the kernel.
Submit them to upstream dtc.

Rob


>
> Signed-off-by: Ben Dooks <ben.dooks@sifive.com>
> ---
>  scripts/dtc/checks.c | 31 ++++++++++++++++++++++++++++++-
>  1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/dtc/checks.c b/scripts/dtc/checks.c
> index 781ba1129a8e..791b93e8e02a 100644
> --- a/scripts/dtc/checks.c
> +++ b/scripts/dtc/checks.c
> @@ -823,7 +823,36 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
>         }
>  }
>  WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
> -WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
> +
> +static void check_dma_ranges_format(struct check *c, struct dt_info *dti,
> +                               struct node *node)
> +{
> +       struct property *prop;
> +       int c_size_cells, p_size_cells, entrylen;
> +       const char *ranges = c->data;
> +
> +       prop = get_property(node, ranges);
> +       if (!prop)
> +               return;
> +
> +       if (!node->parent) {
> +               FAIL_PROP(c, dti, node, prop, "Root node has a \"%s\" property",
> +                         ranges);
> +               return;
> +       }
> +
> +       c_size_cells = node_size_cells(node);
> +       p_size_cells = node_size_cells(node->parent);
> +       entrylen = (p_size_cells + 2 * c_size_cells) * sizeof(cell_t);
> +
> +       if (!is_multiple_of(prop->val.len, entrylen)) {
> +               FAIL_PROP(c, dti, node, prop, "\"%s\" property has invalid length (%d bytes) "
> +                         "(parent #address-cells == %d, "
> +                         "child #address-cells == %d)", ranges, prop->val.len,
> +                         p_size_cells, c_size_cells);
> +       }
> +}
> +WARNING(dma_ranges_format, check_dma_ranges_format, "dma-ranges", &addr_size_cells);
>
>  static const struct bus_type pci_bus = {
>         .name = "PCI",
> --
> 2.35.1
>

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

end of thread, other threads:[~2022-07-08 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 17:03 [PATCH] scripts/dtc: dma-ranges is a multiple of 3 cells Ben Dooks
2022-07-08 21:46 ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.