aboutsummaryrefslogtreecommitdiff
path: root/libfdt/fdt_ro.c
diff options
context:
space:
mode:
authorPierre-Clément Tosi <ptosi@google.com>2023-10-12 13:05:42 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-10-12 13:05:42 +0000
commit132ab4d21169531f07e13345b6f9cb14f395aba9 (patch)
tree6592a432c0666810878e34f66af02ae02fe0a068 /libfdt/fdt_ro.c
parent14b204d7072ea39830d84802e11b39dd4f693612 (diff)
parente5b8c171c50ad29e12b3689cc0cc8ef1a0fcb313 (diff)
downloaddtc-132ab4d21169531f07e13345b6f9cb14f395aba9.tar.gz
Merge changes I1e5a8903,I43c6ad22,If9a102a6,I702e619c into main am: e5b8c171c5
Original change: https://android-review.googlesource.com/c/platform/external/dtc/+/2784253 Change-Id: I0afccef8cf1d66b917fb815c72692f047b7b7672 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'libfdt/fdt_ro.c')
-rw-r--r--libfdt/fdt_ro.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 53db8ce..09d92d4 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -10,14 +10,6 @@
#include "libfdt_internal.h"
-/* Check if a buffer contains a nul-terminated string.
- * Used for checking property values which should be strings.
- */
-static bool is_nul_string(const char *buf, const size_t buf_len) {
- return buf_len > 0 && buf[buf_len - 1] == '\0' &&
- strnlen(buf, buf_len) == buf_len - 1;
-}
-
static int fdt_nodename_eq_(const void *fdt, int offset,
const char *s, int len)
{
@@ -533,30 +525,31 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
return fdt32_ld_(php);
}
+static const void *fdt_path_getprop_namelen(const void *fdt, const char *path,
+ const char *propname, int propnamelen,
+ int *lenp)
+{
+ int offset = fdt_path_offset(fdt, path);
+
+ if (offset < 0)
+ return NULL;
+
+ return fdt_getprop_namelen(fdt, offset, propname, propnamelen, lenp);
+}
+
const char *fdt_get_alias_namelen(const void *fdt,
const char *name, int namelen)
{
- const char *prop;
- int aliasoffset;
- int prop_len;
+ int len;
+ const char *alias;
- aliasoffset = fdt_path_offset(fdt, "/aliases");
- if (aliasoffset < 0)
- return NULL;
+ alias = fdt_path_getprop_namelen(fdt, "/aliases", name, namelen, &len);
- prop = fdt_getprop_namelen(fdt, aliasoffset, name, namelen, &prop_len);
- if (prop && !can_assume(VALID_INPUT)) {
- /* Validate the alias value. From the devicetree spec v0.3:
- * "An alias value is a device path and is encoded as a string.
- * The value representes the full path to a node, ..."
- * A full path must start at the root to prevent recursion.
- */
- if (prop_len == 0 || *prop != '/' || !is_nul_string(prop, prop_len)) {
- prop = NULL;
- }
- }
+ if (!can_assume(VALID_DTB) &&
+ !(alias && len > 0 && alias[len - 1] == '\0' && *alias == '/'))
+ return NULL;
- return prop;
+ return alias;
}
const char *fdt_get_alias(const void *fdt, const char *name)