[PATCH 0/7] RTC: libfdt: Allow more control of code size

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



Since v1.4.6 libfdt has gained a number of checks for incorrect
device-tree input and incorrect parameters. These are valuable and should
be enabled by default. Some are basic sanity checks and some are designed
to avoid security risks with carefully crafted device-tree input.

However the checks have added to code size to such an extent that many
U-Boot boards can no-longer build/boot in SPL. This has prevented recent
versions of libfdt from being used by U-Boot.

U-Boot SPL generally reads a device tree which has been set up by the
build system and is known to be correct (e.g. it may be cryptographically
signed by the build system). Therefore santiy checks in SPL should never
fail, and just contribute to longer run-time and larger code size.

During review of those patches[1] the code-size impact was discussed and
a possible solution was suggested.

This series adds 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. This allows U-Boot SPL to continue to use later versions of
libfdt.

Within the code, inline functions are used which resolve to true or false
to control the use of checks in the code. This seems better than using
ensures that all code is compiled regardless of which checks are enabled
(useful for build coverage).

This series reduces the size of libfdt by about 3KB on 64-bit x86
(about 6%) when all sanity checks are disabled. Future work could probably
reduce this further, but this is a good start.

Note: libfdt includes a number of assignments in conditional statements.
I have only changed these where necessary. It might be desirable to remove
them all, to reduce the output from checkpatch.pl.

[1] https://www.spinics.net/lists/devicetree-compiler/msg02166.html


Simon Glass (7):
  Add a way to control the level of checks in the code
  libfdt: Allow control of checks in fdt.c
  libfdt: Allow control of checks in fdt_ro.c
  libfdt: Allow control of checks in fdt_rw.c
  libfdt: Allow control of checks in fdt_sw.c
  libfdt: Allow control of FDT_RO_PROBE
  libfdt: Allow control of version checks

 Makefile                 | 10 ++++-
 libfdt/fdt.c             | 89 ++++++++++++++++++++++------------------
 libfdt/fdt_ro.c          | 87 ++++++++++++++++++++++++---------------
 libfdt/fdt_rw.c          | 16 +++++---
 libfdt/fdt_sw.c          | 27 +++++++-----
 libfdt/libfdt.h          | 43 ++++++++++++++++++-
 libfdt/libfdt_internal.h |  2 +-
 7 files changed, 184 insertions(+), 90 deletions(-)

-- 
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