[PATCH 1/3] dm: core: Check ofnode_to_offset() return value
Simon Glass
sjg at chromium.org
Thu Nov 13 20:33:16 CET 2025
Hi Marek,
On Thu, 13 Nov 2025 at 05:21, Marek Vasut
<marek.vasut+renesas at mailbox.org> wrote:
>
> The ofnode_to_offset() may return -1 , which is not a valid value
> and is not accepted by modern libfdt 1.7.2. Check the return value
> from ofnode_to_offset() and exit early in case it is not a valid
> offset.
>
> Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
> ---
> Cc: Adriano Cordova <adrianox at gmail.com>
> Cc: Andrew Goodbody <andrew.goodbody at linaro.org>
> Cc: Christian Marangi <ansuelsmth at gmail.com>
> Cc: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> Cc: Patrice Chotard <patrice.chotard at foss.st.com>
> Cc: Sam Edwards <cfsworks at gmail.com>
> Cc: Simon Glass <sjg at chromium.org>
> Cc: Tom Rini <trini at konsulko.com>
> Cc: u-boot at lists.denx.de
> ---
> drivers/core/ofnode.c | 384 +++++++++++++++++++++++++++++++-----------
> 1 file changed, 284 insertions(+), 100 deletions(-)
>
> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
> index 071d998a0a5..55c2b3a10bb 100644
> --- a/drivers/core/ofnode.c
> +++ b/drivers/core/ofnode.c
> @@ -335,7 +335,7 @@ bool ofnode_name_eq_unit(ofnode node, const char *name)
> int ofnode_read_u8(ofnode node, const char *propname, u8 *outp)
> {
> const u8 *cell;
> - int len;
> + int len, off;
>
> assert(ofnode_valid(node));
> log_debug("%s: %s: ", __func__, propname);
> @@ -343,8 +343,13 @@ int ofnode_read_u8(ofnode node, const char *propname, u8 *outp)
> if (ofnode_is_np(node))
> return of_read_u8(ofnode_to_np(node), propname, outp);
>
> - cell = fdt_getprop(gd->fdt_blob, ofnode_to_offset(node), propname,
> - &len);
> + off = ofnode_to_offset(node);
> + if (off < 0) {
> + log_debug("(not valid)\n");
> + return -EINVAL;
> + }
Ugh this is really horrible, sorry :-)
Better to put a wrapper around it than add all these checks, extra
code size, etc. Also in many cases the ofnode is known to be valid(TM)
so it might just be a waste.
Regards,
Simon
More information about the U-Boot
mailing list