diff options
author | 2025-04-11 21:09:39 +0900 | |
---|---|---|
committer | 2025-04-22 17:21:16 +0200 | |
commit | 0c848b3adb45acc1722f94333e2a97bf1720e431 (patch) | |
tree | 3bea773d26d30c7c646b7d71332baa1ab31dded9 /samples | |
parent | rust/revocable: add try_access_with() convenience method (diff) | |
download | linux-rng-0c848b3adb45acc1722f94333e2a97bf1720e431.tar.xz linux-rng-0c848b3adb45acc1722f94333e2a97bf1720e431.zip |
samples: rust: convert PCI rust sample driver to use try_access_with()
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>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/rust/rust_driver_pci.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs index 2bb260aebc9e..9ce3a7323a16 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -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()) } |