Re: [RFC PATCH 03/15] fdtdump: Return an error code on wrong tag value

David Gibson <[email protected]> Tue, 24 Feb 2026 16:57:52 +1100
Newsgroups org.kernel.vger.devicetree-spec,org.kernel.vger.devicetree-compiler,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel
Message-ID <aZ094BpPg4r_xBng@zatzit>
--+1Q0sZ7XDKS8rVEz
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Feb 23, 2026 at 09:39:50AM +0100, Herve Codina wrote:
> Hi David,
>=20
> On Mon, 23 Feb 2026 16:38:09 +1100
> David Gibson <[email protected]> wrote:
>=20
> > On Tue, Feb 10, 2026 at 06:33:31PM +0100, Herve Codina wrote:
> > > fdtdump prints a message on stderr when it encounters a wrong tag and
> > > stop its processing without returning an error code.
> > >=20
> > > Having a wrong tag is really a failure. Indeed, the processing cannot
> > > continue.
> > >=20
> > > Be more strict. Stop the processing, print a message and return an
> > > error code. In other words, call die().
> > >=20
> > > Signed-off-by: Herve Codina <[email protected]> =20
> >=20
> > The intention of fdtdump is that it's a fairly crude debugging tool -
> > it will generally attempt to produce at least partial output even on a
> > bad dtb file.  If you want a polished tool for use on good dtbs, use
> > :dtc -I dtb -O dts".
>=20
> fdtdump is also interesting for tests purpose.
> I use it to check dtb outputs during tests. Those outputs are either
> generated by dtc or by libfdt.

dtc -I dts should still be usable for that purpose, no?  It seems like
the better tool for this job.

> Having an error code returned by fdtdump when it cannot parse the given d=
tb
> allows to have this test (patch 10):
> --- 8< ---
> +
> +    base_run_test wrap_fdtdump unknown_tags_can_skip.dtb unknown_tags_ca=
n_skip.dtb.out
> +    # Remove unneeded comments
> +    sed -i '/^\/\/ /d' unknown_tags_can_skip.dtb.out
> +    base_run_test check_diff unknown_tags_can_skip.dtb.out "$SRCDIR/unkn=
own_tags_can_skip.dtb.expect"
> +
> +    run_wrap_error_test $FDTDUMP unknown_tags_no_skip.dtb
> --- 8< ---
>=20
> >=20
> > That's why this didn't die() initially - the idea is if there's some
> > bogus stuff in the dtb, it might print a bunch of these warnings, but
> > eventually resynchronize on another valid tag.
>=20
> Current implementation cannot resynchronize. The parsing loop is exited
>   https://git.kernel.org/pub/scm/utils/dtc/dtc.git/tree/fdtdump.c#n150
> and the program just returns 0.

Oh, good point.  In that case this change is unequivocally an
improvement.  Applied.

> Instead of just print and exit the loop, the idea was to have a program
> error code set. Calling die() allows to print, exit the loop and exit
> the program with an error code.
>=20
> With that in mind, I can do what you prefer. Either:
>   - keep the die() call
> or
>   - discard this patch and update the test in patch 10 (i.e. remove the
>     'run_wrap_error_test $FDTDUMP unknown_tags_no_skip.dtb' line)

So, I've applied the patch, so I guess option (1).  However, I think
the test should be altered to use dtc instead of fdtdump.  I don't
really encourage fdtdump to be used for anything except ad-hoc
experimentation.

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

--+1Q0sZ7XDKS8rVEz
Content-Type: application/pgp-signature; name=signature.asc

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmdPdUACgkQzQJF27ox
2Gf1pQ/+JVlt9Rv4xLWlHmVh+c/lB9wf3rXhxOv+OHyfEE4sHYzs1e4DwKMmAsxN
p8A2q/iLVAjk1qDlaYnXckhRSFXnw5W6P5aHoJmJyzi8+rfNjOM3QHk6AxGjtjnE
jfy7ou6ZEESb09myqyEax/YxkXl5sNbqfQRp/CuCeSkvUpcbk7YEOJ3CgaUxzyeO
d18cQft83qIlqHtoC1z8ldwtTFZTa3yXsCor9locANTtdQhSyZSMXMgx6uPLyFH9
lS8caGiOyn1X0hYFzc42wKrj2bAeR0Rpd8OKjokI6qumAEPGYsm/4qzIEPgflZV6
a/x5eVeWZEABywsb0YYt3DaGZdcBpEKuGxukq2x9GjCNrXJSlutj3HzGGOyCzIu6
1jsMsROCgNNEKwHcVWto8DerEbEAxSV/0/nx7zxPO8WiJk1ldgmnmUaZVYsTEMas
EmKefrrpll7fuxdlDC+JQP7/04VfXvsSj/WtGHT7yZ8G0e6yK36N/afU1i3J+MhN
M95CnpIV/mOnC0TrLSqkIs/m2JsiME6vSHoBaRPEYrjBIuqviMEAaz1LC8myI9C4
zLyHEIBeB4XP9xwoy/oa5q/aOiybiCUmVJoz804CgGqjUKwcGEn1bv4pc/gKvW57
yGy/KOA+Xm6tWA7iCOFmlzeCsL6EI8ZvyyOwJPSb9lEP3wp6ex0=
=ifY4
-----END PGP SIGNATURE-----

--+1Q0sZ7XDKS8rVEz--