rust: driver: decouple driver private data from driver type

Add a type Data<'bound> associated type to all bus driver traits,
decoupling the driver's bus device private data type from the driver
struct itself.

In the context of adding a 'bound lifetime, making this an associated
type has the advantage that it allows us to avoid a driver trait global
lifetime and it avoids the need for ForLt for bus device private data;
both of which make the subsequent implementation by buses much simpler.

All existing drivers and doc examples set type Data = Self to preserve
the current behavior.

Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20260525202921.124698-5-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Danilo Krummrich
2026-05-25 22:20:51 +02:00
parent c8a43666ba
commit 7fdffdda63
22 changed files with 98 additions and 55 deletions

View File

@@ -117,6 +117,7 @@ fn from_str(s: &str) -> Result<Self> {
impl platform::Driver for RustDebugFs {
type IdInfo = ();
type Data = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);

View File

@@ -58,6 +58,7 @@ unsafe impl kernel::transmute::FromBytes for MyStruct {}
impl pci::Driver for DmaSampleDriver {
type IdInfo = ();
type Data = Self;
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;
fn probe(pdev: &pci::Device<Core>, _info: &Self::IdInfo) -> impl PinInit<Self, Error> {

View File

@@ -31,6 +31,7 @@
impl auxiliary::Driver for AuxiliaryDriver {
type IdInfo = ();
type Data = Self;
const ID_TABLE: auxiliary::IdTable<Self::IdInfo> = &AUX_TABLE;
@@ -65,6 +66,7 @@ struct ParentDriver {
impl pci::Driver for ParentDriver {
type IdInfo = ();
type Data = Self;
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;

View File

@@ -35,6 +35,7 @@
impl i2c::Driver for SampleDriver {
type IdInfo = u32;
type Data = Self;
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);
const I2C_ID_TABLE: Option<i2c::IdTable<Self::IdInfo>> = Some(&I2C_TABLE);

View File

@@ -140,6 +140,7 @@ fn config_space(pdev: &pci::Device<Bound>) {
impl pci::Driver for SampleDriver {
type IdInfo = TestIndex;
type Data = Self;
const ID_TABLE: pci::IdTable<Self::IdInfo> = &PCI_TABLE;

View File

@@ -101,6 +101,7 @@ struct SampleDriver {
impl platform::Driver for SampleDriver {
type IdInfo = Info;
type Data = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);

View File

@@ -26,6 +26,7 @@ struct SampleDriver {
impl usb::Driver for SampleDriver {
type IdInfo = ();
type Data = Self;
const ID_TABLE: usb::IdTable<Self::IdInfo> = &USB_TABLE;
fn probe(

View File

@@ -106,6 +106,7 @@ struct SampleDriver {
impl platform::Driver for SampleDriver {
type IdInfo = ();
type Data = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);

View File

@@ -37,6 +37,7 @@ struct SampleSocDriver {
impl platform::Driver for SampleSocDriver {
type IdInfo = ();
type Data = Self;
const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE);
const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE);