Re: [PATCH v3 4/4] samples: rust: add ACPI match table example to platform driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 06, 2025 at 06:10:33PM +0100, Igor Korotin wrote:
> Extend the Rust sample platform driver to probe using device/driver name
> +/// OF/ACPI match tables for Platform Driver implementation
> +///
> +/// The platform::Driver requires declaration of both OF_ID_TABLE and
> +/// ACPI_ID_TABLE, but if driver is not going to use either of them
> +/// it can implement one of them or both as None.
> +///
> +/// # Example:
> +///
> +/// ```ignore
> +/// impl platform::Driver for SampleDriver {
> +///     type IdInfo = ();
> +///     const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
> +///     const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None;
> +///
> +///     fn probe(
> +///         pdev: &platform::Device<Core>,
> +///         _info: Option<&Self::IdInfo>,
> +///     ) -> Result<Pin<KBox<Self>>> {
> +///         dev_dbg!(pdev.as_ref(), "Probe Rust Platform driver sample.\n");
> +///
> +///         let drvdata = KBox::new(Self { pdev: pdev.into() }, GFP_KERNEL)?;
> +///
> +///         Ok(drvdata.into())
> +///     }
> +/// }
> +/// ```

What I meant with [1] was that I think we should make this code compile and
remove everything that's not needed, i.e.:

	///```
	/// # use kernel::{acpi, device::Core, of, platform};
	///
	/// struct MyDriver;
	///
	/// impl platform::Driver for MyDriver {
	///     type IdInfo = ();
	///     const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = None;
	///     const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = None;
	///
	///     fn probe(
	///         _pdev: &platform::Device<Core>,
	///         _id_info: Option<&Self::IdInfo>,
	///     ) -> Result<Pin<KBox<Self>>> {
	///         Err(ENODEV)
	///     }
	/// }
	///```

However, given that we can't run doctests from drivers yet, we should just
remove this doctest I think. It much more belongs into rust/kernel/platform.rs
anyways (where we already have a similar one).

[1] https://lore.kernel.org/lkml/aEL0AGBZqDp1lMFe@pollux/




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux