Re: [PATCH v2 1/9] rust: device: implement impl_device_context_deref!

From: Christian Schrefl
Date: Sun Apr 13 2025 - 15:38:37 EST


On 13.04.25 7:36 PM, Danilo Krummrich wrote:
> 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@xxxxxxxxx>
> Signed-off-by: Benno Lossin <benno.lossin@xxxxxxxxx>
> Signed-off-by: Danilo Krummrich <dakr@xxxxxxxxxx>
> ---
> rust/kernel/device.rs | 44 +++++++++++++++++++++++++++++++++++++++++
> rust/kernel/pci.rs | 16 +++------------
> rust/kernel/platform.rs | 17 +++-------------
> 3 files changed, 50 insertions(+), 27 deletions(-)
>
> diff --git a/rust/kernel/device.rs b/rust/kernel/device.rs
> index 21b343a1dc4d..7cb6f0fc005d 100644
> --- a/rust/kernel/device.rs
> +++ b/rust/kernel/device.rs
> @@ -235,6 +235,50 @@ impl Sealed for super::Normal {}
> impl DeviceContext for Core {}
> impl DeviceContext for Normal {}
>
> +/// # Safety
> +///
> +/// The type given as `$device` must be a transparent wrapper of a type that doesn't depend on the
> +/// generic argument of `$device`.
Maybe explicitly mention that the memory layout/representation
therefore doesn't depend on the generic arguments.

Either way:

Reviewed-by: Christian Schrefl <chrisi.schrefl@xxxxxxxxx>

Cheers
Christian