Re: [RFC PATCH 06/15] libfdt: Don't assume that a FDT_BEGIN_NODE tag is available at offset 0
From: Luca Ceresoli
Date: Wed Apr 01 2026 - 11:34:21 EST
On Tue Feb 10, 2026 at 6:33 PM CET, Herve Codina wrote:
> In several places, libfdt assumes that a FDT_BEGIN_NODE tag is present
> at the offset 0 of the structure block.
>
> This assumption is not correct. Indeed, a FDT_NOP can be present at the
> offset 0 and this is a legit case.
>
> fdt_first_node() has been introduce recently to get the offset of the
^
introduced
> first node (first FDT_BEGIN_NODE) in a fdt blob.
>
> Use this function to get the first node offset instead of looking for
> this node at offset 0.
>
> Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>
> ---
> libfdt/fdt.c | 10 ++++++++--
> libfdt/fdt_ro.c | 16 +++++++++++++---
> libfdt/fdt_rw.c | 6 ++++++
> 3 files changed, 27 insertions(+), 5 deletions(-)
>
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index 676c7d7..ff2fa6c 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -279,11 +279,17 @@ int fdt_first_node(const void *fdt)
>
> int fdt_next_node(const void *fdt, int offset, int *depth)
> {
> - int nextoffset = 0;
> + int nextoffset = offset;
> uint32_t tag;
>
> + if (offset <= 0) {
What is the difference between 0 and a engative value?
This is where the parameter value is not obvious to the newcomer and I'd
love seeing it concisely documented.
Otherwise this patch looks good to me.
Luca
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com