[PATCH v6 3/9] rust: device: Add property_present() to FwNode

From: Remo Senekowitsch
Date: Sat May 24 2025 - 15:23:18 EST


The new FwNode abstraction will be used for accessing all device
properties, so it must have the property_present method.

It's possible to duplicate the methods on the device itself, but since
some of the methods on Device would have different type sigatures as
the ones on FwNode, this would only lead to inconsistency and confusion.
So, in the future, property_perent will be removed from Device. However,
there's a user about to be merged, so the method is left to make merging
easier.

Signed-off-by: Remo Senekowitsch <remo@xxxxxxxxxxx>
---
rust/kernel/device/property.rs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index ca525ed0e8e8f..71a0605b8ecad 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -6,7 +6,7 @@

use core::ptr;

-use crate::{bindings, types::Opaque};
+use crate::{bindings, str::CStr, types::Opaque};

/// A reference-counted fwnode_handle.
///
@@ -31,6 +31,12 @@ impl FwNode {
pub(crate) fn as_raw(&self) -> *mut bindings::fwnode_handle {
self.0.get()
}
+
+ /// Checks if property is present or not.
+ pub fn property_present(&self, name: &CStr) -> bool {
+ // SAFETY: By the invariant of `CStr`, `name` is null-terminated.
+ unsafe { bindings::fwnode_property_present(self.as_raw().cast_const(), name.as_char_ptr()) }
+ }
}

// SAFETY: Instances of `FwNode` are always reference-counted.
--
2.49.0