]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: device: Move property_present() to FwNode
authorRemo Senekowitsch <remo@buenzli.dev>
Wed, 11 Jun 2025 10:29:02 +0000 (12:29 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Thu, 12 Jun 2025 22:58:52 +0000 (00:58 +0200)
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.

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Remo Senekowitsch <remo@buenzli.dev>
Link: https://lore.kernel.org/r/20250611102908.212514-4-remo@buenzli.dev
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/cpufreq/rcpufreq_dt.rs
rust/kernel/device.rs
rust/kernel/device/property.rs

index 94ed81644fe1c3f8a0240dede2299102a2118e73..4eb240dc9fdc807626fdf03fb12528c120b8123a 100644 (file)
@@ -20,7 +20,8 @@ use kernel::{
 /// 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()
 }
index 48d45af1cfb23b44801cc5570ad7bb6af83c3c67..665f5ceadecca38de49ba013a0b9fb0fbcc8ce28 100644 (file)
@@ -6,7 +6,6 @@
 
 use crate::{
     bindings,
-    str::CStr,
     types::{ARef, Opaque},
 };
 use core::{fmt, marker::PhantomData, ptr};
@@ -219,12 +218,6 @@ impl<Ctx: DeviceContext> Device<Ctx> {
         // 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
index 82ef54b54f1882f1a1d19f2fd6e391c89c52ec95..ed17b20f7ae11f2bc9d1412812cf819521a54459 100644 (file)
@@ -8,6 +8,7 @@ use core::ptr;
 
 use crate::{
     bindings,
+    str::CStr,
     types::{ARef, Opaque},
 };
 
@@ -56,6 +57,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.