devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fdt_get_phandle: Return invalid phandles as 0
@ 2022-08-01 12:31 Pierre-Clément Tosi
       [not found] ` <20220801123134.1499236-1-ptosi-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Pierre-Clément Tosi @ 2022-08-01 12:31 UTC (permalink / raw)
  To: David Gibson
  Cc: Pierre-Clément Tosi,
	devicetree-compiler-u79uwXL29TY76Z2rM5mHXA

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>
---
 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,
-- 
2.37.1.455.g008518b4e5-goog


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

end of thread, other threads:[~2022-08-04  4:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).