From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: "Pierre-Clément Tosi" <ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] fdt_get_phandle: Return invalid phandles as 0
Date: Tue, 2 Aug 2022 16:47:19 +1000 [thread overview]
Message-ID: <YujId/uczDRrdJ9v@yekko> (raw)
In-Reply-To: <20220801123134.1499236-1-ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1632 bytes --]
On Mon, Aug 01, 2022 at 01:31:34PM +0100, Pierre-Clément Tosi wrote:
> If a tree contains an invalid <u32> value as its <phandle> property,
> mask it with '0' (invalid value) instead of returning it from
> fdt_get_phandle().
>
> Signed-off-by: Pierre-Clément Tosi <ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Hm.. I don't really see the point of this. Because FDT_MAX_PHANDLE is
0xfffffffe (-2), the only effect this has is to change 0xffffffff (-1)
into 0 when returned. Both are, indeed, invalid phandles, but they're
sometimes used to mean slightly different things in incomplete trees,
so it seems more useful to return these separately
> ---
> libfdt/fdt_ro.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index 9f6c551..7d1da6d 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -507,6 +507,7 @@ const void *fdt_getprop(const void *fdt, int nodeoffset,
>
> uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
> {
> + uint32_t phandle;
> const fdt32_t *php;
> int len;
>
> @@ -519,7 +520,11 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
> return 0;
> }
>
> - return fdt32_ld_(php);
> + phandle = fdt32_ld_(php);
> + if (phandle > (uint32_t)FDT_MAX_PHANDLE)
> + phandle = 0;
> +
> + return phandle;
> }
>
> const char *fdt_get_alias_namelen(const void *fdt,
--
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:[~2022-08-02 6:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 12:31 [PATCH] fdt_get_phandle: Return invalid phandles as 0 Pierre-Clément Tosi
[not found] ` <20220801123134.1499236-1-ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2022-08-02 6:47 ` David Gibson [this message]
2022-08-02 13:44 ` Pierre-Clément Tosi
[not found] ` <20220802134437.b75rj4mjvhosvh36-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2022-08-04 4:57 ` 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=YujId/uczDRrdJ9v@yekko \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=ptosi-hpIqsD4AKlfQT0dZR+AlfA@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).