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 1/5] yamltree: Remove marker ordering dependency
Date: Tue, 8 Jun 2021 11:54:33 +1000 [thread overview]
Message-ID: <YL7N2Q1zjvtFcy3z@yekko> (raw)
In-Reply-To: <20210526010335.860787-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 3211 bytes --]
On Tue, May 25, 2021 at 08:03:31PM -0500, Rob Herring wrote:
> The check for phandle markers is fragile because the phandle marker must
> be after a type marker. The only guarantee for markers is they are in
> offset order. The order at a specific offset is undefined.
>
> Rework yaml_propval_int() to get the full marker list, so it can find a
> phandle marker no matter the ordering.
>
> Signed-off-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Frankly, I think the difference in data models is enough that yaml
output will *always* be fragile, but this helps somewhat so I've
applied it.
> ---
> yamltree.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/yamltree.c b/yamltree.c
> index e63d32fe142a..55908c829c98 100644
> --- a/yamltree.c
> +++ b/yamltree.c
> @@ -29,11 +29,12 @@ char *yaml_error_name[] = {
> (emitter)->problem, __func__, __LINE__); \
> })
>
> -static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers, char *data, unsigned int len, int width)
> +static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers,
> + char *data, unsigned int seq_offset, unsigned int len, int width)
> {
> yaml_event_t event;
> void *tag;
> - unsigned int off, start_offset = markers->offset;
> + unsigned int off;
>
> switch(width) {
> case 1: tag = "!u8"; break;
> @@ -66,7 +67,7 @@ static void yaml_propval_int(yaml_emitter_t *emitter, struct marker *markers, ch
> m = markers;
> is_phandle = false;
> for_each_marker_of_type(m, REF_PHANDLE) {
> - if (m->offset == (start_offset + off)) {
> + if (m->offset == (seq_offset + off)) {
> is_phandle = true;
> break;
> }
> @@ -114,6 +115,7 @@ static void yaml_propval(yaml_emitter_t *emitter, struct property *prop)
> yaml_event_t event;
> unsigned int len = prop->val.len;
> struct marker *m = prop->val.markers;
> + struct marker *markers = prop->val.markers;
>
> /* Emit the property name */
> yaml_scalar_event_initialize(&event, NULL,
> @@ -151,19 +153,19 @@ static void yaml_propval(yaml_emitter_t *emitter, struct property *prop)
>
> switch(m->type) {
> case TYPE_UINT16:
> - yaml_propval_int(emitter, m, data, chunk_len, 2);
> + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 2);
> break;
> case TYPE_UINT32:
> - yaml_propval_int(emitter, m, data, chunk_len, 4);
> + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 4);
> break;
> case TYPE_UINT64:
> - yaml_propval_int(emitter, m, data, chunk_len, 8);
> + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 8);
> break;
> case TYPE_STRING:
> yaml_propval_string(emitter, data, chunk_len);
> break;
> default:
> - yaml_propval_int(emitter, m, data, chunk_len, 1);
> + yaml_propval_int(emitter, markers, data, m->offset, chunk_len, 1);
> break;
> }
> }
--
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-06-08 1:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 1:03 [PATCH 0/5] Improve output type formatting Rob Herring
[not found] ` <20210526010335.860787-1-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-05-26 1:03 ` [PATCH 1/5] yamltree: Remove marker ordering dependency Rob Herring
[not found] ` <20210526010335.860787-2-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-06-08 1:54 ` David Gibson [this message]
2021-05-26 1:03 ` [PATCH 2/5] checks: Add check_is_cell() for all phandle+arg properties Rob Herring
[not found] ` <20210526010335.860787-3-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-06-08 1:57 ` David Gibson
2021-06-08 14:45 ` Rob Herring
[not found] ` <CAL_JsqL5ks9G1_q+8LN_ceNjE-d40ri8G2BmnxnPCCa+UrqHgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-06-15 6:02 ` David Gibson
2021-05-26 1:03 ` [PATCH 3/5] checks: Drop interrupt_cells_is_cell check Rob Herring
[not found] ` <20210526010335.860787-4-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-06-08 1:58 ` David Gibson
2021-05-26 1:03 ` [PATCH 4/5] checks: Add markers on known properties Rob Herring
[not found] ` <20210526010335.860787-5-robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2021-06-08 2:25 ` David Gibson
2021-06-08 12:49 ` Rob Herring
[not found] ` <CAL_JsqKb-4ay9JNLUOetupxBKNpBsFNB-Ztc1ocbDSj_KxSWsg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2021-06-15 6:01 ` David Gibson
2021-06-15 14:25 ` Rob Herring
2021-05-26 1:03 ` [PATCH 5/5] dtc: Drop dts source restriction for yaml output Rob Herring
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=YL7N2Q1zjvtFcy3z@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;
as well as URLs for NNTP newsgroup(s).