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 a8d0219..f7a3590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [v0.4.1] - 2025-11-06 + +### Fixed + +- Fix UB (and remove unsafe block) in handling of SpiOperation::TransferInPlace + ## [v0.4.0] - 2024-01-10 ### Changed @@ -152,7 +158,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Initial release -[Unreleased]: https://github.com/rust-embedded/linux-embedded-hal/compare/v0.4.0...HEAD +[Unreleased]: https://github.com/rust-embedded/linux-embedded-hal/compare/v0.4.1...HEAD +[v0.4.1]: https://github.com/rust-embedded/linux-embedded-hal/compare/v0.4.0...v0.4.1 [v0.4.0]: https://github.com/rust-embedded/linux-embedded-hal/compare/v0.4.0-alpha.4...v0.4.0 [v0.4.0-alpha.4]: https://github.com/rust-embedded/linux-embedded-hal/compare/v0.4.0-alpha.3...v0.4.0-alpha.4 [v0.4.0-alpha.3]: https://github.com/rust-embedded/linux-embedded-hal/compare/v0.4.0-alpha.2...v0.4.0-alpha.3 diff --git a/Cargo.toml b/Cargo.toml index ea35bed..054d3b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ keywords = ["Linux", "hal"] license = "MIT OR Apache-2.0" name = "linux-embedded-hal" repository = "https://github.com/rust-embedded/linux-embedded-hal" -version = "0.4.0" +version = "0.4.1" edition = "2018" [features] @@ -29,7 +29,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 } -spidev = { version = "0.6.0", optional = true } +spidev = { version = "0.6.1", optional = true } nix = "0.27.1" [dev-dependencies] 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 = {