Skip to content

Commit 53de4fb

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 aa28ea2 commit 53de4fb

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
@@ -64,6 +64,17 @@ impl Device {
6464
self.0.get()
6565
}
6666

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

0 commit comments

Comments
 (0)