Re: [PATCH 3/3] libfdt: fdt_get_name: Add can_assume(VALID_DTB) check

David Gibson <[email protected]> Wed, 10 Dec 2025 17:47:58 +1100
Newsgroups org.kernel.vger.devicetree-compiler
Message-ID <aTkXnnYkjvPbN3Yd@zatzit>
On Tue, Dec 09, 2025 at 03:50:53PM -0600, Tom Rini wrote:
11;rgb:ffff/ffff/ffff> In this function from fdt_ro.c we have (reasonably) some checks of the
> DTB before we begin work. However, we do this in a way that we cannot
> make use of the normal FDT_RO_PROBE macro and instead have a direct call
> to fdt_ro_probe_(). Add a test for !can_assume(VALID_DTB) here first so
> that in cases where we are assuming a valid DTB we can omit the checks.
> 
> Signed-off-by: Tom Rini <[email protected]>

Applied, thanks.

> ---
> This is another case which we see in U-Boot SPL, and for the last 6
> years now have had the equivalent check. This change ends up being a
> noticeable size win for us.
> ---
>  libfdt/fdt_ro.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
> index b78c4e48f1cb..63494fb7ad90 100644
> --- a/libfdt/fdt_ro.c
> +++ b/libfdt/fdt_ro.c
> @@ -306,8 +306,8 @@ const char *fdt_get_name(const void *fdt, int nodeoffset, int *len)
>  	const char *nameptr;
>  	int err;
>  
> -	if (((err = fdt_ro_probe_(fdt)) < 0)
> -	    || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0))
> +	if (!can_assume(VALID_DTB) && (((err = fdt_ro_probe_(fdt)) < 0)
> +	    || ((err = fdt_check_node_offset_(fdt, nodeoffset)) < 0)))
>  			goto fail;
>  
>  	nameptr = nh->name;
> -- 
> 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+dNsU4E3yXUXRK2zQJF27ox2GcFAmk5F50ACgkQzQJF27ox
2Ge5Kw/+LvXDCx4YQqdAQ7GE6j0LIyTf4rgEBfo7rW29r/QCiRlINg1M7rNg+PVH
nfnnjE6tpqywMIRjaEpvrR2jvLsnqCkN89sIF20LL4qwrqVZRMDtfqVBHt/UEldY
8uWi9YXyRrrKn+XFzVzLCpMwTn+eI9w97x5ZZOsMjYqj3iT7sQoOGahXykpFM3Ox
DbZKfq9oPABAIfT+G4527pbz6tmywRss9nU8j47ueP4J68dHoAO2AtyUj71Cy+Yn
SomKxsjNtvvAVmiUKWnX8hKeou1AbWRyOLsuDCh0XN108XBOSAgW5EEEVHFXeldD
BxCAuovgJfWKcLp70o6/y9mP6mf0TVZDlVgf05bYaMmPda2VsTPkymdzqIy7l00q
srku/XlQ0pC+y0SdzXCcDGV0J69m3wn1M16iaHAg8f0jMdd/MZAeZs2Rp/cCHYDP
TrJ57vXUvdR77f1AxUGTQW9d8unJQadyYZyJUbVf6eD7uzxB55pQEBh2SXNtNJUn
TlPOumEluvRGJ/a0wxEgtpcbnEMDDC6I+W7M+XoFQClrpla4t+gOKcqf4SkSBNAy
CjU8zN8f7934S7k62RP7x9jDe0951f4bR4JNzoR21UoXM12t4lHSmNulo/c3AbKz
CUql7+b5xq203Ks93IK/cZbnYp0l65PP3O7Vo3KnbKBnYGp/S2M=
=C9UN
-----END PGP SIGNATURE-----