Re: [PATCH v6 2/3] rust: spi: add SPI driver abstractions

From: Mark Brown

Date: Thu Nov 12 2026 - 15:30:17 EST


> The `write()` and `read()` methods copy the data into DMA-safe bounce
> buffers before transferring, as the SPI core requires transfer buffers
> to be DMA-safe and the caller-provided slices may be located anywhere
> (e.g. on the stack). `write_then_read()` does not need this, since the
> C core's spi_write_then_read() already copies both buffers into
> internal DMA-safe bounce buffers. `write_then_read()` additionally
> validates that the sum of the two buffer lengths fits in `u32`, as the
> C core sums the two lengths as `unsigned int` when sizing its bounce
> buffer.

I do wonder if it's more sensible to go straight to the
spi_sync()/spi_async() APIs - these APIs you're implementing are all
convenience wrappers at the C level, I don't know how idiomatic they are
in Rust but if there's a more Rust native way of doing this stuff it
might be better to go with that and then arrange to map it onto the
lower level C APIs rather than deal with the C wrappers. Of course if
this is actually fairly sensible for Rust then leveraging the existing
wrappers makes sense.

--
Mark Brown <broonie@xxxxxxxxxx>