Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: device: Move property_present() to FwNode

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>

authored by

Remo Senekowitsch and committed by
Danilo Krummrich
d3393e84 658f23b5

+9 -8
+2 -1
drivers/cpufreq/rcpufreq_dt.rs
··· 20 20 /// Finds exact supply name from the OF node. 21 21 fn find_supply_name_exact(dev: &Device, name: &str) -> Option<CString> { 22 22 let prop_name = CString::try_from_fmt(fmt!("{}-supply", name)).ok()?; 23 - dev.property_present(&prop_name) 23 + dev.fwnode()? 24 + .property_present(&prop_name) 24 25 .then(|| CString::try_from_fmt(fmt!("{name}")).ok()) 25 26 .flatten() 26 27 }
-7
rust/kernel/device.rs
··· 6 6 7 7 use crate::{ 8 8 bindings, 9 - str::CStr, 10 9 types::{ARef, Opaque}, 11 10 }; 12 11 use core::{fmt, marker::PhantomData, ptr}; ··· 217 218 // `struct fwnode_handle*` to a `*const FwNode` because `FwNode` is 218 219 // defined as a `#[repr(transparent)]` wrapper around `fwnode_handle`. 219 220 Some(unsafe { &*fwnode_handle.cast() }) 220 - } 221 - 222 - /// Checks if property is present or not. 223 - pub fn property_present(&self, name: &CStr) -> bool { 224 - // SAFETY: By the invariant of `CStr`, `name` is null-terminated. 225 - unsafe { bindings::device_property_present(self.as_raw().cast_const(), name.as_char_ptr()) } 226 221 } 227 222 } 228 223
+7
rust/kernel/device/property.rs
··· 8 8 9 9 use crate::{ 10 10 bindings, 11 + str::CStr, 11 12 types::{ARef, Opaque}, 12 13 }; 13 14 ··· 56 55 /// Obtain the raw `struct fwnode_handle *`. 57 56 pub(crate) fn as_raw(&self) -> *mut bindings::fwnode_handle { 58 57 self.0.get() 58 + } 59 + 60 + /// Checks if property is present or not. 61 + pub fn property_present(&self, name: &CStr) -> bool { 62 + // SAFETY: By the invariant of `CStr`, `name` is null-terminated. 63 + unsafe { bindings::fwnode_property_present(self.as_raw().cast_const(), name.as_char_ptr()) } 59 64 } 60 65 } 61 66