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@xxxxxxxxxx> 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:
signature.asc
Description: PGP signature