[PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly
Tom Rini <[email protected]> Tue, 9 Dec 2025 15:50:52 -0600
| Newsgroups | org.kernel.vger.devicetree-compiler |
|---|---|
| Message-ID | <[email protected]> |
In the case where we have set FDT_ASSUME_MASK to disable ASSUME_VALID_DTB checks, we can improve the FDT_RO_PROBE macro slightly. The first thing that fdt_ro_probe_() does when we can_assume(VALID_DTB) is true is to return whatever the contents of the totalsize field of the DTB is. Since the FDT_RO_PROBE macro only cares about a negative value there, we can optimize this check such that we are to assume it's a valid DTB, we don't need to do anything here. Signed-off-by: Tom Rini <[email protected]> --- In the case of U-Boot SPL (and similar very early stages) we are extremely concerned with binary size, and also assume the device tree is valid. This patch here is not a huge savings for us, but every little bit helps when talking about something that impacts more than half our build configurations. --- libfdt/libfdt_internal.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libfdt/libfdt_internal.h b/libfdt/libfdt_internal.h index 9eb32394eb79..0e103cafa714 100644 --- a/libfdt/libfdt_internal.h +++ b/libfdt/libfdt_internal.h @@ -11,11 +11,13 @@ #define FDT_TAGALIGN(x) (FDT_ALIGN((x), FDT_TAGSIZE)) int32_t fdt_ro_probe_(const void *fdt); -#define FDT_RO_PROBE(fdt) \ - { \ - int32_t totalsize_; \ - if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ - return totalsize_; \ +#define FDT_RO_PROBE(fdt) \ + { \ + if (!can_assume(VALID_DTB)) { \ + int32_t totalsize_; \ + if ((totalsize_ = fdt_ro_probe_(fdt)) < 0) \ + return totalsize_; \ + } \ } int fdt_check_node_offset_(const void *fdt, int offset); -- 2.43.0