From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01A56D35177 for ; Wed, 1 Apr 2026 11:48:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vWEKmqVBjTEpQwDIjVnmDz4c+/yDDPJZ0EI/QhjWeUI=; b=zcyKRnrMEeNO5fBQYixjyr0hY6 q9LJxm2gg7SxxfESWgSj8O9xa6EPISb6v4Afp24QidXTAOEpPFR8ybUjI5DwnFNvuP4ad7a4XR69w +ELGXGuCXIO5RYt8sAtiGbnQO4brHIXP4G/Z1a174PjPeIuYdQ4OfV3AAKryXE6F1tjIuNt4Sd0G2 ZstsuLMM2fTR6w1MBaf5j0r+/UiC4V9kW19ivdZv+WyeOeOAPExV0HerSjU7C6a3NjPWEHIxmmduZ 9JPROMAHc5fteQuwKeBWQdMNVW9F8B3n0gkQc3SQF7/OS6YTR2o7nUTzYEUiXvYaMcfW8zNOblvSs eVj2K4Og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7u3M-0000000Eh1V-1U4U; Wed, 01 Apr 2026 11:48:08 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7u3K-0000000Egze-1Ulb; Wed, 01 Apr 2026 11:48:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=vWEKmqVBjTEpQwDIjVnmDz4c+/yDDPJZ0EI/QhjWeUI=; b=lhOiW0Qtb1f4YQkFF3A2P9czg5 JIi4eM29DDDMhBxrJ3vXET0y/2vSiUPUvA+XfxsfxAqH4/ag5+BlRgDfmXHW+PYU9fECRpC5vKHKX WCS8RE2XUIKD5wNGBiFgN1sqRv2p4Qr0MsdkR5mmGv2zah96OAa0+hsthLrFNVyIqz3j68ELLIJ9M 2MsZBF+ZCAU5OI64XliEy1lF8FvyYke/I75rRgdlwKVBF9TMq9cv5f9FN3dWRj1+hzHhEie3WRnyb nUNm+6OLyvDEl+6IGcCeC3NCDoHt/9LH7/dK6XLOpLAjyWXxBGDTC0bg2VAk8HbIToOVHyMXautLH 1JmT6QyA==; Received: from sea.source.kernel.org ([172.234.252.31]) by desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1w7u3H-00000000EZm-0SLb; Wed, 01 Apr 2026 11:48:05 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id C293E40914; Wed, 1 Apr 2026 11:48:01 +0000 (UTC) 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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260401_124803_450539_5898B878 X-CRM114-Status: UNSURE ( 8.18 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org `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 --- 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, &[u8])> where Self: Sized, { - if bytes.len() < size_of::() { - None - } else { - // PANIC: We checked that `bytes.len() >= size_of::`, thus `split_at` cannot - // panic. - // TODO: replace with `split_at_checked` once the MSRV is >= 1.80. - let (prefix, remainder) = bytes.split_at(size_of::()); + let (prefix, remainder) = bytes.split_at_checked(size_of::())?; - Self::from_bytes(prefix).map(|s| (s, remainder)) - } + Self::from_bytes(prefix).map(|s| (s, remainder)) } /// 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() >= size_of::`, thus `split_at_mut` cannot - // panic. - // TODO: replace with `split_at_mut_checked` once the MSRV is >= 1.80. - let (prefix, remainder) = bytes.split_at_mut(size_of::()); + let (prefix, remainder) = bytes.split_at_mut_checked(size_of::())?; - Self::from_bytes_mut(prefix).map(|s| (s, remainder)) - } + Self::from_bytes_mut(prefix).map(|s| (s, remainder)) } /// Creates an owned instance of `Self` by copying `bytes`. @@ -147,16 +133,9 @@ fn from_bytes_copy_prefix(bytes: &[u8]) -> Option<(Self, &[u8])> where Self: Sized, { - if bytes.len() < size_of::() { - None - } else { - // PANIC: We checked that `bytes.len() >= size_of::`, thus `split_at` cannot - // panic. - // TODO: replace with `split_at_checked` once the MSRV is >= 1.80. - let (prefix, remainder) = bytes.split_at(size_of::()); + let (prefix, remainder) = bytes.split_at_checked(size_of::())?; - Self::from_bytes_copy(prefix).map(|s| (s, remainder)) - } + Self::from_bytes_copy(prefix).map(|s| (s, remainder)) } } -- 2.53.0