Commit da6c47c6 authored by Danilo Krummrich's avatar Danilo Krummrich
Browse files

rust: platform: preserve device context in AsRef



Since device::Device has a generic over its context, preserve this
device context in AsRef.

For instance, when calling platform::Device<Core> the new AsRef
implementation returns device::Device<Core>.

Reviewed-by: default avatarBenno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20250413173758.12068-5-dakr@kernel.org


Signed-off-by: default avatarDanilo Krummrich <dakr@kernel.org>
parent d32e4c24
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ pub struct Device<Ctx: device::DeviceContext = device::Normal>(
    PhantomData<Ctx>,
);

impl Device {
impl<Ctx: device::DeviceContext> Device<Ctx> {
    fn as_raw(&self) -> *mut bindings::platform_device {
        self.0.get()
    }
@@ -207,8 +207,8 @@ unsafe fn dec_ref(obj: NonNull<Self>) {
    }
}

impl AsRef<device::Device> for Device {
    fn as_ref(&self) -> &device::Device {
impl<Ctx: device::DeviceContext> AsRef<device::Device<Ctx>> for Device<Ctx> {
    fn as_ref(&self) -> &device::Device<Ctx> {
        // SAFETY: By the type invariant of `Self`, `self.as_raw()` is a pointer to a valid
        // `struct platform_device`.
        let dev = unsafe { addr_of_mut!((*self.as_raw()).dev) };