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: 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 <dakr@kernel.org>

+10 -1
+10 -1
samples/rust/rust_driver_pci.rs
··· 18 18 19 19 type Bar0 = pci::Bar<{ Regs::END }>; 20 20 21 - #[derive(Debug)] 21 + #[derive(Copy, Clone, Debug)] 22 22 struct TestIndex(u8); 23 23 24 24 impl TestIndex { ··· 30 30 pdev: ARef<pci::Device>, 31 31 #[pin] 32 32 bar: Devres<Bar0>, 33 + index: TestIndex, 33 34 } 34 35 35 36 kernel::pci_device_table!( ··· 80 79 try_pin_init!(Self { 81 80 pdev: pdev.into(), 82 81 bar <- pdev.iomap_region_sized::<{ Regs::END }>(0, c_str!("rust_driver_pci")), 82 + index: *info, 83 83 }), 84 84 GFP_KERNEL, 85 85 )?; ··· 93 91 ); 94 92 95 93 Ok(drvdata) 94 + } 95 + 96 + fn unbind(pdev: &pci::Device<Core>, this: Pin<&Self>) { 97 + if let Ok(bar) = this.bar.access(pdev.as_ref()) { 98 + // Reset pci-testdev by writing a new test index. 99 + bar.write8(this.index.0, Regs::TEST); 100 + } 96 101 } 97 102 } 98 103