diff options
author | Danilo Krummrich <dakr@kernel.org> | 2025-04-13 19:36:59 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2025-04-17 15:21:45 +0200 |
commit | da6c47c6cb45ffb392e016631c08098ad2a6d418 (patch) | |
tree | 1ce1f64af980ee29a0cceecbd5e84e639723e9a4 /rust/kernel | |
parent | d32e4c24a7fe01195ba427c67fc15864279a3c0d (diff) |
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 <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20250413173758.12068-5-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/platform.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/rust/kernel/platform.rs b/rust/kernel/platform.rs index 9476b717c425..b1c48cd95cd6 100644 --- a/rust/kernel/platform.rs +++ b/rust/kernel/platform.rs @@ -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 impl crate::types::AlwaysRefCounted for Device { } } -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) }; |