[PATCH] rust: io: fix Mmio::from_raw safety docs
From: Yilin Chen
Date: Tue Jul 07 2026 - 12:07:15 EST
MmioRaw can be constructed safely. It also explicitly does not guarantee
that the represented MMIO range exists or is mapped.
The unsafe precondition for Mmio::from_raw() therefore belongs to the
range described by the MmioRaw argument, not to nonexistent addr and
maxsize parameters. Document that this range must stay valid for the
returned reference.
Assisted-by: Codex:GPT-5
Signed-off-by: Yilin Chen <1479826151@xxxxxx>
---
rust/kernel/io.rs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
index fcc7678fd..59b276a04 100644
--- a/rust/kernel/io.rs
+++ b/rust/kernel/io.rs
@@ -780,8 +780,9 @@ impl<const SIZE: usize> Mmio<SIZE> {
///
/// # Safety
///
- /// Callers must ensure that `addr` is the start of a valid I/O mapped memory region of size
- /// `maxsize`.
+ /// Callers must ensure that the MMIO range described by `raw.addr()` and
+ /// `raw.maxsize()` is a valid I/O mapped memory region for the entire lifetime
+ /// of the returned reference.
pub unsafe fn from_raw(raw: &MmioRaw<SIZE>) -> &Self {
// SAFETY: `Mmio` is a transparent wrapper around `MmioRaw`.
unsafe { &*core::ptr::from_ref(raw).cast() }
--
2.25.1