diff options
author | Danilo Krummrich <dakr@kernel.org> | 2025-04-13 19:36:56 +0200 |
---|---|---|
committer | Danilo Krummrich <dakr@kernel.org> | 2025-04-17 15:21:11 +0200 |
commit | cb271c2edfd0ab7204d5ef3c9d5ae9a0710f5bf2 (patch) | |
tree | 953fdf1e4af2226572ed8db14f3a471da3aadd82 /rust/kernel/pci.rs | |
parent | 0af2f6be1b4281385b618cb86ad946eded089ac8 (diff) |
rust: device: implement impl_device_context_deref!
The Deref hierarchy for device context generics is the same for every
(bus specific) device.
Implement those with a generic macro to avoid duplicated boiler plate
code and ensure the correct Deref hierarchy for every device
implementation.
Co-developed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Link: https://lore.kernel.org/r/20250413173758.12068-2-dakr@kernel.org
[ Add missing `::` prefix in macros. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Diffstat (limited to 'rust/kernel/pci.rs')
-rw-r--r-- | rust/kernel/pci.rs | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/rust/kernel/pci.rs b/rust/kernel/pci.rs index c97d6d470b28..8474608e7a90 100644 --- a/rust/kernel/pci.rs +++ b/rust/kernel/pci.rs @@ -422,19 +422,9 @@ impl Device<device::Core> { } } -impl Deref for Device<device::Core> { - type Target = Device; - - fn deref(&self) -> &Self::Target { - let ptr: *const Self = self; - - // CAST: `Device<Ctx>` is a transparent wrapper of `Opaque<bindings::pci_dev>`. - let ptr = ptr.cast::<Device>(); - - // SAFETY: `ptr` was derived from `&self`. - unsafe { &*ptr } - } -} +// SAFETY: `Device` is a transparent wrapper of a type that doesn't depend on `Device`'s generic +// argument. +kernel::impl_device_context_deref!(unsafe { Device }); impl From<&Device<device::Core>> for ARef<Device> { fn from(dev: &Device<device::Core>) -> Self { |