[PATCH v8 3/9] rust: device: Move property_present() to FwNode
From: Remo Senekowitsch
Date: Wed Jun 11 2025 - 06:30:26 EST
The new FwNode abstraction will be used for accessing all device
properties.
It would be 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. For this reason, property_present is removed from Device and
existing users are updated.
Signed-off-by: Remo Senekowitsch <remo@xxxxxxxxxxx>
---
drivers/cpufreq/rcpufreq_dt.rs | 3 ++-
rust/kernel/device.rs | 7 -------
rust/kernel/device/property.rs | 7 +++++++
3 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
index 94ed81644fe1c..4eb240dc9fdc8 100644
--- a/drivers/cpufreq/rcpufreq_dt.rs
+++ b/drivers/cpufreq/rcpufreq_dt.rs
@@ -20,7 +20,8 @@
/// Finds exact supply name from the OF node.
fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> {
let prop_name = CString::try_from_fmt(fmt!("{}-supply", name)).ok()?;
- dev.property_present(&prop_name)
+ dev.fwnode()?
+ .property_present(&prop_name)
.then(|| CString::try_from_fmt(fmt!("{name}")).ok())
.flatten()
}
diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
index b69f03a7f8d30..241a395d529a1 100644
--- a/rust/kernel/device.rs
+++ b/rust/kernel/device.rs
@@ -6,7 +6,6 @@
use crate::{
bindings,
- str::CStr,
types::{ARef, Opaque},
};
use core::{fmt, marker::PhantomData, ptr};
@@ -219,12 +218,6 @@ pub fn fwnode(&self) -> Option<&property::FwNode> {
// defined as a `#[repr(transparent)]` wrapper around `fwnode_handle`.
Some(unsafe { &*fwnode_handle.cast() })
}
-
- /// 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::device_property_present(self.as_raw().cast_const(), name.as_char_ptr()) }
- }
}
// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic
diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 03850b7bb8087..50c61aa056e6b 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -8,6 +8,7 @@
use crate::{
bindings,
+ str::CStr,
types::{ARef, Opaque},
};
@@ -55,6 +56,12 @@ unsafe fn from_raw(raw: *mut bindings::fwnode_handle) -> ARef<Self> {
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