mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-21 23:57:36 -04:00
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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user