rust: auxiliary: consider auxiliary devices always have a parent

An auxiliary device is guaranteed to always have a parent device (both
in C and Rust), hence don't return an Option<&auxiliary::Device> in
auxiliary::Device::parent().

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Danilo Krummrich
2025-10-21 00:34:25 +02:00
parent 6f61a2637a
commit 589b061975
3 changed files with 6 additions and 5 deletions

View File

@@ -28,7 +28,7 @@ impl File {
_file: &drm::File<File>,
) -> Result<u32> {
let adev = &dev.adev;
let parent = adev.parent().ok_or(ENOENT)?;
let parent = adev.parent();
let pdev: &pci::Device = parent.try_into()?;
let value = match getparam.param as u32 {

View File

@@ -215,9 +215,10 @@ impl<Ctx: device::DeviceContext> Device<Ctx> {
unsafe { (*self.as_raw()).id }
}
/// Returns a reference to the parent [`device::Device`], if any.
pub fn parent(&self) -> Option<&device::Device> {
self.as_ref().parent()
/// Returns a reference to the parent [`device::Device`].
pub fn parent(&self) -> &device::Device {
// SAFETY: A `struct auxiliary_device` always has a parent.
unsafe { self.as_ref().parent().unwrap_unchecked() }
}
}

View File

@@ -68,7 +68,7 @@ impl pci::Driver for ParentDriver {
impl ParentDriver {
fn connect(adev: &auxiliary::Device) -> Result<()> {
let parent = adev.parent().ok_or(EINVAL)?;
let parent = adev.parent();
let pdev: &pci::Device = parent.try_into()?;
let vendor = pdev.vendor_id();