Linux driver-core infrastructure
 help / color / mirror / Atom feed
* [PATCH 1/2] rust: io: document const-offset requirement for infallible accessors
@ 2026-07-16 14:25 Gary Guo
  2026-07-16 14:25 ` [PATCH 2/2] rust: drm: fix non-const `read8` in unit test Gary Guo
  0 siblings, 1 reply; 2+ messages in thread
From: Gary Guo @ 2026-07-16 14:25 UTC (permalink / raw)
  To: Danilo Krummrich, Alice Ryhl, Daniel Almeida, Miguel Ojeda,
	Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Trevor Gross, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan
  Cc: driver-core, rust-for-linux, linux-kernel

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-16 14:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 14:25 [PATCH 1/2] rust: io: document const-offset requirement for infallible accessors Gary Guo
2026-07-16 14:25 ` [PATCH 2/2] rust: drm: fix non-const `read8` in unit test Gary Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox