Skip to content

Commit da6c47c

Browse files
author
Danilo Krummrich
committed
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: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent d32e4c2 commit da6c47c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

rust/kernel/platform.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub struct Device<Ctx: device::DeviceContext = device::Normal>(
183183
PhantomData<Ctx>,
184184
);
185185

186-
impl Device {
186+
impl<Ctx: device::DeviceContext> Device<Ctx> {
187187
fn as_raw(&self) -> *mut bindings::platform_device {
188188
self.0.get()
189189
}
@@ -207,8 +207,8 @@ unsafe impl crate::types::AlwaysRefCounted for Device {
207207
}
208208
}
209209

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

0 commit comments

Comments
 (0)