]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
rust: auxiliary: move parent() to impl Device
authorDanilo Krummrich <dakr@kernel.org>
Mon, 20 Oct 2025 22:34:27 +0000 (00:34 +0200)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 29 Oct 2025 17:29:32 +0000 (18:29 +0100)
Currently, the parent method is implemented for any Device<Ctx>, i.e.
any device context and returns a &device::Device<Normal>.

However, a subsequent patch will introduce

impl Device<Bound> {
    pub fn parent() -> device::Device<Bound> { ... }
}

which takes advantage of the fact that if the auxiliary device is bound
the parent is guaranteed to be bound as well.

I.e. the behavior we want is that all device contexts that dereference
to Bound, will use the implementation above, whereas the old
implementation should only be implemented for Device<Normal>.

Hence, move the current implementation.

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 8c0a2472c26adb6233fb144519cb0f5fddefc49f..497601f7473bfd7132a078788e9fbe18db963673 100644 (file)
@@ -215,15 +215,15 @@ impl<Ctx: device::DeviceContext> Device<Ctx> {
         // `struct auxiliary_device`.
         unsafe { (*self.as_raw()).id }
     }
+}
 
+impl Device {
     /// 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() }
     }
-}
 
-impl Device {
     extern "C" fn release(dev: *mut bindings::device) {
         // SAFETY: By the type invariant `self.0.as_raw` is a pointer to the `struct device`
         // embedded in `struct auxiliary_device`.