[PATCH 1/2] rust: io: document const-offset requirement for infallible accessors
Gary Guo <[email protected]>
| Newsgroups | org.kernel.vger.rust-for-linux,dev.linux.lists.driver-core,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
From: Gary Guo <[email protected]> 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 <[email protected]> --- 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