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

Andreas Hindborg
2026-03-26T14:31:36Z

"Gary Guo" <gary@kernel.org> writes:

> From: Gary Guo <gary@garyguo.net>
>
> 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@garyguo.net>
> ---
> 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@kernel.org>

Best regards,
Andreas Hindborg