[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230714-classless_lockdep-v1-1-229b9671ce31@asahilina.net>
Date: Fri, 14 Jul 2023 18:13:53 +0900
From: Asahi Lina <lina@...hilina.net>
To: Miguel Ojeda <ojeda@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Masahiro Yamada <masahiroy@...nel.org>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Nicolas Schier <nicolas@...sle.eu>, Tom Rix <trix@...hat.com>,
Daniel Vetter <daniel@...ll.ch>
Cc: Hector Martin <marcan@...can.st>, Sven Peter <sven@...npeter.dev>,
Alyssa Rosenzweig <alyssa@...enzweig.io>,
asahi@...ts.linux.dev, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-kbuild@...r.kernel.org,
llvm@...ts.linux.dev, Asahi Lina <lina@...hilina.net>
Subject: [PATCH RFC 01/11] rust: types: Add Opaque::zeroed()
Opaque types are internally MaybeUninit, so it's safe to actually
zero-initialize them as long as we don't claim they are initialized.
This is useful for many FFI types that are expected to be zero-inited by
the user.
Signed-off-by: Asahi Lina <lina@...hilina.net>
---
rust/kernel/types.rs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs
index 1e5380b16ed5..185d3493857e 100644
--- a/rust/kernel/types.rs
+++ b/rust/kernel/types.rs
@@ -237,6 +237,11 @@ pub const fn uninit() -> Self {
Self(MaybeUninit::uninit())
}
+ /// Creates a zeroed value.
+ pub fn zeroed() -> Self {
+ Self(MaybeUninit::zeroed())
+ }
+
/// Creates a pin-initializer from the given initializer closure.
///
/// The returned initializer calls the given closure with the pointer to the inner `T` of this
--
2.40.1
Powered by blists - more mailing lists