Skip to contentSkip to conversation

samples: rust_dma: construct driver data by value

PATCH New Danilo Krummrich 1 participant 1 message Nov 22

Subsystems (3)
lore
Share & tools
lore

Danilo Krummrich

author maintainer
#0 lore raw

PATCH 1/1 samples: rust_dma: construct driver data by value

Now that SGTable no longer requires pinning, construct DmaSampleData by value and replace PinnedDrop with Drop.

---
 samples/rust/rust_dma.rs | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)
samples/rust/rust_dma.rs +15 -19
index 844e137cddc8..b5d71ada8521 100644
@@ -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

Signature · 1 line
2.56.1