From: Gary Guo <gary@kernel.org>
To: "Danilo Krummrich" <dakr@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>
Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] rust: io: document const-offset requirement for infallible accessors
Date: Thu, 16 Jul 2026 15:25:43 +0100 [thread overview]
Message-ID: <20260716142545.3622278-1-gary@kernel.org> (raw)
From: Gary Guo <gary@garyguo.net>
Due to the usage of `build_assert!` for address validity checking, these
accessors want constant offsets. Non-constant offsets can work but it
depend on compiler optimization levels, so it should be avoided.
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/kernel/io.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
index 95f46bb75f9e..a38c20ba3d23 100644
--- a/rust/kernel/io.rs
+++ b/rust/kernel/io.rs
@@ -721,6 +721,8 @@ fn try_write64(self, value: u64, offset: usize) -> Result
}
/// Infallible 8-bit read with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn read8(self, offset: usize) -> u8
where
@@ -731,6 +733,8 @@ fn read8(self, offset: usize) -> u8
}
/// Infallible 16-bit read with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn read16(self, offset: usize) -> u16
where
@@ -741,6 +745,8 @@ fn read16(self, offset: usize) -> u16
}
/// Infallible 32-bit read with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn read32(self, offset: usize) -> u32
where
@@ -751,6 +757,8 @@ fn read32(self, offset: usize) -> u32
}
/// Infallible 64-bit read with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn read64(self, offset: usize) -> u64
where
@@ -761,6 +769,8 @@ fn read64(self, offset: usize) -> u64
}
/// Infallible 8-bit write with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn write8(self, value: u8, offset: usize)
where
@@ -771,6 +781,8 @@ fn write8(self, value: u8, offset: usize)
}
/// Infallible 16-bit write with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn write16(self, value: u16, offset: usize)
where
@@ -781,6 +793,8 @@ fn write16(self, value: u16, offset: usize)
}
/// Infallible 32-bit write with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn write32(self, value: u32, offset: usize)
where
@@ -791,6 +805,8 @@ fn write32(self, value: u32, offset: usize)
}
/// Infallible 64-bit write with compile-time bounds check.
+ ///
+ /// `offset` should be constant.
#[inline(always)]
fn write64(self, value: u64, offset: usize)
where
base-commit: b8809969e1d7a591e0f49dd464a5d04b3cf02ab1
--
2.54.0
next reply other threads:[~2026-07-16 14:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 14:25 Gary Guo [this message]
2026-07-16 14:25 ` [PATCH 2/2] rust: drm: fix non-const `read8` in unit test Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260716142545.3622278-1-gary@kernel.org \
--to=gary@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.