Re: [PATCH v3 12/15] libfdt: Introduce fdt_getprop_offset_namelen()

From: David Gibson

Date: Mon Sep 21 2026 - 02:10:28 EST


On Wed, Aug 26, 2026 at 10:31:43AM +0200, Herve Codina wrote:
> Future operations, such as handling unknown tags on dtb modifications,
> need to get an offset to a property based on the node offset and the
> property name.
>
> Several function exists to get a property based on the node offset
> and the property name but none of them allows to get the property
> offset.
>
> Fill the lack and introduce fdt_getprop_offset_namelen() and its
> simple variant fdt_getprop_offset().
>
> Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>

This seems redundant with fdt_ptr_offset_(), which can trivially get
this information when combined with fdt_get_property().

> ---
> libfdt/fdt_ro.c | 13 +++++++++++++
> libfdt/libfdt_internal.h | 8 ++++++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index 856c62f1..50c0a8bc 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -536,6 +536,19 @@ const void *fdt_getprop(const void *fdt, int nodeoffset,
> return fdt_getprop_namelen(fdt, nodeoffset, name, strlen(name), lenp);
> }
>
> +int fdt_getprop_offset_namelen(const void *fdt, int nodeoffset,
> + const char *name, int namelen)
> +{
> + const struct fdt_property *prop;
> + int lenp, offset;
> +
> + prop = fdt_get_property_namelen_(fdt, nodeoffset, name, namelen,
> + &lenp, &offset);
> + if (!prop)
> + return lenp;
> + return offset;
> +}
> +
> uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
> {
> const fdt32_t *php;
> diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h
> index 3c83d9a7..e3923629 100644
> --- a/libfdt/libfdt_internal.h
> +++ b/libfdt/libfdt_internal.h
> @@ -26,6 +26,14 @@ uint32_t fdt_next_tag_(const void *fdt, int startoffset, int *nextoffset,
> int fdt_check_node_offset_(const void *fdt, int offset);
> int fdt_check_prop_offset_(const void *fdt, int offset);
>
> +int fdt_getprop_offset_namelen(const void *fdt, int nodeoffset,
> + const char *name, int namelen);
> +static inline int fdt_getprop_offset(const void *fdt, int nodeoffset,
> + const char *name)
> +{
> + return fdt_getprop_offset_namelen(fdt, nodeoffset, name, strlen(name));
> +}
> +
> const char *fdt_find_string_len_(const char *strtab, int tabsize, const char *s,
> int s_len);
> static inline const char *fdt_find_string_(const char *strtab, int tabsize,
> --
> 2.55.0
>
>

--
David Gibson (he or they) | 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