From: Marek Vasut <marek.vasut@mailbox.org>
To: Simon Glass <sjg@chromium.org>
Cc: Marek Vasut <marek.vasut+renesas@mailbox.org>,
u-boot@lists.denx.de, Adriano Cordova <adrianox@gmail.com>,
Andrew Goodbody <andrew.goodbody@linaro.org>,
Christian Marangi <ansuelsmth@gmail.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Patrice Chotard <patrice.chotard@foss.st.com>,
Sam Edwards <cfsworks@gmail.com>, Tom Rini <trini@konsulko.com>
Subject: Re: [PATCH 1/3] dm: core: Check ofnode_to_offset() return value
Date: Fri, 14 Nov 2025 06:17:27 +0100 [thread overview]
Message-ID: <fd30d6ca-fdfe-4096-8057-a952a6a4bb7e@mailbox.org> (raw)
In-Reply-To: <CAFLszTjktw3yS9Dp9KGC=BAnpJAHg46f--NRRfnzXApQVOiuUQ@mail.gmail.com>
On 11/13/25 11:46 PM, Simon Glass wrote:
Hello Simon,
>>>> 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.
>>
>> How would you propose the wrapper should look like ?
>>
>> Keep in mind, not everything is fdt_getprop( ... ofnode_to_offset() ...)
>> in this patch.
>
> I was thinking of
>
> my_fdt_getprop(fdt, node, propname, lenp)
> {
> if (node is not valid)
> return NULL;
> return fdt_getprop();
> }
We would need a wrapper for almost every libfdt call, which isn't really
better.
> What does fdt_getprop() return when the offset is -1 ?
If can_assume(VALID_DTB) , then crash on NULL pointer dereference .
If not, I think FDT_END (premature end) or an error code.
next prev parent reply other threads:[~2025-11-14 5:17 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 12:21 [PATCH 0/3] Synchronize DTC to 1.7.2 Marek Vasut
2025-11-13 12:21 ` [PATCH 1/3] dm: core: Check ofnode_to_offset() return value Marek Vasut
2025-11-13 19:33 ` Simon Glass
2025-11-13 21:51 ` Marek Vasut
2025-11-13 22:46 ` Simon Glass
2025-11-14 5:17 ` Marek Vasut [this message]
2025-11-14 14:36 ` Tom Rini
2025-11-16 0:16 ` Marek Vasut
2025-11-16 14:13 ` Tom Rini
2025-11-16 21:28 ` Marek Vasut
2025-11-17 14:14 ` Tom Rini
2025-11-13 12:21 ` [PATCH 2/3] scripts/dtc: Update to upstream version v1.7.2-35-g52f07dcca47c Marek Vasut
2025-11-13 12:21 ` [PATCH 3/3] libfdt: Check fdt_offset_ptr() return value unconditionally Marek Vasut
2025-11-13 19:33 ` Simon Glass
2025-11-13 21:48 ` Marek Vasut
2025-11-13 23:34 ` Simon Glass
2025-11-20 4:20 ` Marek Vasut
2025-11-13 17:57 ` [PATCH 0/3] Synchronize DTC to 1.7.2 Tom Rini
2025-11-13 18:40 ` Marek Vasut
2025-11-13 18:49 ` Tom Rini
2025-11-13 19:32 ` Simon Glass
2025-11-15 23:23 ` Marek Vasut
2025-11-16 14:11 ` Tom Rini
2025-11-16 21:48 ` Marek Vasut
2025-11-17 18:40 ` Tom Rini
2025-11-19 21:31 ` Marek Vasut
2025-11-20 15:54 ` Tom Rini
2025-11-20 20:14 ` Marek Vasut
2025-11-21 19:55 ` Tom Rini
2025-12-02 17:46 ` Marek Vasut
2025-12-02 18:06 ` Tom Rini
2025-12-02 18:35 ` Marek Vasut
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=fd30d6ca-fdfe-4096-8057-a952a6a4bb7e@mailbox.org \
--to=marek.vasut@mailbox.org \
--cc=adrianox@gmail.com \
--cc=andrew.goodbody@linaro.org \
--cc=ansuelsmth@gmail.com \
--cc=cfsworks@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=marek.vasut+renesas@mailbox.org \
--cc=patrice.chotard@foss.st.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/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