From nobody Mon Jun 8 20:53:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1F423DD51D; Tue, 26 May 2026 14:39:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779806382; cv=none; b=cTEraoxAJ9WYB8oyLqS7vxJwJyffp4X1n0d/319cAinXXGSIWfSFJt5zTwgwUOj56ee3TDbDuGPRijqigu0UA5eNHvT8JF1HnrRxEgpqyq3EEmlswCWubdXX892uO3AZJRe8t818ucA+jWMsYIe/wgo3uYRMUciXmD9E+6cLDcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779806382; c=relaxed/simple; bh=FtAEkUaUKgpbdEcSGG19C3UOQzIEkfHbM4RuQWECPTE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=liwMRDzWEFB6+ed6Axj0iFHWJ8rtfifaYM/daEq3QBd17BLZojxEYovIb3a/T8GcODFbWK30ssN+32lsB+/Q3cRq65vbCypQ1skDep6H+yhu5Y9U1WbPXIxZe+XiGzegUEOM76zniLp5T1tIW7LyauMGQcOiW1vsiG8Zwi9KElM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XQZo4Ay8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XQZo4Ay8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74DB31F00A3C; Tue, 26 May 2026 14:39:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779806377; bh=/sTcFllR8dDFAzTpA0T3cKmFW0quYw/+CcgqKmyW5Nw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=XQZo4Ay8y8G/+q01Odi8vUTtR/X4eAuseAHoSn5XE1uDvdHS1dfJBXYrXV3QveGwU iwOSMmLyseh9Vn+ii5ADpUSChcyJX6RJ1+oGdx36DDyabjNkR1UpJrb2KUEvNWfGgm nAfW2PC1sFfozKTFEz3ZXQgQkzdg2VLlTBXuE0Qmv/jXI74GpadVarB28u7fMkasp6 BG8v7n1Wx/CLQ5r4TADfdvi9HBwAWrXOxUTIb/3IkW1gOY0y+1iSY69moAmcMoHSzR AxPbf2IsDLXkm9DYuB3mjLzj5CA6h8QlSkpbnvjmXYp4PGAM2KxlXaual0q1I/kZKk XZbNgXQeqNRCA== From: Tamir Duberstein Date: Tue, 26 May 2026 10:39:31 -0400 Subject: [PATCH 1/2] rust: device: remove unused ref-to-ref transmute Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-trasnmute_ptr_to_ptr-v1-1-d89bc1dda3b5@kernel.org> References: <20260526-trasnmute_ptr_to_ptr-v1-0-d89bc1dda3b5@kernel.org> In-Reply-To: <20260526-trasnmute_ptr_to_ptr-v1-0-d89bc1dda3b5@kernel.org> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3963; i=tamird@kernel.org; h=from:subject:message-id; bh=FtAEkUaUKgpbdEcSGG19C3UOQzIEkfHbM4RuQWECPTE=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiG5ZJXjton9r6/fwklrz/G4RKbxo4xjpm6M/k0dqbx /hS9YJCx0QWBjEuBksxRZZE0UN701Nv75HNfHccZg4rE8gQaZEGBiBgYeDLTcwrNdIx0jPVNtQz NNIx0DFm4OIUgKnWeMjIsEHc7Yz1NGXhAB7OvzHJBrvn7bXYcH7e9sXrb/Bbhz61r2RkuLq2jYf Z8HV7DMusyetWHFFVX2GycdHy51EzvUuzREwesgAA X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 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 Reviewed-by: Onur =C3=96zkan --- 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: Pro= pertyInt>( let mut val: KVec =3D KVec::with_capacity(len, GFP_KERNEL)?; =20 let res =3D T::read_array_from_fwnode_property(self, name, val.spa= re_capacity_mut()); - let res =3D match res { - Ok(_) =3D> { - // 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 in= itialized - // by `read_array_from_fwnode_property`. - unsafe { val.inc_len(len) } - Ok(val) - } - Err(e) =3D> Err(e), - }; + let res =3D 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 initia= lized + // 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 { /// 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], - ) -> Result<&'a mut [Self]>; + out: &mut [MaybeUninit], + ) -> Result; =20 /// Reads the length of a property array. fn read_array_len_from_fwnode_property(fwnode: &FwNode, name: &CStr) -= > Result; @@ -495,11 +492,11 @@ impl Sealed for $int {} impl Sealed for [$int; N] {} =20 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], - ) -> Result<&'a mut [Self]> { + out: &mut [MaybeUninit], + ) -> 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]` = to - // `&'a mut [Self]` is sound, because the previous call to= a - // `fwnode_property_read_*_array` function (which didn't f= ail) - // fully initialized the slice. - Ok(unsafe { core::mem::transmute::<&mut [MaybeUninit= ], &mut [Self]>(out) }) + to_result(ret) } =20 fn read_array_len_from_fwnode_property(fwnode: &FwNode, name: = &CStr) -> Result { --=20 2.54.0 From nobody Mon Jun 8 20:53:48 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE9D03C8C7C; Tue, 26 May 2026 14:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779806382; cv=none; b=IIca6d1RQG3gpVGJ2p8NgWxydH6ZZKBJ2axKd+RhXzxFCu+vF4P/oVsGxL2/mb4lSUVeeS8xhDRp4O8czK9lrad3y4zdJizTdndItgpA5wYszAExg0Yx/jWTnFfguHjy6SIFvL5TqZ++8cqFvIJZIiToDtsO/aO1rQItroTHERg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779806382; c=relaxed/simple; bh=jtSVR/F6PNKgzGgxXsKqAicbXWohzTvPvShM+TgstwA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tY/ZY079xrFt/+fzpBkkPaGGr5aI5GqZxyRnhtzLJN8WIOHlxzmaQBRQH8Mt4qEamCpKgP0jF+y9K4hPE9YDGXLtO2MB7DAIEU/3/K1f57XZuv6hEw0FcFm8Vfs4tC/+9E44I40ZrbcyGMNXZ7/KwB4yoix92xH9IL4zURCskmA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kECZXKqB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kECZXKqB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 158B51F00A3E; Tue, 26 May 2026 14:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779806379; bh=4iVepei/+7bQofT0t4P5cu88kUQu5myDyLxDZfehFtg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=kECZXKqB76o3vjV+vsk/RKKP59wVnCtoeiHf9sHXV9wa2entj+Qc0kngmhVW1Ej5k T+YGI94bGjJpQHW0pigLpN3lJMgt3d6AFO+/dBeHTDD4U+M2vbIcrpZ/1Ecb4zekbK dkSwmjiouKpfzzeuJg+D86uiBgCdeLIXQOUBepkPIHuKAUJmiVwBC+zL3W20zAmAgT wHCeOckPj8wrc+b6yudJqI2nXTskceXIEuXrpIQufb8j0LckIK7Us/EWFWZzh8k4qV s1qUqWWy/nLUbBNLnLnRRcD3dHZknZ2UZcw/289oOgFvn6qFq8D8HOWlYGFjjQk7rW SBA6KaKQLFzww== From: Tamir Duberstein Date: Tue, 26 May 2026 10:39:32 -0400 Subject: [PATCH 2/2] rust: device: remove array copy Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-trasnmute_ptr_to_ptr-v1-2-d89bc1dda3b5@kernel.org> References: <20260526-trasnmute_ptr_to_ptr-v1-0-d89bc1dda3b5@kernel.org> In-Reply-To: <20260526-trasnmute_ptr_to_ptr-v1-0-d89bc1dda3b5@kernel.org> To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross Cc: driver-core@lists.linux.dev, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Tamir Duberstein X-Mailer: b4 0.16-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1102; i=tamird@kernel.org; h=from:subject:message-id; bh=jtSVR/F6PNKgzGgxXsKqAicbXWohzTvPvShM+TgstwA=; b=owGbwMvMwCV2wYdPVfy60HTG02pJDFmiG5aF9Gv8Vjxe90Bl+4rYx3M/3y5abP2TgcG74P4Fa R3dpGWeHRNZGMS4GCzFFFkSRQ/tTU+9vUc2891xmDmsTCBDpEUaGICAhYEvNzGv1EjHSM9U21DP 0EjHQMeYgYtTAKb6myzDP0tG+52MKSy9Ge91DfaXvPA3sHM78o+vvlHj+K7nrnMVzzMyLF3XJxX K2mJpFcPOtPN5zwRht8wpEv2vXCwc2Se+O/OFEwA= X-Developer-Key: i=tamird@kernel.org; a=openpgp; fpr=5A6714204D41EC844C50273C19D6FF6092365380 `[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; N]` to `[T; N]`. Signed-off-by: Tamir Duberstein --- 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: &CS= tr) -> Result { =20 // 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.May= beUninit.html#initializing-an-array-element-by-element. + Ok(unsafe { mem::transmute::<_, [$int; N]>(val) }) } } )* }; --=20 2.54.0