aboutsummaryrefslogtreecommitdiff
path: root/libfdt/fdt.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2017-10-22 16:32:15 +1100
committerDavid Gibson <david@gibson.dropbear.id.au>2018-06-07 11:45:44 +1000
commit04b5b4062ccd55ea7caf04c0eb02753e6986df76 (patch)
treed660bcc412a0f5992da1aac02eff6ec77997134e /libfdt/fdt.c
parent44d3efedc81618e2d51ebbc2305ff020d1107988 (diff)
downloaddtc-04b5b4062ccd55ea7caf04c0eb02753e6986df76.zip
dtc-04b5b4062ccd55ea7caf04c0eb02753e6986df76.tar.gz
dtc-04b5b4062ccd55ea7caf04c0eb02753e6986df76.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 'libfdt/fdt.c')
-rw-r--r--libfdt/fdt.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libfdt/fdt.c b/libfdt/fdt.c
index 7855a17..8bbf2dc 100644
--- a/libfdt/fdt.c
+++ b/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;