[PATCH v2 06/12] rust: io: register: implement Copy and Clone for RegisterArrayLoc

From: Alexandre Courbot

Date: Sat Nov 07 2026 - 04:51:57 EST


Register array locations are small values that are cheap to copy, but
obtaining one can fail. Making them implement `Copy` lets the same
location be checked once and used for several accesses.

Cc: Danilo Krummrich <dakr@xxxxxxxxxx>
Cc: Alice Ryhl <aliceryhl@xxxxxxxxxx>
Cc: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
Cc: Gary Guo <gary@xxxxxxxxxxx>
Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
---
rust/kernel/io/register.rs | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/rust/kernel/io/register.rs b/rust/kernel/io/register.rs
index b6513fa0f412..9e31e68d02cd 100644
--- a/rust/kernel/io/register.rs
+++ b/rust/kernel/io/register.rs
@@ -194,6 +194,14 @@ pub fn try_new(idx: usize) -> Option<Self> {
}
}

+impl<T: RegisterArray> Clone for RegisterArrayLoc<T> {
+ fn clone(&self) -> Self {
+ *self
+ }
+}
+
+impl<T: RegisterArray> Copy for RegisterArrayLoc<T> {}
+
impl<Base: ?Sized, T> IoLoc<Base, T> for RegisterArrayLoc<T>
where
T: RegisterArray<Base = Base>,

--
2.56.0