From: Ritvik Gupta <ritvikfoss@gmail.com>
To: viresh.kumar@linaro.org, yury.norov@gmail.com, ojeda@kernel.org,
alex.gaynor@gmail.com, boqun.feng@gmail.com, gary@garyguo.net,
bjorn3_gh@protonmail.com, a.hindborg@kernel.org,
tmgross@umich.edu, dakr@kernel.org
Cc: rust-for-linux@vger.kernel.org, skhan@linuxfoundation.org,
Benno Lossin <lossin@kernel.org>,
Alice Ryhl <aliceryhl@google.com>
Subject: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
Date: Mon, 14 Jul 2025 00:32:44 +0530 [thread overview]
Message-ID: <20250713190244.143286-1-ritvikfoss@gmail.com> (raw)
Replace the following unsafe initializations:
1. `MaybeUninit::uninit().assume_init()` with `Opaque::uninit()`
2. `core::mem::zeroed()` with `Opaque::zeroed()`
Suggested-by: Benno Lossin <lossin@kernel.org>
Link: https://github.com/Rust-for-Linux/linux/issues/1178
Suggested-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/rust-for-linux/CAH5fLgj0OoCn56OkNUmiPQ=RAVa_VmS-yMZ4TNBSpGPNtZ5D0A@mail.gmail.com/
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Ritvik Gupta <ritvikfoss@gmail.com>
---
Carried forward 'Reviewed-by' tags from v1 since there're no substantial changes, just added suggested changes :)
(reviewers from v1 cc'd)
Changes in v2:
- Replaced `core::mem::zeroed()` with `Opaque::zeroed()` in `CpumaskVar::new_zero()` (thanks, Alice!)
Link to v1: https://lore.kernel.org/rust-for-linux/20250710123836.146825-1-ritvikfoss@gmail.com/
---
rust/kernel/cpumask.rs | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/rust/kernel/cpumask.rs b/rust/kernel/cpumask.rs
index 4bce230a73b6..3fcbff438670 100644
--- a/rust/kernel/cpumask.rs
+++ b/rust/kernel/cpumask.rs
@@ -14,9 +14,6 @@
#[cfg(CONFIG_CPUMASK_OFFSTACK)]
use core::ptr::{self, NonNull};
-#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
-use core::mem::MaybeUninit;
-
use core::ops::{Deref, DerefMut};
/// A CPU Mask.
@@ -239,10 +236,7 @@ pub fn new_zero(_flags: Flags) -> Result<Self, AllocError> {
},
#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
- // SAFETY: FFI type is valid to be zero-initialized.
- //
- // INVARIANT: The associated memory is freed when the `CpumaskVar` goes out of scope.
- mask: unsafe { core::mem::zeroed() },
+ mask: Cpumask(Opaque::zeroed()),
})
}
@@ -266,10 +260,7 @@ pub unsafe fn new(_flags: Flags) -> Result<Self, AllocError> {
NonNull::new(ptr.cast()).ok_or(AllocError)?
},
#[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
- // SAFETY: Guaranteed by the safety requirements of the function.
- //
- // INVARIANT: The associated memory is freed when the `CpumaskVar` goes out of scope.
- mask: unsafe { MaybeUninit::uninit().assume_init() },
+ mask: Cpumask(Opaque::uninit()),
})
}
base-commit: 2009a2d5696944d85c34d75e691a6f3884e787c0
--
2.50.1
next reply other threads:[~2025-07-13 19:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-13 19:02 Ritvik Gupta [this message]
2025-07-14 4:54 ` [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs Viresh Kumar
2025-07-14 16:53 ` Miguel Ojeda
2025-07-15 3:06 ` Viresh Kumar
2025-07-15 11:18 ` Miguel Ojeda
2025-07-16 4:15 ` Viresh Kumar
2025-07-16 12:40 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250713190244.143286-1-ritvikfoss@gmail.com \
--to=ritvikfoss@gmail.com \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tmgross@umich.edu \
--cc=viresh.kumar@linaro.org \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).