From: Danilo Krummrich Date: Sat, 21 Jun 2025 19:43:34 +0000 (+0200) Subject: samples: rust: pci: reset pci-testdev in unbind() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f512533b7aa780488c15e001791d1b8000ad50e;p=thirdparty%2Flinux.git samples: rust: pci: reset pci-testdev in unbind() Reset the pci-testdev when the driver is unbound from its device. Link: https://lore.kernel.org/r/20250621195118.124245-9-dakr@kernel.org Signed-off-by: Danilo Krummrich --- diff --git a/samples/rust/rust_driver_pci.rs b/samples/rust/rust_driver_pci.rs index 5c35f1414172a..606946ff4d7fd 100644 --- a/samples/rust/rust_driver_pci.rs +++ b/samples/rust/rust_driver_pci.rs @@ -18,7 +18,7 @@ impl Regs { type Bar0 = pci::Bar<{ Regs::END }>; -#[derive(Debug)] +#[derive(Copy, Clone, Debug)] struct TestIndex(u8); impl TestIndex { @@ -30,6 +30,7 @@ struct SampleDriver { pdev: ARef, #[pin] bar: Devres, + index: TestIndex, } kernel::pci_device_table!( @@ -79,6 +80,7 @@ impl pci::Driver for SampleDriver { try_pin_init!(Self { pdev: pdev.into(), bar <- pdev.iomap_region_sized::<{ Regs::END }>(0, c_str!("rust_driver_pci")), + index: *info, }), GFP_KERNEL, )?; @@ -92,6 +94,13 @@ impl pci::Driver for SampleDriver { Ok(drvdata) } + + fn unbind(pdev: &pci::Device, this: Pin<&Self>) { + if let Ok(bar) = this.bar.access(pdev.as_ref()) { + // Reset pci-testdev by writing a new test index. + bar.write8(this.index.0, Regs::TEST); + } + } } #[pinned_drop]