* [PATCH] samples: rust_dma: construct driver data by value
@ 2026-11-22 17:15 Danilo Krummrich
0 siblings, 0 replies; only message in thread
From: Danilo Krummrich @ 2026-11-22 17:15 UTC (permalink / raw)
To: dakr, abdiel.janulgue, daniel.almeida, robin.murphy, a.hindborg,
ojeda, boqun, gary, bjorn3_gh, lossin, aliceryhl, tmgross,
tamird, acourbot, work
Cc: driver-core, rust-for-linux, linux-kernel
Now that SGTable no longer requires pinning, construct DmaSampleData by
value and replace PinnedDrop with Drop.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
samples/rust/rust_dma.rs | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/samples/rust/rust_dma.rs b/samples/rust/rust_dma.rs
index 844e137cddc8..b5d71ada8521 100644
--- a/samples/rust/rust_dma.rs
+++ b/samples/rust/rust_dma.rs
@@ -31,7 +31,6 @@
struct DmaSampleDriver;
-#[pin_data(PinnedDrop)]
struct DmaSampleData<'bound> {
pdev: &'bound pci::Device<Bound>,
ca: Coherent<'bound, [MyStruct]>,
@@ -77,28 +76,26 @@ fn probe<'bound>(
pdev: &'bound pci::Device<Core<'_>>,
_info: Option<&'bound Self::IdInfo>,
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
- pin_init::pin_init_scope(move || {
- dev_info!(pdev, "Probe DMA test driver.\n");
+ dev_info!(pdev, "Probe DMA test driver.\n");
- let mask = DmaMask::new::<64>();
+ let mask = DmaMask::new::<64>();
- // SAFETY: There are no concurrent calls to DMA allocation and mapping primitives.
- unsafe { pdev.dma_set_mask_and_coherent(mask)? };
+ // SAFETY: There are no concurrent calls to DMA allocation and mapping primitives.
+ unsafe { pdev.dma_set_mask_and_coherent(mask)? };
- let ca: Coherent<'_, [MyStruct]> =
- Coherent::zeroed_slice(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?;
+ let ca: Coherent<'_, [MyStruct]> =
+ Coherent::zeroed_slice(pdev.as_ref(), TEST_VALUES.len(), GFP_KERNEL)?;
- for (i, value) in TEST_VALUES.into_iter().enumerate() {
- io_project!(ca, [panic: i]).copy_write(MyStruct::new(value.0, value.1));
- }
+ for (i, value) in TEST_VALUES.into_iter().enumerate() {
+ io_project!(ca, [panic: i]).copy_write(MyStruct::new(value.0, value.1));
+ }
- let size = 4 * page::PAGE_SIZE;
- let pages = VVec::with_capacity(size, GFP_KERNEL)?;
+ let size = 4 * page::PAGE_SIZE;
+ let pages = VVec::with_capacity(size, GFP_KERNEL)?;
- let sgt = SGTable::new(pdev.as_ref(), pages, DataDirection::ToDevice, GFP_KERNEL)?;
+ let sgt = SGTable::new(pdev.as_ref(), pages, DataDirection::ToDevice, GFP_KERNEL)?;
- Ok(try_pin_init!(Self::Data { pdev, ca, sgt }))
- })
+ Ok(Self::Data { pdev, ca, sgt })
}
}
@@ -114,9 +111,8 @@ fn check_dma(&self) {
}
}
-#[pinned_drop]
-impl PinnedDrop for DmaSampleData<'_> {
- fn drop(self: Pin<&mut Self>) {
+impl Drop for DmaSampleData<'_> {
+ fn drop(&mut self) {
dev_info!(self.pdev, "Unload DMA test driver.\n");
self.check_dma();
base-commit: 0504beeb95d1be229d7cce00a12033468f5ac50b
--
2.56.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-22 17:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 17:15 [PATCH] samples: rust_dma: construct driver data by value Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®