Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Alexandre Courbot and committed by
Danilo Krummrich
0c848b3a 80e62fce

+5 -6
+5 -6
samples/rust/rust_driver_pci.rs
··· 83 83 GFP_KERNEL, 84 84 )?; 85 85 86 - let bar = drvdata.bar.try_access().ok_or(ENXIO)?; 86 + let res = drvdata 87 + .bar 88 + .try_access_with(|b| Self::testdev(info, b)) 89 + .ok_or(ENXIO)??; 87 90 88 - dev_info!( 89 - pdev.as_ref(), 90 - "pci-testdev data-match count: {}\n", 91 - Self::testdev(info, &bar)? 92 - ); 91 + dev_info!(pdev.as_ref(), "pci-testdev data-match count: {}\n", res); 93 92 94 93 Ok(drvdata.into()) 95 94 }