Re: [PATCH] rust: ACPI: fix missing match data for PRP0001

Danilo Krummrich
2026-04-04T22:07:35Z

On Wed Apr 1, 2026 at 4:06 PM CEST, Markus Probst wrote:
> @@ -866,6 +866,7 @@ static bool acpi_of_match_device(const struct acpi_device *adev,
>
> return false;
> }
> +EXPORT_SYMBOL_GPL(acpi_of_match_device);

We only use this from Rust core code, so I'd rather avoid exporting this symbol.

We can work around the compiler inlining this into modules with this indirection
instead:

+#[inline(never)]
+#[allow(clippy::missing_safety_doc)]
+#[must_use]
+unsafe fn acpi_of_match_device(
+ adev: *const bindings::acpi_device,
+ of_match_table: *const bindings::of_device_id,
+ of_id: *mut *const bindings::of_device_id,
+) -> bool {
+ // SAFETY: Safety requirements are the same as `bindings::acpi_device_id`.
+ unsafe { bindings::acpi_of_match_device(adev, of_match_table, of_id) }
+}
+
/// The bus independent adapter to match a drivers and a devices.
///
/// This trait should be implemented by the bus specific adapter, which represents the connection
@@ -373,7 +385,7 @@ fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
// - `adev` is a valid pointer to `acpi_device` or is null. It is guaranteed to be
// valid as long as `dev` is alive.
// - `table` has static lifetime, hence it's valid for read.
- if unsafe { bindings::acpi_of_match_device(adev, table.as_ptr(), &raw mut raw_id) } {
+ if unsafe { acpi_of_match_device(adev, table.as_ptr(), &raw mut raw_id) } {
// SAFETY:
// - the function returns true, therefore `raw_id` has been set to a pointer to a
// valid `of_device_id`.

Please see also [1].

[1] https://patch.msgid.link/20260213220718.82835-6-dakr@kernel.org

> @@ -329,35 +334,60 @@ fn acpi_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
> ///
> /// If this returns `None`, it means there is no match with an entry in the [`of::IdTable`].
> fn of_id_info(dev: &device::Device) -> Option<&'static Self::IdInfo> {
> - #[cfg(not(CONFIG_OF))]
> + let table = Self::of_id_table()?;
> +
> + #[cfg(not(any(CONFIG_OF, CONFIG_ACPI)))]
> {
> - let _ = dev;
> - None
> + let _ = (dev, table);
> }
>
> #[cfg(CONFIG_OF)]
> {
> - let table = Self::of_id_table()?;
> -
> // SAFETY:
> // - `table` has static lifetime, hence it's valid for read,
> // - `dev` is guaranteed to be valid while it's alive, and so is `dev.as_raw()`.
> let raw_id = unsafe { bindings::of_match_device(table.as_ptr(), dev.as_raw()) };
>
> - if raw_id.is_null() {
> - None
> - } else {
> + if !raw_id.is_null() {
> // SAFETY: `DeviceId` is a `#[repr(transparent)]` wrapper of `struct of_device_id`
> // and does not add additional invariants, so it's safe to transmute.
> let id = unsafe { &*raw_id.cast::<of::DeviceId>() };
>
> - Some(
> - table.info(<of::DeviceId as crate::device_id::RawDeviceIdIndex>::index(
> - id,
> - )),
> - )
> + return Some(table.info(
> + <of::DeviceId as crate::device_id::RawDeviceIdIndex>::index(id),
> + ));
> + }
> + }
> +
> + #[cfg(CONFIG_ACPI)]
> + {
> + let mut raw_id = ptr::null();
> +
> + // SAFETY: `dev.fwnode().as_raw()` is a pointer to a valid `fwnode_handle`. A null
> + // pointer will be passed through the function.
> + let adev = unsafe {
> + bindings::to_acpi_device_node(dev.fwnode().map_or(ptr::null_mut(), FwNode::as_raw))
> + };

Please only pass the final pointer to bindings::to_acpi_device_node() to keep
unsafe {} sections as short as possible.

> +
> + // SAFETY:
> + // - `adev` is a valid pointer to `acpi_device` or is null. It is guaranteed to be
> + // valid as long as `dev` is alive.
> + // - `table` has static lifetime, hence it's valid for read.
> + if unsafe { bindings::acpi_of_match_device(adev, table.as_ptr(), &raw mut raw_id) } {
> + // SAFETY:
> + // - the function returns true, therefore `raw_id` has been set to a pointer to a
> + // valid `of_device_id`.
> + // - `DeviceId` is a `#[repr(transparent)]` wrapper of `struct of_device_id`
> + // and does not add additional invariants, so it's safe to transmute.
> + let id = unsafe { &*raw_id.cast::<of::DeviceId>() };
> +
> + return Some(table.info(
> + <of::DeviceId as crate::device_id::RawDeviceIdIndex>::index(id),
> + ));
> }
> }
> +
> + None
> }