mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 1/2] rust: device: remove unused ref-to-ref transmute
Date: Tue, 26 May 2026 10:39:31 -0400	[thread overview]
Message-ID: <20260526-trasnmute_ptr_to_ptr-v1-1-d89bc1dda3b5@kernel.org> (raw)
In-Reply-To: <20260526-trasnmute_ptr_to_ptr-v1-0-d89bc1dda3b5@kernel.org>

The Ok return value of `read_array_from_fwnode_property` requires a
reference-to-reference transmute to construct but is never read, thus
remove it.

Signed-off-by: Tamir Duberstein <tamird@kernel.org>
---
 rust/kernel/device/property.rs | 42 +++++++++++++++++-------------------------
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/rust/kernel/device/property.rs b/rust/kernel/device/property.rs
index 5aead835fbbc..87be2784f7a7 100644
--- a/rust/kernel/device/property.rs
+++ b/rust/kernel/device/property.rs
@@ -136,18 +136,15 @@ pub fn property_read_array_vec<'fwnode, 'name, T: PropertyInt>(
         let mut val: KVec<T> = KVec::with_capacity(len, GFP_KERNEL)?;
 
         let res = T::read_array_from_fwnode_property(self, name, val.spare_capacity_mut());
-        let res = match res {
-            Ok(_) => {
-                // SAFETY:
-                // - `len` is equal to `val.capacity - val.len`, because
-                //   `val.capacity` is `len` and `val.len` is zero.
-                // - All elements within the interval [`0`, `len`) were initialized
-                //   by `read_array_from_fwnode_property`.
-                unsafe { val.inc_len(len) }
-                Ok(val)
-            }
-            Err(e) => Err(e),
-        };
+        let res = res.map(|()| {
+            // SAFETY:
+            // - `len` is equal to `val.capacity - val.len`, because
+            //   `val.capacity` is `len` and `val.len` is zero.
+            // - All elements within the interval [`0`, `len`) were initialized
+            //   by `read_array_from_fwnode_property`.
+            unsafe { val.inc_len(len) }
+            val
+        });
         Ok(PropertyGuard {
             inner: res,
             fwnode: self,
@@ -474,12 +471,12 @@ fn read_from_fwnode_property(fwnode: &FwNode, name: &CStr) -> Result<Self> {
 /// It must be public, because it appears in the signatures of other public
 /// functions, but its methods shouldn't be used outside the kernel crate.
 pub trait PropertyInt: Copy + Sealed {
-    /// Reads a property array.
-    fn read_array_from_fwnode_property<'a>(
+    /// Reads a property array into `out`.
+    fn read_array_from_fwnode_property(
         fwnode: &FwNode,
         name: &CStr,
-        out: &'a mut [MaybeUninit<Self>],
-    ) -> Result<&'a mut [Self]>;
+        out: &mut [MaybeUninit<Self>],
+    ) -> Result;
 
     /// Reads the length of a property array.
     fn read_array_len_from_fwnode_property(fwnode: &FwNode, name: &CStr) -> Result<usize>;
@@ -495,11 +492,11 @@ impl Sealed for $int {}
         impl<const N: usize> Sealed for [$int; N] {}
 
         impl PropertyInt for $int {
-            fn read_array_from_fwnode_property<'a>(
+            fn read_array_from_fwnode_property(
                 fwnode: &FwNode,
                 name: &CStr,
-                out: &'a mut [MaybeUninit<Self>],
-            ) -> Result<&'a mut [Self]> {
+                out: &mut [MaybeUninit<Self>],
+            ) -> Result {
                 // SAFETY:
                 // - `fwnode`, `name` and `out` are all valid by their type
                 //   invariants.
@@ -515,12 +512,7 @@ fn read_array_from_fwnode_property<'a>(
                         out.len(),
                     )
                 };
-                to_result(ret)?;
-                // SAFETY: Transmuting from `&'a mut [MaybeUninit<Self>]` to
-                // `&'a mut [Self]` is sound, because the previous call to a
-                // `fwnode_property_read_*_array` function (which didn't fail)
-                // fully initialized the slice.
-                Ok(unsafe { core::mem::transmute::<&mut [MaybeUninit<Self>], &mut [Self]>(out) })
+                to_result(ret)
             }
 
             fn read_array_len_from_fwnode_property(fwnode: &FwNode, name: &CStr) -> Result<usize> {

-- 
2.54.0


  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 " Tamir Duberstein
2026-05-26 14:39 ` Tamir Duberstein [this message]
2026-05-26 18:45   ` [PATCH 1/2] rust: device: remove unused " Onur Özkan
2026-05-28 13:29   ` Gary Guo
2026-05-30 11:17     ` Tamir Duberstein
2026-05-26 14:39 ` [PATCH 2/2] rust: device: remove array copy Tamir Duberstein
2026-05-26 16:29   ` 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-1-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®