rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
Subsystems (2)
PATCH v2 1/1 rust: cpumask: Replace `MaybeUninit` and `mem::zeroed` with `Opaque` APIs
Replace the following unsafe initializations:
1. MaybeUninit::uninit().assume_init() with Opaque::uninit()
2. core::mem::zeroed() with Opaque::zeroed()
---
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/[email protected]/
--- rust/kernel/cpumask.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
rust/kernel/cpumask.rs +2 -11
@@ -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
Signature · 1 line
2.50.1
Quoted 11 lines · Ritvik Gupta
Replace the following unsafe initializations:
1.MaybeUninit::uninit().assume_init()withOpaque::uninit()
2.core::mem::zeroed()withOpaque::zeroed()Suggested-by Benno Lossin <[email protected]>Suggested-by Alice Ryhl <[email protected]>Link https://lore.kernel.org/rust-for-linux/CAH5fLgj0OoCn56OkNUmiPQ=RAVa_VmS-yMZ4TNBSpGPNtZ5D0A@mail.gmail.com/ open hereReviewed-by Benno Lossin <[email protected]>Reviewed-by Alice Ryhl <[email protected]>Signed-off-by Ritvik Gupta <[email protected]>
Signature · 1 line
viresh
Quoted 2 lines · Viresh Kumar
Acked-by Viresh Kumar <[email protected]>
Wouldn't this go via your pm tree to Rafael? Or am I confused?
Thanks!
Cheers,
Miguel
Viresh Kumar
maintainerQuoted 5 lines · Miguel Ojeda
Quoted 2 lines · Viresh Kumar
Acked-by Viresh Kumar <[email protected]>Wouldn't this go via your
pmtree 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.
Signature · 1 line
viresh
Quoted 8 lines · Viresh Kumar
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
Viresh Kumar
maintainerQuoted 1 line · Miguel Ojeda
Ah, I thought the idea was to continue like that.
I will keep pushing the changes via the PM tree for now.
Signature · 1 line
viresh
Quoted 2 lines · Viresh Kumar
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