]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: auxiliary: consider auxiliary devices always have a parent
authorDanilo Krummrich <dakr@kernel.org>
Mon, 20 Oct 2025 22:34:25 +0000 (00:34 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 29 Oct 2025 17:29:32 +0000 (18:29 +0100)
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>
drivers/gpu/drm/nova/file.rs
rust/kernel/auxiliary.rs
samples/rust/rust_driver_auxiliary.rs

index 90b9d2d0ec4ae0ddaf1c8bdfbcac72537f475601..a3b7bd36792c1be597a3d4eabe2ecb58fc002560 100644 (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 {
index a6a2b23befceacb78d37986bb5e3b09a6727f8e3..e5bddb738d587fa32242cc7403ac99dede0586ac 100644 (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() }
     }
 }
 
index 0e221abe4936c894e24b6c11a6cc387cc540685b..2e9afeb83d4fa95ee7a783c2abb7ea6cc349c5ca 100644 (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();