Re: [PATCH 3/3] samples: rust: pci: take advantage of Devres::access_with()

From: Benno Lossin
Date: Sat Apr 26 2025 - 16:31:00 EST


On Sat Apr 26, 2025 at 3:30 PM CEST, Danilo Krummrich wrote:
> For the I/O operations executed from the probe() method, take advantage
> of Devres::access_with(), avoiding the atomic check and RCU read lock
> required otherwise entirely.
>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> samples/rust/rust_driver_pci.rs | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs
> index 9ce3a7323a16..3e1569e5096e 100644
> --- a/samples/rust/rust_driver_pci.rs
> +++ b/samples/rust/rust_driver_pci.rs
> @@ -83,12 +83,12 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> Result<Pin<KBox<Self>
> GFP_KERNEL,
> )?;
>
> - 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", res);
> + let bar = drvdata.bar.access_with(pdev.as_ref())?;

Since this code might inspire other code, I don't think that we should
return `EINVAL` here (bubbled up from `access_with`). Not sure what the
correct thing here would be though...

---
Cheers,
Benno

> + dev_info!(
> + pdev.as_ref(),
> + "pci-testdev data-match count: {}\n",
> + Self::testdev(info, bar)?
> + );
>
> Ok(drvdata.into())
> }