rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: init: remove impl Zeroable for Infallible
@ 2024-03-13 23:09 Benno Lossin
  2024-03-14  9:14 ` Alice Ryhl
  2024-03-18 17:25 ` Boqun Feng
  0 siblings, 2 replies; 13+ messages in thread
From: Benno Lossin @ 2024-03-13 23:09 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng,
	Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg,
	Alice Ryhl, Martin Rodriguez Reboredo
  Cc: Laine Taffin Altman, stable, rust-for-linux, linux-kernel

From: Laine Taffin Altman <alexanderaltman@me.com>

It is not enough for a type to be a ZST to guarantee that zeroed memory
is a valid value for it; it must also be inhabited. Creating a value of
an uninhabited type, ZST or no, is immediate UB.
Thus remove the implementation of `Zeroable` for `Infallible`, since
that type is not inhabited.

Cc: stable@vger.kernel.org
Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function")
Closes: https://github.com/Rust-for-Linux/pinned-init/pull/13
Signed-off-by: Laine Taffin Altman <alexanderaltman@me.com>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
---
 rust/kernel/init.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs
index 424257284d16..538e03cfc84a 100644
--- a/rust/kernel/init.rs
+++ b/rust/kernel/init.rs
@@ -1292,8 +1292,8 @@ macro_rules! impl_zeroable {
     i8, i16, i32, i64, i128, isize,
     f32, f64,
 
-    // SAFETY: These are ZSTs, there is nothing to zero.
-    {<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, Infallible, (),
+    // SAFETY: These are inhabited ZSTs, there is nothing to zero and a valid value exists.
+    {<T: ?Sized>} PhantomData<T>, core::marker::PhantomPinned, (),
 
     // SAFETY: Type is allowed to take any value, including all zeros.
     {<T>} MaybeUninit<T>,

base-commit: 768409cff6cc89fe1194da880537a09857b6e4db
-- 
2.42.0



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-03-30 16:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-13 23:09 [PATCH] rust: init: remove impl Zeroable for Infallible Benno Lossin
2024-03-14  9:14 ` Alice Ryhl
2024-03-18 17:25 ` Boqun Feng
2024-03-19  3:17   ` Laine Taffin Altman
2024-03-19  4:39     ` Boqun Feng
2024-03-19  5:28       ` Laine Taffin Altman
2024-03-19 10:34         ` Benno Lossin
2024-03-19 11:24           ` Miguel Ojeda
2024-03-21  4:53           ` Laine Taffin Altman
2024-03-21  9:07             ` Miguel Ojeda
2024-03-30 12:03             ` Benno Lossin
2024-03-30 16:36               ` Laine Taffin Altman
2024-03-30 16:43                 ` Benno Lossin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).