Commit 0c848b3a authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Danilo Krummrich
Browse files

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: default avatarBenno Lossin <benno.lossin@proton.me>
Signed-off-by: default avatarAlexandre Courbot <acourbot@nvidia.com>
Acked-by: default avatarMiguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20250411-try_with-v4-2-f470ac79e2e2@nvidia.com


Signed-off-by: default avatarDanilo Krummrich <dakr@kernel.org>
parent 80e62fce
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -83,13 +83,12 @@ fn probe(pdev: &pci::Device<Core>, info: &Self::IdInfo) -> Result<Pin<KBox<Self>
            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())
    }