From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v3 3/5] checks: Add markers on known properties
Date: Mon, 11 Oct 2021 16:09:32 +1100 [thread overview]
Message-ID: <YWPHDJBS51Ne2fMT@yekko> (raw)
In-Reply-To: <20210727183023.3212077-4-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 7491 bytes --]
On Tue, Jul 27, 2021 at 12:30:21PM -0600, Rob Herring wrote:
> For properties we already have checks for, we know the type and how to
> parse them. Use this to add type and phandle markers so we have them when
> the source did not (e.g. dtb format).
>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
> v3:
> - Rework marker_add() and callers into 3 functions. marker_add() just
> adds a marker. marker_add_type_annotations() adds type annotations
> at each entry offset. marker_add_phandle_annotation() adds a phandle
> and type annotation at a phandle offset.
> - Only add type info when no type markers are present at all.
> - Keep phandle ref check on phandle+args properties.
> v2:
> - Set marker.ref on phandle markers
> - Avoid adding markers if there's any conflicting type markers.
> ---
> checks.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 82 insertions(+), 5 deletions(-)
>
> diff --git a/checks.c b/checks.c
> index e2690e90f90c..b7ac1732b0b8 100644
> --- a/checks.c
> +++ b/checks.c
> @@ -58,6 +58,56 @@ struct check {
> #define CHECK(nm_, fn_, d_, ...) \
> CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__)
>
> +static struct marker *marker_add(struct marker **list, enum markertype type,
> + unsigned int offset, char * ref)
> +{
> + struct marker *m = *list;
> +
> + m = xmalloc(sizeof(*m));
> + m->type = type;
> + m->offset = offset;
> + m->next = NULL;
> + m->ref = ref;
> +
> + /* Find the insertion point, markers are in order by offset */
> + while (*list && ((*list)->offset < m->offset))
> + list = &((*list)->next);
> +
> + if (*list) {
> + m->next = (*list)->next;
> + (*list)->next = m;
> + } else
> + *list = m;
> +
> + return m;
> +}
> +
> +static void marker_add_type_annotations(struct property *prop,
> + enum markertype type,
> + unsigned int entrylen)
> +{
> + unsigned int offset;
> +
> + assert(is_type_marker(type));
> +
> + if (has_type_markers(prop->val.markers))
> + return;
> +
> + for (offset = 0; offset < prop->val.len; offset += entrylen)
> + marker_add(&prop->val.markers, type, offset, NULL);
> +}
> +
> +static void marker_add_phandle_annotation(struct property *prop,
> + unsigned int cell,
> + char *ref)
> +{
> + if (!cell && has_type_markers(prop->val.markers))
> + return;
So, you allow adding a phandle annotation if the property has no
existing type markers *or* you're adding it after position 0. That
seems a bit arbitrary and fragile.
> +
> + marker_add(&prop->val.markers, TYPE_UINT32, cell * sizeof(cell_t), NULL);
> + marker_add(&prop->val.markers, REF_PHANDLE, cell * sizeof(cell_t), ref);
> +}
> +
> static inline void PRINTF(5, 6) check_msg(struct check *c, struct dt_info *dti,
> struct node *node,
> struct property *prop,
> @@ -260,8 +310,12 @@ static void check_is_cell(struct check *c, struct dt_info *dti,
> if (!prop)
> return; /* Not present, assumed ok */
>
> - if (prop->val.len != sizeof(cell_t))
> + if (prop->val.len != sizeof(cell_t)) {
> FAIL_PROP(c, dti, node, prop, "property is not a single cell");
> + return;
> + }
> +
> + marker_add_type_annotations(prop, TYPE_UINT32, prop->val.len);
> }
> #define WARNING_IF_NOT_CELL(nm, propname) \
> WARNING(nm, check_is_cell, (propname))
> @@ -526,6 +580,8 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
> return 0;
> }
>
> + marker_add_type_annotations(prop, TYPE_UINT32, prop->val.len);
> +
> return phandle;
> }
>
> @@ -774,10 +830,14 @@ static void check_reg_format(struct check *c, struct dt_info *dti,
> size_cells = node_size_cells(node->parent);
> entrylen = (addr_cells + size_cells) * sizeof(cell_t);
>
> - if (!is_multiple_of(prop->val.len, entrylen))
> + if (!is_multiple_of(prop->val.len, entrylen)) {
> FAIL_PROP(c, dti, node, prop, "property has invalid length (%d bytes) "
> "(#address-cells == %d, #size-cells == %d)",
> prop->val.len, addr_cells, size_cells);
> + return;
> + }
> +
> + marker_add_type_annotations(prop, TYPE_UINT32, entrylen);
> }
> WARNING(reg_format, check_reg_format, NULL, &addr_size_cells);
>
> @@ -821,6 +881,8 @@ static void check_ranges_format(struct check *c, struct dt_info *dti,
> "#size-cells == %d)", ranges, prop->val.len,
> p_addr_cells, c_addr_cells, c_size_cells);
> }
> +
> + marker_add_type_annotations(prop, TYPE_UINT32, entrylen);
> }
> WARNING(ranges_format, check_ranges_format, "ranges", &addr_size_cells);
> WARNING(dma_ranges_format, check_ranges_format, "dma-ranges", &addr_size_cells);
> @@ -1389,6 +1451,7 @@ static void check_property_phandle_args(struct check *c,
> {
> struct node *root = dti->dt;
> unsigned int cell, cellsize = 0;
> + bool has_type = has_type_markers(prop->val.markers);
>
> if (!is_multiple_of(prop->val.len, sizeof(cell_t))) {
> FAIL_PROP(c, dti, node, prop,
> @@ -1417,7 +1480,7 @@ static void check_property_phandle_args(struct check *c,
> }
>
> /* If we have markers, verify the current cell is a phandle */
> - if (prop->val.markers) {
> + if (has_type) {
> struct marker *m = prop->val.markers;
> for_each_marker_of_type(m, REF_PHANDLE) {
> if (m->offset == (cell * sizeof(cell_t)))
> @@ -1454,7 +1517,11 @@ static void check_property_phandle_args(struct check *c,
> FAIL_PROP(c, dti, node, prop,
> "property size (%d) too small for cell size %d",
> prop->val.len, cellsize);
> + break;
> }
> +
> + if (!has_type)
> + marker_add_phandle_annotation(prop, cell, provider_node->fullpath);
> }
> }
>
> @@ -1629,10 +1696,13 @@ static void check_interrupts_property(struct check *c,
> FAIL_PROP(c, dti, parent, prop, "Bad phandle");
> return;
> }
> - if (!node_is_interrupt_provider(irq_node))
> + if (!node_is_interrupt_provider(irq_node)) {
> FAIL(c, dti, irq_node,
> "Missing interrupt-controller or interrupt-map property");
> + return;
> + }
>
> + marker_add_phandle_annotation(prop, 0, irq_node->fullpath);
> break;
> }
>
> @@ -1655,7 +1725,10 @@ static void check_interrupts_property(struct check *c,
> FAIL_PROP(c, dti, node, prop,
> "size is (%d), expected multiple of %d",
> irq_prop->val.len, (int)(irq_cells * sizeof(cell_t)));
> + return;
> }
> +
> + marker_add_type_annotations(irq_prop, TYPE_UINT32, irq_cells * sizeof(cell_t));
> }
> WARNING(interrupts_property, check_interrupts_property, &phandle_references);
>
> @@ -1776,8 +1849,12 @@ static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
> return NULL;
>
> node = get_node_by_phandle(dti->dt, phandle);
> - if (!node)
> + if (!node) {
> FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid");
> + return NULL;
> + }
> +
> + marker_add_phandle_annotation(prop, 0, node->fullpath);
Shouldn't this be the same as check_property_phandle_args() and verify
the type annotation if there's one already, only adding it if there
are no pre-existing types.
>
> return node;
> }
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-10-11 5:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 18:30 [PATCH v3 0/5] Improve output type formatting Rob Herring
[not found] ` <20210727183023.3212077-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-07-27 18:30 ` [PATCH v3 1/5] Move marker functions to dtc.h Rob Herring
[not found] ` <20210727183023.3212077-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-08-26 4:00 ` David Gibson
2021-09-27 20:56 ` Rob Herring
[not found] ` <CAL_Jsq+QAnyu=Fj_RtRu-dS4Ta0bZJWFUABsK1uKbnAKpXi1mA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-10-11 5:29 ` David Gibson
2021-07-27 18:30 ` [PATCH v3 2/5] Add has_type_markers() helper Rob Herring
2021-07-27 18:30 ` [PATCH v3 3/5] checks: Add markers on known properties Rob Herring
[not found] ` <20210727183023.3212077-4-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-10-11 5:09 ` David Gibson [this message]
2021-10-11 13:57 ` Rob Herring
2021-07-27 18:30 ` [PATCH v3 4/5] dtc: Drop dts source restriction for yaml output Rob Herring
[not found] ` <20210727183023.3212077-5-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-10-11 5:15 ` David Gibson
2021-10-11 13:22 ` Rob Herring
[not found] ` <CAL_Jsq+sMrRWqqPgcvoaiY0rLSp_s+gXOqJ9OuFLQ-3piUHSVA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-10-13 3:12 ` David Gibson
2021-10-14 1:29 ` Rob Herring
[not found] ` <CAL_Jsq+iv7eM+LZ1O8d3V18dHraEAyfgdT8ucFKKVXZc9jEp4g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-11-03 4:42 ` David Gibson
2021-11-03 15:59 ` Rob Herring
[not found] ` <CAL_JsqLNyfe8Ou4RXeLm0ie1vvJ+z15J6EDgB96dPbCC5qvHVQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-11-03 19:16 ` Rob Herring
[not found] ` <CAL_JsqKeNne0Bf0ahG_h977snsBtsk3hbQOPO-6RiyFSyiOsfA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-11-03 19:56 ` Simon Glass
[not found] ` <CAPnjgZ3BNPW+L4BrhQ9W4nLovSgcchWPfbznYxtf20sv2ntYaA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-11-03 22:42 ` Rob Herring
[not found] ` <CAL_JsqLdKsVO9kzkZcqL160COrpEp6GsR10AyPvmSG3B=grAXg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-11-03 22:48 ` Simon Glass
2021-11-09 4:41 ` David Gibson
2021-07-27 18:30 ` [PATCH v3 5/5] treesource: Maintain phandle label/path on output Rob Herring
[not found] ` <20210727183023.3212077-6-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-10-11 5:21 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YWPHDJBS51Ne2fMT@yekko \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox