Skip to content

Commit ee889e0

Browse files
WhatAmISupposedToPutHerejannau
authored andcommitted
rust: device: Add Device::parent()
Just a wrapper over dev->parent. Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
1 parent fca9a80 commit ee889e0

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

rust/kernel/device.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ impl Device {
6565
self.0.get()
6666
}
6767

68+
/// Returns the parent device
69+
pub fn parent(&self) -> Option<ARef<Self>> {
70+
// SAFETY: pointer is valid by type invariant
71+
let pdev = unsafe { (*self.as_raw()).parent };
72+
if pdev == ptr::null_mut() {
73+
return None;
74+
}
75+
// SAFETY: if the parent pointer is not null it points to a valid device
76+
unsafe { Some(Self::get_device(pdev)) }
77+
}
78+
6879
/// Convert a raw C `struct device` pointer to a `&'a Device`.
6980
///
7081
/// # Safety

0 commit comments

Comments
 (0)