* [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
@ 2025-07-13 19:02 Ritvik Gupta
2025-07-14 4:54 ` Viresh Kumar
0 siblings, 1 reply; 7+ messages in thread
From: Ritvik Gupta @ 2025-07-13 19:02 UTC (permalink / raw)
To: viresh.kumar, yury.norov, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, a.hindborg, tmgross, dakr
Cc: rust-for-linux, skhan, Benno Lossin, Alice Ryhl
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
2025-07-13 19:02 [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs Ritvik Gupta
@ 2025-07-14 4:54 ` Viresh Kumar
2025-07-14 16:53 ` Miguel Ojeda
0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2025-07-14 4:54 UTC (permalink / raw)
To: Ritvik Gupta
Cc: yury.norov, ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh,
a.hindborg, tmgross, dakr, rust-for-linux, skhan, Benno Lossin,
Alice Ryhl
On 14-07-25, 00:32, Ritvik Gupta wrote:
> 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>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
2025-07-14 4:54 ` Viresh Kumar
@ 2025-07-14 16:53 ` Miguel Ojeda
2025-07-15 3:06 ` Viresh Kumar
0 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2025-07-14 16:53 UTC (permalink / raw)
To: Viresh Kumar
Cc: Ritvik Gupta, yury.norov, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, a.hindborg, tmgross, dakr, rust-for-linux, skhan,
Benno Lossin, Alice Ryhl
On Mon, Jul 14, 2025 at 6:54 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Wouldn't this go via your `pm` tree to Rafael? Or am I confused?
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
2025-07-14 16:53 ` Miguel Ojeda
@ 2025-07-15 3:06 ` Viresh Kumar
2025-07-15 11:18 ` Miguel Ojeda
0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2025-07-15 3:06 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Ritvik Gupta, yury.norov, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, a.hindborg, tmgross, dakr, rust-for-linux, skhan,
Benno Lossin, Alice Ryhl
On 14-07-25, 18:53, Miguel Ojeda wrote:
> On Mon, Jul 14, 2025 at 6:54 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> >
> > Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
>
> Wouldn't this go via your `pm` tree to Rafael? Or am I confused?
Applied now.
I manage pull requests for cpufreq and OPP normally. I had to to
cpumask, clk, etc., as dependencies for my Rust stuff but I am not
sure about what's the best way to get them merged.
For now I can take this one though.
--
viresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
2025-07-15 3:06 ` Viresh Kumar
@ 2025-07-15 11:18 ` Miguel Ojeda
2025-07-16 4:15 ` Viresh Kumar
0 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2025-07-15 11:18 UTC (permalink / raw)
To: Viresh Kumar
Cc: Ritvik Gupta, yury.norov, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, a.hindborg, tmgross, dakr, rust-for-linux, skhan,
Benno Lossin, Alice Ryhl
On Tue, Jul 15, 2025 at 5:06 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> Applied now.
>
> I manage pull requests for cpufreq and OPP normally. I had to to
> cpumask, clk, etc., as dependencies for my Rust stuff but I am not
> sure about what's the best way to get them merged.
>
> For now I can take this one though.
Ah, I thought the idea was to continue like that.
If that was not the case, then it should be clarified. Do you have a
pointer to the latest discussion on this?
Thanks!
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
2025-07-15 11:18 ` Miguel Ojeda
@ 2025-07-16 4:15 ` Viresh Kumar
2025-07-16 12:40 ` Miguel Ojeda
0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2025-07-16 4:15 UTC (permalink / raw)
To: Miguel Ojeda
Cc: Ritvik Gupta, yury.norov, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, a.hindborg, tmgross, dakr, rust-for-linux, skhan,
Benno Lossin, Alice Ryhl
On 15-07-25, 13:18, Miguel Ojeda wrote:
> Ah, I thought the idea was to continue like that.
I will keep pushing the changes via the PM tree for now.
--
viresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
2025-07-16 4:15 ` Viresh Kumar
@ 2025-07-16 12:40 ` Miguel Ojeda
0 siblings, 0 replies; 7+ messages in thread
From: Miguel Ojeda @ 2025-07-16 12:40 UTC (permalink / raw)
To: Viresh Kumar
Cc: Ritvik Gupta, yury.norov, ojeda, alex.gaynor, boqun.feng, gary,
bjorn3_gh, a.hindborg, tmgross, dakr, rust-for-linux, skhan,
Benno Lossin, Alice Ryhl
On Wed, Jul 16, 2025 at 6:15 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>
> I will keep pushing the changes via the PM tree for now.
Ok, great, thanks -- please let me know if there is a renewed
discussion on that or if we can help somehow in the future.
Cheers,
Miguel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-16 12:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-13 19:02 [PATCH v2] rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs Ritvik Gupta
2025-07-14 4:54 ` 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
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).