From nobody Mon Feb 9 07:26:28 2026 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (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 BB1DC205ADE for ; Wed, 5 Mar 2025 13:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741181353; cv=none; b=JuXvkSXyEIVk2ChWS7kmFoHKpa3KLv7DLUxlhZmLl/aeCvUG83jTvVKW/JGzXDgDC5CgX6B4hXY0Rsjsalf/DzdS7/JehI8gELvAPzzZAAwvSdYp0AM3cuFn5CIuzMW8v2/L1kM7xZ8LcgOMOqSfve5Wub1kVZvW5JrcsMjByUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741181353; c=relaxed/simple; bh=4m3lsk3diPdi+pXnlMOPu66YINy014+l1ZqCdwvE+zY=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=YlLQJv3Hw0T8Ck+FO9MThCwyFb3SkOrAFYFN+KCu9VcgEgrpoyydZ3SpApDsA+UEP8tt5s7ZDi1nVrdAM8I2vDXRSDMP4cK3TM/TS2wub2Az0fBAV6dLDs01lLyNeeUG6tQ5//LXeKso5Lhkj1NYleken9VJwEN8w35XaumtibI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=GWwmNM4l; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="GWwmNM4l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1741181348; x=1741440548; bh=VLRuq+zLi3QgzPU0fq1VXCBryN9TCDq6Mg2zpj1ReCg=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=GWwmNM4lNNstyWlFysdFMIZvbZt6jCpaq1UHZAxQNF1Fr6oTvR91TWnV9D4UEbEyO bplPBXXgPXoKdipJrHfIdEEEKzDi3BR3UtxseEY4EIwzZUJEQnGNe328Zjd/k3OANY 4SnN/EKcQaWlOAyAlvGfEfcUVjoyzEfsfzxgGbKVIaRopX1fIDtfo5Peebf/MYbjmO fC9l7K3TXO867LBafW3iaDIFj1L3Hv5Jc8TlZMUxKibhFkS5cIDyFjbxkaKCK1lHep Z2gIIP6JROra80QkVdCbCIrFk/do5XHsxi5I14xpn47+rh5bjl07ZYFLHdZqbmEw6h ssIpcI73/CD9w== Date: Wed, 05 Mar 2025 13:29:01 +0000 To: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross From: Benno Lossin Cc: stable@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rust: init: fix `Zeroable` implementation for `Option>` and `Option>` Message-ID: <20250305132836.2145476-1-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: d1e529b8444b826cfa13a136a432f83cb566a8c5 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" According to [1], `NonNull` and `#[repr(transparent)]` wrapper types such as our custom `KBox` have the null pointer optimization only if `T: Sized`. Thus remove the `Zeroable` implementation for the unsized case. Link: https://doc.rust-lang.org/stable/std/option/index.html#representation= [1] Cc: stable@vger.kernel.org # v6.12+ (a custom patch will be needed for 6.6.= y) Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` f= unction") Signed-off-by: Benno Lossin Reported-by: Alice Ryhl Reviewed-by: Alice Ryhl Reviewed-by: Andreas Hindborg --- rust/kernel/init.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index 7fd1ea8265a5..8bbd5e3398fc 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -1418,17 +1418,14 @@ macro_rules! impl_zeroable { // SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`. {} UnsafeCell, =20 - // SAFETY: All zeros is equivalent to `None` (option layout optimizati= on guarantee). + // SAFETY: All zeros is equivalent to `None` (option layout optimizati= on guarantee: + // https://doc.rust-lang.org/stable/std/option/index.html#representati= on). Option, Option, Option, Option, Option, Option, Option, Option, Option, Option, Option, Option, - - // SAFETY: All zeros is equivalent to `None` (option layout optimizati= on guarantee). - // - // In this case we are allowed to use `T: ?Sized`, since all zeros is = the `None` variant. - {} Option>, - {} Option>, + {} Option>, + {} Option>, =20 // SAFETY: `null` pointer is valid. // base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6 --=20 2.48.1