The primitive accessors, `read8` to `write64` and their `try_` variants,
pass their offset as an `IoLoc` to the generic `read`, `write`,
`try_read` and `try_write`, which project the view to that location and
then call `read_val` or `write_val`. Commit 147b41ba23d6 ("rust: io: use
generic read/write accessors for primitive accesses") made them do so to
reduce the number of unsafe blocks.
Since commit e0454ec1220c ("rust: io: use view types instead of
addresses for `Io`"), projecting to an offset is safe. Thus, have the
primitive accessors project with `io_view` and `io_view_assert` and call
`read_val` or `write_val` themselves. The bounds checks are the same.
This prepares for access modes on I/O locations, added in a following
patch, which make the bounds of the generic methods depend on the mode
of the location. The primitive accessors keep their current bounds.
No functional change intended.
Signed-off-by: Daniel Almeida <[email protected]>
---
rust/kernel/io.rs | 36 ++++++++++++++++++++----------------
1 file changed, 20 insertions(+), 16 deletions(-)
diff --git a/rust/kernel/io.rs b/rust/kernel/io.rs
index 03af0590b0f4..4be8c761c556 100644
--- a/rust/kernel/io.rs
+++ b/rust/kernel/io.rs
@@ -760,7 +760,7 @@ fn try_read8(self, offset: usize) -> Result<u8>
usize: IoLoc<Self::Target, u8>,
Self::Backend: IoReadable<u8>,
{
- self.try_read(offset)
+ Ok(io_view::<_, u8>(self, offset)?.read_val())
}
/// Fallible 16-bit read with runtime bounds check.
@@ -770,7 +770,7 @@ fn try_read16(self, offset: usize) -> Result<u16>
usize: IoLoc<Self::Target, u16>,
Self::Backend: IoReadable<u16>,
{
- self.try_read(offset)
+ Ok(io_view::<_, u16>(self, offset)?.read_val())
}
/// Fallible 32-bit read with runtime bounds check.
@@ -780,7 +780,7 @@ fn try_read32(self, offset: usize) -> Result<u32>
usize: IoLoc<Self::Target, u32>,
Self::Backend: IoReadable<u32>,
{
- self.try_read(offset)
+ Ok(io_view::<_, u32>(self, offset)?.read_val())
}
/// Fallible 64-bit read with runtime bounds check.
@@ -790,7 +790,7 @@ fn try_read64(self, offset: usize) -> Result<u64>
usize: IoLoc<Self::Target, u64>,
Self::Backend: IoReadable<u64>,
{
- self.try_read(offset)
+ Ok(io_view::<_, u64>(self, offset)?.read_val())
}
/// Fallible 8-bit write with runtime bounds check.
@@ -800,7 +800,8 @@ fn try_write8(self, value: u8, offset: usize) -> Result
usize: IoLoc<Self::Target, u8>,
Self::Backend: IoWritable<u8>,
{
- self.try_write(offset, value)
+ io_view::<_, u8>(self, offset)?.write_val(value);
+ Ok(())
}
/// Fallible 16-bit write with runtime bounds check.
@@ -810,7 +811,8 @@ fn try_write16(self, value: u16, offset: usize) -> Result
usize: IoLoc<Self::Target, u16>,
Self::Backend: IoWritable<u16>,
{
- self.try_write(offset, value)
+ io_view::<_, u16>(self, offset)?.write_val(value);
+ Ok(())
}
/// Fallible 32-bit write with runtime bounds check.
@@ -820,7 +822,8 @@ fn try_write32(self, value: u32, offset: usize) -> Result
usize: IoLoc<Self::Target, u32>,
Self::Backend: IoWritable<u32>,
{
- self.try_write(offset, value)
+ io_view::<_, u32>(self, offset)?.write_val(value);
+ Ok(())
}
/// Fallible 64-bit write with runtime bounds check.
@@ -830,7 +833,8 @@ fn try_write64(self, value: u64, offset: usize) -> Result
usize: IoLoc<Self::Target, u64>,
Self::Backend: IoWritable<u64>,
{
- self.try_write(offset, value)
+ io_view::<_, u64>(self, offset)?.write_val(value);
+ Ok(())
}
/// Infallible 8-bit read with compile-time bounds check.
@@ -842,7 +846,7 @@ fn read8(self, offset: usize) -> u8
usize: IoLoc<Self::Target, u8>,
Self::Backend: IoReadable<u8>,
{
- self.read(offset)
+ io_view_assert::<_, u8>(self, offset).read_val()
}
/// Infallible 16-bit read with compile-time bounds check.
@@ -854,7 +858,7 @@ fn read16(self, offset: usize) -> u16
usize: IoLoc<Self::Target, u16>,
Self::Backend: IoReadable<u16>,
{
- self.read(offset)
+ io_view_assert::<_, u16>(self, offset).read_val()
}
/// Infallible 32-bit read with compile-time bounds check.
@@ -866,7 +870,7 @@ fn read32(self, offset: usize) -> u32
usize: IoLoc<Self::Target, u32>,
Self::Backend: IoReadable<u32>,
{
- self.read(offset)
+ io_view_assert::<_, u32>(self, offset).read_val()
}
/// Infallible 64-bit read with compile-time bounds check.
@@ -878,7 +882,7 @@ fn read64(self, offset: usize) -> u64
usize: IoLoc<Self::Target, u64>,
Self::Backend: IoReadable<u64>,
{
- self.read(offset)
+ io_view_assert::<_, u64>(self, offset).read_val()
}
/// Infallible 8-bit write with compile-time bounds check.
@@ -890,7 +894,7 @@ fn write8(self, value: u8, offset: usize)
usize: IoLoc<Self::Target, u8>,
Self::Backend: IoWritable<u8>,
{
- self.write(offset, value)
+ io_view_assert::<_, u8>(self, offset).write_val(value)
}
/// Infallible 16-bit write with compile-time bounds check.
@@ -902,7 +906,7 @@ fn write16(self, value: u16, offset: usize)
usize: IoLoc<Self::Target, u16>,
Self::Backend: IoWritable<u16>,
{
- self.write(offset, value)
+ io_view_assert::<_, u16>(self, offset).write_val(value)
}
/// Infallible 32-bit write with compile-time bounds check.
@@ -914,7 +918,7 @@ fn write32(self, value: u32, offset: usize)
usize: IoLoc<Self::Target, u32>,
Self::Backend: IoWritable<u32>,
{
- self.write(offset, value)
+ io_view_assert::<_, u32>(self, offset).write_val(value)
}
/// Infallible 64-bit write with compile-time bounds check.
@@ -926,7 +930,7 @@ fn write64(self, value: u64, offset: usize)
usize: IoLoc<Self::Target, u64>,
Self::Backend: IoWritable<u64>,
{
- self.write(offset, value)
+ io_view_assert::<_, u64>(self, offset).write_val(value)
}
/// Generic fallible read with runtime bounds check.
--
2.56.0