From: Danilo Krummrich <dakr@xxxxxxxxxx> Implement FwNode::is_compatible() to check whether a given match string is compatible with a FwNode. Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx> --- rust/helpers/property.c | 6 ++++++ rust/kernel/device/property.rs | 9 +++++++++ 2 files changed, 15 insertions(+) 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: -- 2.43.0