summaryrefslogtreecommitdiffstats
path: root/cpukit/dtc/libfdt/fdt.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2017-10-22 16:32:15 +1100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2018-07-19 07:01:11 +0200
commit85d17691faa51925c5bf2316f80612ebb02f7c89 (patch)
tree750897ee2dab86936c35f228880af183cb98e1a2 /cpukit/dtc/libfdt/fdt.c
parentAdd limited read-only support for older (V2 and V3) device tree to libfdt. (diff)
downloadrtems-85d17691faa51925c5bf2316f80612ebb02f7c89.tar.bz2
libfdt: Clean up header checking functions
Many of the libfdt entry points call some sort of sanity check function before doing anything else. These need to do slightly different things for the various classes of functions. The read-only version is shared with the exported fdt_check_header(), which limits us a bit in how we can improve it. For that reason split the two functions apart (though the exported one just calls the ro one for now). We also rename the functions for more consistency - they're all named fdt_XX_probe_() where the XX indicates which class of functions they're for. "probe" is a better "term" than the previous check, since they really only do minimal validation. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Tested-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'cpukit/dtc/libfdt/fdt.c')
-rw-r--r--cpukit/dtc/libfdt/fdt.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/cpukit/dtc/libfdt/fdt.c b/cpukit/dtc/libfdt/fdt.c
index 7855a17877..8bbf2dc894 100644
--- a/cpukit/dtc/libfdt/fdt.c
+++ b/cpukit/dtc/libfdt/fdt.c
@@ -55,7 +55,12 @@
#include "libfdt_internal.h"
-int fdt_check_header(const void *fdt)
+/*
+ * Minimal sanity check for a read-only tree. fdt_ro_probe_() checks
+ * that the given buffer contains what appears to be a flattened
+ * device tree with sane information in its header.
+ */
+int fdt_ro_probe_(const void *fdt)
{
if (fdt_magic(fdt) == FDT_MAGIC) {
/* Complete tree */
@@ -74,6 +79,11 @@ int fdt_check_header(const void *fdt)
return 0;
}
+int fdt_check_header(const void *fdt)
+{
+ return fdt_ro_probe_(fdt);
+}
+
const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
{
unsigned absoffset = offset + fdt_off_dt_struct(fdt);
@@ -244,7 +254,7 @@ const char *fdt_find_string_(const char *strtab, int tabsize, const char *s)
int fdt_move(const void *fdt, void *buf, int bufsize)
{
- FDT_CHECK_HEADER(fdt);
+ FDT_RO_PROBE(fdt);
if (fdt_totalsize(fdt) > bufsize)
return -FDT_ERR_NOSPACE;