diff mbox series

[v7,1/9] rust: device: implement FwNode::is_compatible()

Message ID 20250618100636.3047585-1-igor.korotin.linux@gmail.com
State New
Headers show
Series rust: Add ACPI match table support for Rust drivers | expand

Commit Message

Igor Korotin June 18, 2025, 10:06 a.m. UTC
From: Danilo Krummrich <dakr@kernel.org>

Implement FwNode::is_compatible() to check whether a given match string
is compatible with a FwNode.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/helpers/property.c        | 6 ++++++
 rust/kernel/device/property.rs | 9 +++++++++
 2 files changed, 15 insertions(+)
diff mbox series

Patch

diff --git a/rust/helpers/property.c b/rust/helpers/property.c
index 08f68e2dac4a..177b9ffd7ba4 100644
--- a/rust/helpers/property.c
+++ b/rust/helpers/property.c
@@ -6,3 +6,9 @@  void rust_helper_fwnode_handle_put(struct fwnode_handle *fwnode)
 {
 	fwnode_handle_put(fwnode);
 }
+
+bool rust_helper_fwnode_device_is_compatible(const struct fwnode_handle *fwnode,
+					     const char *match)
+{
+	return fwnode_device_is_compatible(fwnode, match);
+}
diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 838509111e57..a946bf8d5571 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -93,6 +93,15 @@  pub fn property_present(&self, name: &CStr) -> bool {
         unsafe { bindings::fwnode_property_present(self.as_raw().cast_const(), name.as_char_ptr()) }
     }
 
+    /// Return `true` if this [`FwNode`] is compatible with `match_str`, `false` otherwise.
+    pub fn is_compatible(&self, match_str: &CStr) -> bool {
+        // SAFETY:
+        // - By the invariant of `CStr`, `name.as_char_ptr()` is valid and null-terminated.
+        // - The type invariant of `Self` guarantees that `self.as_raw() is a pointer to a valid
+        //   `struct fwnode_handle`.
+        unsafe { bindings::fwnode_device_is_compatible(self.as_raw(), match_str.as_char_ptr()) }
+    }
+
     /// Returns firmware property `name` boolean value.
     pub fn property_read_bool(&self, name: &CStr) -> bool {
         // SAFETY: