Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
9 changes: 2 additions & 7 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down Expand Up @@ -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 = {
Expand Down