Thread (57 messages) flat view 57 messages, 2 authors, 4h ago
HOTtoday

Revision v3 of 2 in this series.

Revisions (2)
  1. rfc [diff vs current]
  2. v3 current

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

From: Herve Codina <herve.codina@bootlin.com>
Date: 2026-08-26 08:33:05
Also in: lkml
Subsystem: the rest · Maintainer: Linus Torvalds

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@bootlin.com>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help