rust-embedded/linux-embedded-hal

SPI `TransferInPlace` operation is unsound.

Closed this issue · 2 comments

The implementation for the TransferInPlace operation violates the aliasing rule by creating an immutable reference from a mutable one, but keeping both.

SpiOperation::TransferInPlace(buf) => {
let tx = unsafe {
let p = buf.as_ptr();
std::slice::from_raw_parts(p, buf.len())
};
transfers.push(SpidevTransfer::read_write(tx, buf));
}

There needs to be a corresponding method for SpidevTransfer, e.g. read_write_in_place.

I definitely concur with this being UB! Would be great to have this fixed, we've notified @sirhcel, who will be taking a peak when possible :)

This could be fixed with #123, but needs a release of spidev first, to implement the required read_write_in_place function.
(with rust-embedded/rust-spidev#49)