Re: [PATCH v6 2/3] rust: spi: add SPI driver abstractions
From: Shuai Liu
Date: Fri Nov 13 2026 - 04:00:22 EST
Hi Mark,
Thanks for the review.
Agreed -- mapping onto the lower-level APIs is the better design for the
Rust layer, so v7 (coming shortly) reworks the device I/O around a single
`SpiDevice::transfer()` primitive that maps onto spi_sync(): a sequence of
`Transfer`s (write, read, or full duplex) is submitted as one spi_message,
executed in order with the chip select asserted for the whole message.
Since spi_sync() requires DMA-safe transfer buffers and Rust slices may be
located anywhere (e.g. on the stack), the Rust layer owns the
bounce-buffering: every transfer buffer is copied into a kmalloc'd buffer
before submission, and received data is copied back afterwards. This
removes the dependency on the C convenience wrappers (and their helpers)
entirely, and adds full-duplex support, which the wrappers do not offer.
`write()`, `read()` and `write_then_read()` remain as thin convenience
methods built on top of `transfer()`: register-style access is what most
SPI drivers need, and keeping the familiar names makes porting C drivers
straightforward.
Best regards,
Shuai Liu