Re: [PATCH 4/8] rust: io: add view type

From: Andreas Hindborg

Date: Thu Mar 26 2026 - 10:42:58 EST


"Gary Guo" <gary@xxxxxxxxxx> writes:

> From: Gary Guo <gary@xxxxxxxxxxx>
>
> The view may be created statically via I/O projection using `io_project!()`
> macro to perform compile-time checks, or created by type-casting an
> existing view type with `try_cast()` function, where the size and alignment
> checks are performed at runtime.
>
> Signed-off-by: Gary Guo <gary@xxxxxxxxxxx>
> ---
> rust/kernel/io.rs | 147 +++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 146 insertions(+), 1 deletion(-)
>
> diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
> index 72902a4a343d..8166e47f1381 100644
> --- a/rust/kernel/io.rs
> +++ b/rust/kernel/io.rs
> @@ -7,7 +7,11 @@
> use crate::{
> bindings,
> prelude::*,
> - ptr::KnownSize, //
> + ptr::KnownSize,
> + transmute::{
> + AsBytes,
> + FromBytes, //
> + }, //
> };
>
> pub mod mem;
> @@ -296,6 +300,13 @@ pub trait Io {
> /// Type of this I/O region. For untyped I/O regions, [`Region`] type can be used.
> type Type: ?Sized + KnownSize;
>
> + /// Get a [`View`] covering the entire region.
> + #[inline]
> + fn as_view(&self) -> View<'_, Self, Self::Type> {
> + // SAFETY: Trivially satisfied.

What might be trivial to you is not necessarily obvious to others.
Please explain why we are satisfying safety requirements.

Otherwise looks good, with the above fixed, please add:

Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>

Best regards,
Andreas Hindborg