Re: [PATCH 1/2] rust: Add initial cpumask abstractions
From: Viresh Kumar
Date: Tue Feb 25 2025 - 05:54:42 EST
On 25-02-25, 10:55, Alice Ryhl wrote:
> On Tue, Feb 25, 2025 at 10:47 AM Viresh Kumar <viresh.kumar@xxxxxxxxxx> 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.
> > + #[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.
--
viresh
[1] https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=70cd7d31633d98774a088fed68ebb00d