[PATCH 1/7] Add a way to control the level of checks in the code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Add a new CHECK_LEVEL option, which allows for some control over the
checks used in libfdt. At the minimum level, libfdt assumes that the input
data and parameters are all correct and that internal errors cannot
happen.

By default all checks are enabled.

Signed-off-by: Simon Glass <sjg@xxxxxxxxxxxx>
---

 Makefile        | 10 +++++++++-
 libfdt/libfdt.h | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 98f74b1..1ed7115 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,15 @@ EXTRAVERSION =
 LOCAL_VERSION =
 CONFIG_LOCALVERSION =
 
-CPPFLAGS = -I libfdt -I .
+# Set the level of checking (e.g. to avoid security issues) to include in the
+# code:
+# 0 - no checking (minimal code size)
+# 1 - very basic checking, assuming DT is sane but may be an old version
+# 2 - most checking, will catch most DT and API parameter inconsistencies
+# 3 - all possible checks with no regard to performance or code size
+CHECK_LEVEL ?= 3
+
+CPPFLAGS = -I libfdt -I . -DCHECK_LEVEL=$(CHECK_LEVEL)
 WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
 	-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
 CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS)
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index 8037f39..3277468 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -172,6 +172,47 @@ static inline void fdt64_st(void *property, uint64_t value)
 	bp[7] = value & 0xff;
 }
 
+/**********************************************************************/
+/* Checking controls                                                  */
+/**********************************************************************/
+
+#ifndef CHECK_LEVEL
+#define CHECK_LEVEL 3
+#endif
+
+/**
+ * _check1() - see if basic checking of parameters and DT data is enabled
+ *
+ * This level assumes that the device tree is sane (header metadata and basic
+ * hierarchy are correct). Old device-tree versions are handled correctly.
+ */
+static inline bool _check1(void)
+{
+	return CHECK_LEVEL >= 1;
+}
+
+/**
+ * _check2() - see if normal checking of parameters and DT data is enabled
+ *
+ * This level enables extensive checking of parameters and the device tree,
+ * making few assumptions about correctness.
+ */
+static inline bool _check2(void)
+{
+	return CHECK_LEVEL >= 2;
+}
+
+/**
+ * _check3() - see if full checking is enabled
+ *
+ * This level enables all possible checks with no regard to performance or code
+ * size.
+ */
+static inline bool _check3(void)
+{
+	return CHECK_LEVEL >= 3;
+}
+
 /**********************************************************************/
 /* Traversal functions                                                */
 /**********************************************************************/
-- 
2.22.0.657.g960e92d24f-goog




[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux