diff options
| author | Danilo Krummrich <dakr@kernel.org> | 2026-08-30 17:40:34 +0200 |
|---|---|---|
| committer | Danilo Krummrich <dakr@kernel.org> | 2026-09-04 17:58:47 +0200 |
| commit | bed87375f90f44cd2f9fe804a469274127d38593 (patch) | |
| tree | e23c4f4730378ccbef6ebbe48992bdf5efba340c /samples | |
| parent | c3d4fd0e9d27651d2daf223fa72128633a082b05 (diff) | |
| download | linux-bed87375f90f44cd2f9fe804a469274127d38593.tar.gz linux-bed87375f90f44cd2f9fe804a469274127d38593.zip | |
rust: dma: tie Coherent and CoherentBox to the device's bound lifetime
Add a lifetime parameter to Coherent and CoherentBox that ties the DMA
allocation to the device's bound scope, ensuring it is freed before the
device is unbound.
DMA allocations carry device resources (e.g. IOMMU mappings) that must
not outlive the device's bound lifetime. Without a lifetime parameter,
there was no compile-time enforcement that a Coherent or CoherentBox is
dropped before the device is unbound.
Propagate the new lifetime parameter through all users.
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260830193824.471089-5-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/rust/rust_dma.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs index 0fac9d4ae566..ffb693544673 100644 --- a/samples/rust/rust_dma.rs +++ b/samples/rust/rust_dma.rs @@ -34,7 +34,7 @@ struct DmaSampleDriver; #[pin_data(PinnedDrop)] struct DmaSampleData<'bound> { pdev: &'bound pci::Device<Bound>, - ca: Coherent<[MyStruct]>, + ca: Coherent<'bound, [MyStruct]>, #[pin] sgt: SGTable<Owned<VVec<u8>>>, } @@ -86,7 +86,7 @@ impl pci::Driver for DmaSampleDriver { // SAFETY: There are no concurrent calls to DMA allocation and mapping primitives. unsafe { pdev.dma_set_mask_and_coherent(mask)? }; - let ca: Coherent<[MyStruct]> = + let ca: Coherent<'_, [MyStruct]> = Coherent::zeroed_slice(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?; for (i, value) in TEST_VALUES.into_iter().enumerate() { |
