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: Enable accessing the FwNode of a Device

Subsequent patches will add methods for reading properties to FwNode.
The first step to accessing these methods will be to access the "root"
FwNode of a Device.

Add the method `fwnode` to `Device`.

Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Signed-off-by: Remo Senekowitsch <remo@buenzli.dev>
Link: https://lore.kernel.org/r/20250611102908.212514-3-remo@buenzli.dev
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

authored by

Remo Senekowitsch and committed by
Danilo Krummrich
658f23b5 a2801aff

+15
+15
rust/kernel/device.rs
··· 205 205 }; 206 206 } 207 207 208 + /// Obtain the [`FwNode`](property::FwNode) corresponding to this [`Device`]. 209 + pub fn fwnode(&self) -> Option<&property::FwNode> { 210 + // SAFETY: `self` is valid. 211 + let fwnode_handle = unsafe { bindings::__dev_fwnode(self.as_raw()) }; 212 + if fwnode_handle.is_null() { 213 + return None; 214 + } 215 + // SAFETY: `fwnode_handle` is valid. Its lifetime is tied to `&self`. We 216 + // return a reference instead of an `ARef<FwNode>` because `dev_fwnode()` 217 + // doesn't increment the refcount. It is safe to cast from a 218 + // `struct fwnode_handle*` to a `*const FwNode` because `FwNode` is 219 + // defined as a `#[repr(transparent)]` wrapper around `fwnode_handle`. 220 + Some(unsafe { &*fwnode_handle.cast() }) 221 + } 222 + 208 223 /// Checks if property is present or not. 209 224 pub fn property_present(&self, name: &CStr) -> bool { 210 225 // SAFETY: By the invariant of `CStr`, `name` is null-terminated.