diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a84a4e0..945ada9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,9 @@ jobs: toolchain: ${{ matrix.rust }} target: ${{ matrix.target }} + - if: ${{ matrix.rust=='1.65.0' }} + run: cargo update --precise 2.0.106 --package syn + - name: Install armv7 libraries if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }} run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index dbcc339..2f51f00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added async `DelayNs` implementation for `tokio`. - Added feature flag for `serial`. +### Fixed + +- Fix UB (and remove unsafe block) in handling of SpiOperation::TransferInPlace + ## [v0.4.0] - 2024-01-10 ### Changed diff --git a/Cargo.toml b/Cargo.toml index 6371f30..894de2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ sysfs_gpio = { version = "0.6.1", optional = true } i2cdev = { version = "0.6.0", optional = true } nb = "1" serialport = { version = "4.2.0", default-features = false, optional = true } -spidev = { version = "0.6.0", optional = true } +spidev = { version = "0.6.1", optional = true } nix = { version = "0.27.1", optional = true } tokio = { version = "1", default-features = false, optional = true } diff --git a/src/spi.rs b/src/spi.rs index 675506e..9854dde 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -173,9 +173,8 @@ mod embedded_hal_impl { } fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Self::Error> { - let tx = words.to_owned(); self.0 - .transfer(&mut SpidevTransfer::read_write(&tx, words)) + .transfer(&mut SpidevTransfer::read_write_in_place(words)) .map_err(|err| SPIError { err }) } @@ -214,11 +213,7 @@ mod embedded_hal_impl { } }, 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)); + transfers.push(SpidevTransfer::read_write_in_place(buf)); } SpiOperation::DelayNs(ns) => { let us = {