Re: [PATCH 09/10] rust: init: update `init` module to take allocation flags

Benno Lossin
2024-03-26T14:08:21Z

On 25.03.24 20:54, Wedson Almeida Filho wrote:
> From: Wedson Almeida Filho <walmeida@microsoft.com>
>
> This is the last component in the conversion for allocators to take
> allocation flags as parameters.
>
> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
> ---
> rust/kernel/init.rs | 49 ++++++++++++++++---------------
> rust/kernel/sync/arc.rs | 17 ++++++-----
> rust/kernel/sync/condvar.rs | 2 +-
> rust/kernel/sync/lock/mutex.rs | 2 +-
> rust/kernel/sync/lock/spinlock.rs | 2 +-
> rust/kernel/workqueue.rs | 13 +++++---
> 6 files changed, 47 insertions(+), 38 deletions(-)

One formatting issue below, with that fixed:

Reviewed-by: Benno Lossin <benno.lossin@proton.me>

> diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs
> index 077200f5350b..af539c5eb4bc 100644
> --- a/rust/kernel/sync/arc.rs
> +++ b/rust/kernel/sync/arc.rs
> @@ -565,13 +565,16 @@ pub fn new(value: T, flags: Flags) -> Result<Self, AllocError> {
> }
>
> /// Tries to allocate a new [`UniqueArc`] instance whose contents are not initialised yet.
> - pub fn new_uninit(_flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError> {
> + pub fn new_uninit(flags: Flags) -> Result<UniqueArc<MaybeUninit<T>>, AllocError> {
> // INVARIANT: The refcount is initialised to a non-zero value.
> - let inner = Box::try_init::<AllocError>(try_init!(ArcInner {
> + let inner = Box::try_init::<AllocError>(
> + try_init!(ArcInner {
> // SAFETY: There are no safety requirements for this FFI call.
> refcount: Opaque::new(unsafe { bindings::REFCOUNT_INIT(1) }),
> data <- init::uninit::<T, AllocError>(),
> - }? AllocError))?;
> + }? AllocError),
> + flags,
> + )?;

The indentation looks wrong, rustfmt sadly cannot handle the pin-init
macros. This looks better to me:

let inner = Box::try_init::<AllocError>(
try_init!(ArcInner {
// SAFETY: There are no safety requirements for this FFI call.
refcount: Opaque::new(unsafe { bindings::REFCOUNT_INIT(1) }),
data <- init::uninit::<T, AllocError>(),
}? AllocError),
flags,
)?;

--
Cheers,
Benno

> Ok(UniqueArc {
> // INVARIANT: The newly-created object has a refcount of 1.
> // SAFETY: The pointer from the `Box` is valid.