mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Almeida <daniel.almeida@collabora.com>
To: "Danilo Krummrich" <dakr@kernel.org>,
	"Abdiel Janulgue" <abdiel.janulgue@gmail.com>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"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>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>
Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	 dri-devel@lists.freedesktop.org,
	 Daniel Almeida <daniel.almeida@collabora.com>
Subject: [PATCH 4/7] rust: io: project primitive accessors directly
Date: Thu, 15 Oct 2026 09:39:08 -0300	[thread overview]
Message-ID: <20261015-io-access-modes-v1-4-93611b84b5e3@collabora.com> (raw)
In-Reply-To: <20261015-io-access-modes-v1-0-93611b84b5e3@collabora.com>

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 <daniel.almeida@collabora.com>
---
 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


  parent reply	other threads:[~2026-10-15 12:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 12:39 [PATCH 0/7] rust: io: add read-only and write-only views and registers Daniel Almeida
2026-10-15 12:39 ` [PATCH 1/7] rust: io: split IoCapable into IoReadable and IoWritable Daniel Almeida
2026-10-15 12:39 ` [PATCH 2/7] rust: io: split IoCopyable into IoCopyReadable and IoCopyWritable Daniel Almeida
2026-10-15 12:39 ` [PATCH 3/7] rust: io: add read-only and write-only views Daniel Almeida
2026-10-15 12:39 ` Daniel Almeida [this message]
2026-10-15 12:39 ` [PATCH 5/7] rust: io: let I/O locations carry an access mode Daniel Almeida
2026-10-15 12:39 ` [PATCH 6/7] rust: io: register: add `#[ro]` and `#[wo]` attributes Daniel Almeida
2026-10-15 12:39 ` [PATCH 7/7] drm/tyr: mark read-only and write-only registers Daniel Almeida
2026-10-20  8:01 ` [PATCH 0/7] rust: io: add read-only and write-only views and registers Alice Ryhl

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=20261015-io-access-modes-v1-4-93611b84b5e3@collabora.com \
    --to=daniel.almeida@collabora.com \
    --cc=a.hindborg@kernel.org \
    --cc=abdiel.janulgue@gmail.com \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gary@garyguo.net \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®