]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: auxiliary: implement parent() for Device<Bound>
authorDanilo Krummrich <dakr@kernel.org>
Mon, 20 Oct 2025 22:34:28 +0000 (00:34 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 29 Oct 2025 17:29:32 +0000 (18:29 +0100)
Take advantage of the fact that if the auxiliary device is bound the
parent is guaranteed to be bound as well and implement a separate
parent() method for auxiliary::Device<Bound>.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/auxiliary.rs

index 497601f7473bfd7132a078788e9fbe18db963673..cc67fa5ddde30d5913806eb79c56e54f2c4aedcb 100644 (file)
@@ -217,6 +217,16 @@ impl<Ctx: device::DeviceContext> Device<Ctx> {
     }
 }
 
+impl Device<device::Bound> {
+    /// Returns a bound reference to the parent [`device::Device`].
+    pub fn parent(&self) -> &device::Device<device::Bound> {
+        let parent = (**self).parent();
+
+        // SAFETY: A bound auxiliary device always has a bound parent device.
+        unsafe { parent.as_bound() }
+    }
+}
+
 impl Device {
     /// Returns a reference to the parent [`device::Device`].
     pub fn parent(&self) -> &device::Device {