Re: [PATCH 2/3] libfdt: Improve size savings in FDT_RO_PROBE slightly

David Gibson <[email protected]> Wed, 10 Dec 2025 17:46:44 +1100
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <aTkXVOPm3BoinU24@zatzit>
On Tue, Dec 09, 2025 at 03:50:52PM -0600, Tom Rini wrote:
> 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]>

Applied, thanks.

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

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmk5F1MACgkQzQJF27ox
2Gdjzg//dbGXP/BSEgWJSlSb/FZM7iQuEQ+FHyf+u8MCa8dQ23KHZFyQfWYewrlV
nei+6ZgK3V9yFEoSkIxOxuFCRhc7m1gvvthk34k2XwRNC/pQa0+VId0kUsGd/tjv
7eSQjb2yiwx9aH6Am4IJX5PY0ZqsVRY2D2JnI6PGSVZs4kaY0wQuQL9vT/8pl+t8
EsD3m4m4AU682xr/8qIarSFxjJuD/TPb4lU6zyP1k6GmI5Tk5UwCDiuolxHABw9g
/NGpsk77vGOeJ+rc2I/3XbfjWrYATEZ3uxv3x0ixpUQDTvYo8h093zike81DMu72
jZ1NthZQPWVavu1hFHdbr86e8RgeNjS64LXca1IxTx4DkcOmNouiAbA7g61ZeqxW
fCDus/aRTNR6EtvgXXofNsmrCGCKC7uVQHNR+BTNqlJ3xIXIE0DvtZTmKFlbXFZB
HX1j6y5PuAJlxIGR/5IvL/44nbtRkoncUJGAmD/YenydtiYjQhXhJzboqMS8ax9y
mCLBHVoR+hxSXSHzTn8sS+k7wsfOK/Cj4mYLiXAmBwh25h4XjlhRnwngIWZhF750
LfAp+FsN7n1pTPka7bOmmsiE2q5Y2iGNNH1CDp+JJabqOjok5XAnAOj0Y+nhldCX
2iUCnYD5wDwGuVwqEOMHQkVg+OPyL2kkc/4xyUZ9tfSPFYzgJqc=
=J49W
-----END PGP SIGNATURE-----