[PATCH 2/2] rust: device: remove array copy
From: Tamir Duberstein
Date: Tue May 26 2026 - 10:46:31 EST
`[T; N]::map` constructs a copy of the array which is not necessary
here, thus follow the example in the `MaybeUninit` documentation and
transmute `[MaybeUninit<T>; N]` to `[T; N]`.
Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxxx>
---
rust/kernel/device/property.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 87be2784f7a7..a85467c99636 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -549,7 +549,9 @@ fn read_from_fwnode_property(fwnode: &FwNode, name: &CStr) -> Result<Self> {
// SAFETY: `val` is always initialized when
// `fwnode_property_read_*_array` is successful.
- Ok(val.map(|v| unsafe { v.assume_init() }))
+ //
+ // See https://doc.rust-lang.org/stable/core/mem/union.MaybeUninit.html#initializing-an-array-element-by-element.
+ Ok(unsafe { mem::transmute::<_, [$int; N]>(val) })
}
}
)* };
--
2.54.0