Skip to content

Commit

Permalink
rust: dma: add Send implementation for CoherentAllocation
Browse files Browse the repository at this point in the history
Stephen found a future build failure in linux-next [1]:

    error[E0277]: `*mut MyStruct` cannot be sent between threads safely
      --> samples/rust/rust_dma.rs:47:22
       |
    47 | impl pci::Driver for DmaSampleDriver {
       |                      ^^^^^^^^^^^^^^^ `*mut MyStruct` cannot be sent between threads safely

It is caused by the interaction between commit 935e1d9 ("rust: pci:
require Send for Driver trait implementers") from the driver-core tree,
which fixes a missing concurrency requirement, and commit 9901add
("samples: rust: add Rust dma test sample driver") which adds a sample
that does not satisfy that requirement.

Add a `Send` implementation to `CoherentAllocation`, which allows the
sample (and other future users) to satisfy it.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/linux-next/20250324215702.1515ba92@canb.auug.org.au/ [1]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250324174048.1075597-1-ojeda@kernel.org
[ Added number to Closes. Fix typo spotted by Boqun. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
Danilo Krummrich authored and Miguel Ojeda committed Mar 24, 2025
1 parent a0b539a commit 28bb48c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rust/kernel/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ impl<T: AsBytes + FromBytes> Drop for CoherentAllocation<T> {
}
}

// SAFETY: It is safe to send a `CoherentAllocation` to another thread if `T`
// can be sent to another thread.
unsafe impl<T: AsBytes + FromBytes + Send> Send for CoherentAllocation<T> {}

/// Reads a field of an item from an allocated region of structs.
///
/// # Examples
Expand Down

0 comments on commit 28bb48c

Please sign in to comment.