[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjbW0yGm0TQcQEG9cc+i3WxbF8JKaqBUFD7=pJ-JkJ9zg@mail.gmail.com>
Date: Tue, 25 Feb 2025 12:34:09 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Viresh Kumar <viresh.kumar@...aro.org>
Cc: Yury Norov <yury.norov@...il.com>, Rasmus Villemoes <linux@...musvillemoes.dk>,
Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, linux-kernel@...r.kernel.org,
Danilo Krummrich <dakr@...hat.com>, rust-for-linux@...r.kernel.org,
Vincent Guittot <vincent.guittot@...aro.org>
Subject: Re: [PATCH 1/2] rust: Add initial cpumask abstractions
On Tue, Feb 25, 2025 at 11:54 AM Viresh Kumar <viresh.kumar@...aro.org> wrote:
>
> On 25-02-25, 10:55, Alice Ryhl wrote:
> > On Tue, Feb 25, 2025 at 10:47 AM Viresh Kumar <viresh.kumar@...aro.org> wrote:
> > > +impl Drop for Cpumask {
> > > + fn drop(&mut self) {
> > > + if self.owned {
> > > + // SAFETY: `ptr` is guaranteed to be valid for the lifetime of `self`. And it is safe
> > > + // to call `free_cpumask_var()`.
> > > + unsafe { bindings::free_cpumask_var(self.ptr) }
> >
> > This is missing a semicolon, but it's not the last statement in the
> > block. Did you compile this with CPUMASK_OFFSTACK=n? I don't think it
> > compiles with that setting.
>
> I would always add a semicolon here, yeah I missed adding that but ..
>
> I have missed minor things before sending a series a few times in the
> past and this one really scared me thinking here I did it again :)
>
> Though I was sure that I have built the code with both
> CPUMASK_OFFSTACK=y and =n, I performed the builds again and it worked
> (again). That confused me even more :)
>
> And here is what I think is happening here (which makes it build fine
> accidentally):
> - free_cpumask_var() has a return type of void.
> - The block {} allows it to build fine without a semicolon here.
> - I performed a simple test for this [1] and it works too.
Ah, you are right, the block makes it work in this particular case.
> > > + #[cfg(not(CONFIG_CPUMASK_OFFSTACK))]
> > > + // SAFETY: The pointer was earlier initialized from the result of `KBox::into_raw()`.
> > > + unsafe {
> > > + drop(KBox::from_raw(self.ptr))
> > > + };
> >
> > This looks like you did not run rustfmt.
>
> I did this:
>
> make CLIPPY=1 rustfmtcheck ARCH=arm64 O=../barm64t/ -j8 CROSS_COMPILE=aarch64-linux-gnu- CONFIG_DEBUG_SECTION_MISMATCH=y
>
> I hope that is all I need ? I checked again with both CONFIG options,
> doesn't complain with rustc 1.84.1.
Hmm, ok. I would have expected it to format on one line:
unsafe { drop(KBox::from_raw(self.ptr)) };
That is what normally happens when the semi-colon is outside the
block. Not sure why it did not happen in this case.
Alice
Powered by blists - more mailing lists