[PATCH v4 18/22] libfdt: Introduce fdt_ptr_offset_()

From: Herve Codina

Date: Thu Nov 26 2026 - 06:25:31 EST


libfdt provides internal helpers to convert an offset to a pointer but
nothing to perform the reverse operation.

Introduce the fdt_ptr_offset_() internal helper to convert a pointer to
an offset.

Signed-off-by: Herve Codina <herve.codina@xxxxxxxxxxx>
Reviewed-by: Luca Ceresoli <luca.ceresoli@xxxxxxxxxxx>
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
---
libfdt/libfdt_internal.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h
index 8df9ffba..83e296b1 100644
--- a/libfdt/libfdt_internal.h
+++ b/libfdt/libfdt_internal.h
@@ -43,6 +43,11 @@ static inline void *fdt_offset_ptr_w_(void *fdt, int offset)
return (void *)(uintptr_t)fdt_offset_ptr_(fdt, offset);
}

+static inline int fdt_ptr_offset_(const void *fdt, const void *ptr)
+{
+ return (const char *)ptr - (const char *)fdt_offset_ptr_(fdt, 0);
+}
+
static inline const struct fdt_reserve_entry *fdt_mem_rsv_(const void *fdt, int n)
{
const struct fdt_reserve_entry *rsv_table =
--
2.56.1