From: Tamir Duberstein <tamird@kernel.org>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
"Danilo Krummrich" <dakr@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>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>
Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org,
Tamir Duberstein <tamird@kernel.org>
Subject: [PATCH 2/2] rust: device: remove array copy
Date: Tue, 26 May 2026 10:39:32 -0400 [thread overview]
Message-ID: <20260526-trasnmute_ptr_to_ptr-v1-2-d89bc1dda3b5@kernel.org> (raw)
In-Reply-To: <20260526-trasnmute_ptr_to_ptr-v1-0-d89bc1dda3b5@kernel.org>
`[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@kernel.org>
---
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
next prev parent reply other threads:[~2026-05-26 14:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 14:39 [PATCH 0/2] rust: device: remove ref-to-ref transmute Tamir Duberstein
2026-05-26 14:39 ` [PATCH 1/2] rust: device: remove unused " Tamir Duberstein
2026-05-26 18:45 ` Onur Özkan
2026-05-28 13:29 ` Gary Guo
2026-05-30 11:17 ` Tamir Duberstein
2026-05-26 14:39 ` Tamir Duberstein [this message]
2026-05-26 16:29 ` [PATCH 2/2] rust: device: remove array copy Tamir Duberstein
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=20260526-trasnmute_ptr_to_ptr-v1-2-d89bc1dda3b5@kernel.org \
--to=tamird@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rafael@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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®