Re: [PATCH 2/2] spi: Add KUnit coverage for DMA mapping error paths

Mark Brown <[email protected]>
Newsgroups org.kernel.vger.linux-spi,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Wed, Aug 05, 2026 at 11:14:56PM +0800, Honghui Jiang wrote:
> Add KUnit tests for the __spi_map_msg() error paths.  The tests verify
> that mappings created before a later TX or RX failure are unwound, their
> flags are cleared, and cur_{tx,rx}_dma_dev point to the device used for
> the mapping.

The tests themselves look good but some style/integration stuff:

> --- /dev/null
> +++ b/drivers/spi/.kunitconfig
> @@ -0,0 +1,4 @@
> +CONFIG_KUNIT=y
> +CONFIG_SPI=y
> +CONFIG_SPI_MASTER=y
> +CONFIG_SPI_KUNIT_TEST=y

This also needs enabling in the KUnit defconfigs in
tools/testing/kunit/configs.

> index 05a852494..42e337c54 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -5146,3 +5146,7 @@ static int __init spi_init(void)
>   * include needing to have boardinfo data structures be much more public.
>   */
>  postcore_initcall(spi_init);
> +
> +#ifdef CONFIG_SPI_KUNIT_TEST
> +#include "tests/spi_kunit.c"
> +#endif

If this is just so we can peer into the internals it'd be better to add
a local header for internals and build as a separate translation unit
like normal rather than doing this sort of bodge.

> diff --git a/drivers/spi/tests/spi_kunit.c b/drivers/spi/tests/spi_kunit.c

Everywhere else we use - as a separator.

> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * KUnit tests for the SPI core DMA mapping error paths.
> + *

Please make the entire comment a C++ one so things look more intentional.

> + * The invariant under test:
> + *
> + *   When __spi_map_msg() returns an error, no transfer in the message may
> + *   still claim a DMA mapping.  Any transfer that was mapped before the
> + *   failure must have an empty SG table and a cleared *_sg_mapped flag.
> + *   ctlr->cur_{tx,rx}_dma_dev must identify the device used for this map,
> + *   rather than a device retained from an earlier message.

This is for one specific test, either this file should have a test
specific name with everything else namespaced to make room for further
tests or all this should go with the specific test.  This looks like a
DMA subsuite so possibly named after that?  The same applies to internal
identifiers.
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAmpzsdQACgkQJNaLcl1U
h9B/fgf9Gw8KnvDf5UwgZX9s1UqYkz3M6ZVSVZErzXGtdvpsg0K8RKC83d+/wwK/
FOsOgSrvKAE5TcPV23+w4AIeAXI21HJNHFBZqemVFdQFA0CUYQI+Vgl4H2MSiDwf
SvWDJP6SwKuK9n17s21HoD8ociqKFk0vUyDXU+GZuOgbZhjot8AI9y0wPhpYw/vc
IWC2g853XkT9WhWSZFrVgwzVRgnIXpY2QMcy89fdrS8AVCYu64lSMhdSRsv7/PKm
Wn1bKrCUf9L9ViwxcTtkUgffwRBwK3wOExqAT7GufWnZKbgGmwUGIJjklvUFZY7Q
GV7qlI00LRqIAgLJNqdEoXsuC1lSjA==
=rpC4
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.