Rust-for-linux archive mirror
 help / color / mirror / Atom feed
From: Wedson Almeida Filho <wedsonaf@gmail.com>
To: Benno Lossin <benno.lossin@proton.me>
Cc: rust-for-linux@vger.kernel.org, "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>,
	linux-kernel@vger.kernel.org,
	"Wedson Almeida Filho" <walmeida@microsoft.com>
Subject: Re: [PATCH 09/10] rust: init: update `init` module to take allocation flags
Date: Tue, 26 Mar 2024 23:17:31 -0300	[thread overview]
Message-ID: <CANeycqou9AT6BzxdNKrT_B2eRs4htjJx3dq-mKBByMOAj-8qiw@mail.gmail.com> (raw)
In-Reply-To: <kiqpEglPExNZBB0TsooPwQsQTwFfYadAnVfztU9sFzYJ5CU_Rg0PC_KYEQF4duxv7qOo6gOBUFVnR-GfuEsIEYqgBSWnOGEZAcl3t06cB2s=@proton.me>

On Tue, 26 Mar 2024 at 11:08, Benno Lossin <benno.lossin@proton.me> wrote:
>
> 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,
>         )?;

I remember trying to rearrange this and `rustfmtcheck` not liking it
but it seems to be happy with your suggestion.

Applying it in v2.

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

  reply	other threads:[~2024-03-27  2:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-25 19:54 [PATCH 00/10] Allocation APIs Wedson Almeida Filho
2024-03-25 19:54 ` [PATCH 01/10] rust: kernel: move `allocator` module under `alloc` Wedson Almeida Filho
2024-03-25 21:56   ` Benno Lossin
2024-03-26  0:04     ` Wedson Almeida Filho
2024-03-25 19:54 ` [PATCH 02/10] rust: alloc: introduce the `VecExt` trait Wedson Almeida Filho
2024-03-25 22:05   ` Benno Lossin
2024-03-26  0:02     ` Wedson Almeida Filho
2024-03-25 19:54 ` [PATCH 03/10] kbuild: use the upstream `alloc` crate Wedson Almeida Filho
2024-03-25 19:54 ` [PATCH 04/10] rust: alloc: remove our fork of the " Wedson Almeida Filho
2024-03-25 22:24   ` Benno Lossin
2024-03-25 19:54 ` [PATCH 05/10] rust: alloc: introduce allocation flags Wedson Almeida Filho
2024-03-25 22:26   ` Benno Lossin
2024-03-25 19:54 ` [PATCH 06/10] rust: alloc: introduce the `BoxExt` trait Wedson Almeida Filho
2024-03-25 22:37   ` Benno Lossin
2024-03-26  0:17     ` Wedson Almeida Filho
2024-03-26 13:30       ` Benno Lossin
2024-03-27  1:54         ` Wedson Almeida Filho
2024-03-27  1:55         ` Wedson Almeida Filho
2024-03-25 19:54 ` [PATCH 07/10] rust: alloc: update `VecExt` to take allocation flags Wedson Almeida Filho
2024-03-25 20:44   ` Boqun Feng
2024-03-26  0:03     ` Wedson Almeida Filho
2024-03-26 13:58       ` Benno Lossin
2024-03-25 19:54 ` [PATCH 08/10] rust: sync: update `Arc` and `UniqueArc` " Wedson Almeida Filho
2024-03-26 14:01   ` Benno Lossin
2024-03-25 19:54 ` [PATCH 09/10] rust: init: update `init` module " Wedson Almeida Filho
2024-03-26 14:08   ` Benno Lossin
2024-03-27  2:17     ` Wedson Almeida Filho [this message]
2024-03-25 19:54 ` [PATCH 10/10] rust: kernel: remove usage of `allocator_api` unstable feature Wedson Almeida Filho
2024-03-26 15:27   ` Benno Lossin
2024-03-27  2:13     ` Wedson Almeida Filho

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=CANeycqou9AT6BzxdNKrT_B2eRs4htjJx3dq-mKBByMOAj-8qiw@mail.gmail.com \
    --to=wedsonaf@gmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=walmeida@microsoft.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 read-only IMAP folder(s) and NNTP newsgroup(s).