Message ID | 20250606170341.3880941-1-igor.korotin.linux@gmail.com |
---|---|
Headers | show |
Series | rust: Add ACPI match table support for Rust drivers | expand |
On Fri Jun 6, 2025 at 7:06 PM CEST, Igor Korotin wrote: > +impl DeviceId { > + const ACPI_ID_LEN: usize = 16; > + > + /// Create a new device id from an ACPI 'id' string. > + pub const fn new(id: &'static CStr) -> Self { > + assert!(id.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes"); > + let src = id.as_bytes_with_nul(); > + // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`. > + // SAFETY: FFI type is valid to be zero-initialized. > + let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() }; This can be made safe using this series: https://lore.kernel.org/all/20250523145125.523275-1-lossin@kernel.org --- Cheers, Benno > + let mut i = 0; > + while i < src.len() { > + acpi.id[i] = src[i]; > + i += 1; > + } > + > + Self(acpi) > + } > +}
On Sun, Jun 08, 2025 at 09:48:00AM +0200, Benno Lossin wrote: > On Fri Jun 6, 2025 at 7:06 PM CEST, Igor Korotin wrote: > > +impl DeviceId { > > + const ACPI_ID_LEN: usize = 16; > > + > > + /// Create a new device id from an ACPI 'id' string. > > + pub const fn new(id: &'static CStr) -> Self { > > + assert!(id.len() <= Self::ACPI_ID_LEN, "ID exceeds 16 bytes"); > > + let src = id.as_bytes_with_nul(); > > + // Replace with `bindings::acpi_device_id::default()` once stabilized for `const`. > > + // SAFETY: FFI type is valid to be zero-initialized. > > + let mut acpi: bindings::acpi_device_id = unsafe { core::mem::zeroed() }; > > This can be made safe using this series: > > https://lore.kernel.org/all/20250523145125.523275-1-lossin@kernel.org Indeed, I did not mention this though since I think this series should not depend on the one above. They'll land through different trees and the improvement can still be made later on.
On Fri, Jun 06, 2025 at 06:09:05PM +0100, Igor Korotin wrote: > @@ -144,6 +150,7 @@ macro_rules! module_platform_driver { > /// impl platform::Driver for MyDriver { > /// type IdInfo = (); > /// const OF_ID_TABLE: Option<of::IdTable<Self::IdInfo>> = Some(&OF_TABLE); > +/// const ACPI_ID_TABLE: Option<acpi::IdTable<Self::IdInfo>> = Some(&ACPI_TABLE); This breaks the doctest. You need to define ACPI_TABLE above, just like OF_TABLE is defined above. If you enable CONFIG_RUST_KERNEL_DOCTESTS=y it will compile the doctests and run them as kunit test.