From nobody Wed Apr 1 22:11:50 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CEFBB3E7172; Wed, 1 Apr 2026 11:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775044081; cv=none; b=cEoXMp62PKRfyd7itFESuIoRLQSM3ANfIv1Hh55L/rGkkMUUgFOF4Tix1mEVJxq7UiWh4MdJT6ZTpVDb/7+3YNQTpZ8tYNEcTJqJ9z3FFnRjwXpijCbpfr//kQHwvI28zEaQ7xU04OYeaeudtIosdINX+bAvDb2gyI6ygde37S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775044081; c=relaxed/simple; bh=adABYvIqd3NTguvnrLCuC9umM1YlmwtHIfAtv/sMMlY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P0JZ/AD/SsFuKmpexO+ddzZi8dOdM/UFwVWuyjJwYLQRdViN1KkSvqKQzCYsvb8l1gzoQqt+d24yDK+G/SDWOX0cclHmjBjd9HoeXFlbtZ2EmdskZjxPko6LVxJpnzAh5xpziFHfKOpMghepUnGQ+sD8hQ7ZxDO9ccxGNiq81h4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W7RUQV2H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W7RUQV2H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60409C4CEF7; Wed, 1 Apr 2026 11:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775044081; bh=adABYvIqd3NTguvnrLCuC9umM1YlmwtHIfAtv/sMMlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W7RUQV2HZDvpt7cb2QLkpsSjIXygeJXHzglkI2wvWnPnI2M1b6re/EbnmI0XwokyF wrrwYxN+/b+ugyMYmH9z5Umd525lrDMMtI1jgyazypmGOGTbjEKg2Uf67p5z3f9Bmg c6SqSWS5dXNcFVk9QuiGQs+D+hKuqndvN5lUWvCrCbINYOm3WsPZfDOtxulUNeWqbM y89bDoxVl41VBEb3zkJMUAunBi8T9StVC/clbVAz8kgUAUUzxcNf8AJj/euaS7+TKs GxDpNxLDh92OcnV4pmrI+T0sPk26QqFNokBc1fpaibHISln0xBEqZ/Iba9ePZXRZ+o QQE6E4BNPh56g== From: Miguel Ojeda To: Miguel Ojeda , Nathan Chancellor , Nicolas Schier , Danilo Krummrich , Andreas Hindborg , Catalin Marinas , Will Deacon , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Courbot , David Airlie , Simona Vetter , Brendan Higgins , David Gow , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Christian Brauner , Carlos Llamas , Alice Ryhl , Jonathan Corbet Cc: Boqun Feng , Gary Guo , =?UTF-8?q?Bj=C3=B6rn=20Roy=20Baron?= , Benno Lossin , Trevor Gross , rust-for-linux@vger.kernel.org, linux-kbuild@vger.kernel.org, Lorenzo Stoakes , Vlastimil Babka , "Liam R . Howlett" , Uladzislau Rezki , linux-block@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated for non-subscribers), Alexandre Ghiti , linux-riscv@lists.infradead.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Rae Moar , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, Nick Desaulniers , Bill Wendling , Justin Stitt , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Shuah Khan , linux-doc@vger.kernel.org Subject: [PATCH 10/33] rust: transmute: simplify code with Rust 1.80.0 `split_at_*checked()` Date: Wed, 1 Apr 2026 13:45:17 +0200 Message-ID: <20260401114540.30108-11-ojeda@kernel.org> In-Reply-To: <20260401114540.30108-1-ojeda@kernel.org> References: <20260401114540.30108-1-ojeda@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" `feature(split_at_checked)` [1] has been stabilized in Rust 1.80.0 [2], which is beyond our new minimum Rust version (Rust 1.85.0). Thus simplify the code using `split_at_*checked()`. Link: https://github.com/rust-lang/rust/issues/119128 [1] Link: https://github.com/rust-lang/rust/pull/124678 [2] Signed-off-by: Miguel Ojeda Reviewed-by: Gary Guo --- rust/kernel/transmute.rs | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/rust/kernel/transmute.rs b/rust/kernel/transmute.rs index b9e6eadc08f5..654b5ede2fe2 100644 --- a/rust/kernel/transmute.rs +++ b/rust/kernel/transmute.rs @@ -66,16 +66,9 @@ fn from_bytes_prefix(bytes: &[u8]) -> Option<(&Self, &[u= 8])> where Self: Sized, { - if bytes.len() < size_of::() { - None - } else { - // PANIC: We checked that `bytes.len() >=3D size_of::`, = thus `split_at` cannot - // panic. - // TODO: replace with `split_at_checked` once the MSRV is >=3D= 1.80. - let (prefix, remainder) =3D bytes.split_at(size_of::()); + let (prefix, remainder) =3D bytes.split_at_checked(size_of::= ())?; =20 - Self::from_bytes(prefix).map(|s| (s, remainder)) - } + Self::from_bytes(prefix).map(|s| (s, remainder)) } =20 /// Converts a mutable slice of bytes to a reference to `Self`. @@ -108,16 +101,9 @@ fn from_bytes_mut_prefix(bytes: &mut [u8]) -> Option<(= &mut Self, &mut [u8])> where Self: AsBytes + Sized, { - if bytes.len() < size_of::() { - None - } else { - // PANIC: We checked that `bytes.len() >=3D size_of::`, = thus `split_at_mut` cannot - // panic. - // TODO: replace with `split_at_mut_checked` once the MSRV is = >=3D 1.80. - let (prefix, remainder) =3D bytes.split_at_mut(size_of::= ()); + let (prefix, remainder) =3D bytes.split_at_mut_checked(size_of::())?; =20 - Self::from_bytes_mut(prefix).map(|s| (s, remainder)) - } + Self::from_bytes_mut(prefix).map(|s| (s, remainder)) } =20 /// Creates an owned instance of `Self` by copying `bytes`. @@ -147,16 +133,9 @@ fn from_bytes_copy_prefix(bytes: &[u8]) -> Option<(Sel= f, &[u8])> where Self: Sized, { - if bytes.len() < size_of::() { - None - } else { - // PANIC: We checked that `bytes.len() >=3D size_of::`, = thus `split_at` cannot - // panic. - // TODO: replace with `split_at_checked` once the MSRV is >=3D= 1.80. - let (prefix, remainder) =3D bytes.split_at(size_of::()); + let (prefix, remainder) =3D bytes.split_at_checked(size_of::= ())?; =20 - Self::from_bytes_copy(prefix).map(|s| (s, remainder)) - } + Self::from_bytes_copy(prefix).map(|s| (s, remainder)) } } =20 --=20 2.53.0