]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
samples: rust: convert PCI rust sample driver to use try_access_with()
authorAlexandre Courbot <acourbot@nvidia.com>
Fri, 11 Apr 2025 12:09:39 +0000 (21:09 +0900)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 22 Apr 2025 15:21:16 +0000 (17:21 +0200)
This method limits the scope of the revocable guard and is considered
safer to use for most cases, so let's showcase it here.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20250411-try_with-v4-2-f470ac79e2e2@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
samples/rust/rust_driver_pci.rs

index 2bb260aebc9eae24db431238d7d7b48fbad788b4..9ce3a7323a1632e08f833a14c3f49a4218e9a5e6 100644 (file)
@@ -83,13 +83,12 @@ impl pci::Driver for SampleDriver {
             GFP_KERNEL,
         )?;
 
-        let bar = drvdata.bar.try_access().ok_or(ENXIO)?;
+        let res = drvdata
+            .bar
+            .try_access_with(|b| Self::testdev(info, b))
+            .ok_or(ENXIO)??;
 
-        dev_info!(
-            pdev.as_ref(),
-            "pci-testdev data-match count: {}\n",
-            Self::testdev(info, &bar)?
-        );
+        dev_info!(pdev.as_ref(), "pci-testdev data-match count: {}\n", res);
 
         Ok(drvdata.into())
     }