[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z9gEcDRDLTd4Svp7@pollux>
Date: Mon, 17 Mar 2025 12:16:00 +0100
From: Danilo Krummrich <dakr@...nel.org>
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Tamir Duberstein <tamird@...il.com>,
Andrew Ballance <andrewjballance@...il.com>,
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>, rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] rust: alloc: replace `Vec::set_len` with `inc_len`
On Mon, Mar 17, 2025 at 10:50:15AM +0000, Alice Ryhl wrote:
> On Sun, Mar 16, 2025 at 06:32:00PM -0400, Tamir Duberstein wrote:
> > Rename `set_len` to `inc_len` and simplify its safety contract.
>
> You're missing a Signed-off-by tag.
>
> > rust/kernel/alloc/kvec.rs | 19 +++++++++----------
> > rust/kernel/str.rs | 2 +-
> > rust/kernel/uaccess.rs | 2 +-
> > 3 files changed, 11 insertions(+), 12 deletions(-)
> >
> > diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> > index ae9d072741ce..d43a1d609434 100644
> > --- a/rust/kernel/alloc/kvec.rs
> > +++ b/rust/kernel/alloc/kvec.rs
> > @@ -183,17 +183,16 @@ pub fn len(&self) -> usize {
> > self.len
> > }
> >
> > - /// Forcefully sets `self.len` to `new_len`.
> > + /// Increments `self.len` by `additional`.
> > ///
> > /// # Safety
> > ///
> > - /// - `new_len` must be less than or equal to [`Self::capacity`].
> > - /// - If `new_len` is greater than `self.len`, all elements within the interval
> > - /// [`self.len`,`new_len`) must be initialized.
> > + /// - `self.len + additional` must be less than or equal to [`Self::capacity`].
> > + /// - All elements within the interval [`self.len`,`self.len + additional`) must be initialized.
> > #[inline]
> > - pub unsafe fn set_len(&mut self, new_len: usize) {
> > - debug_assert!(new_len <= self.capacity());
> > - self.len = new_len;
> > + pub unsafe fn inc_len(&mut self, additional: usize) {
> > + debug_assert!(self.len() + additional <= self.capacity());
> > + self.len += additional;
>
> I guess we could use an INVARIANT: comment here.
Yeah, I fixed that up in a separate patch. I'm fine with Tamir picking it up or
doing it himself in a new one, etc. But I think this patch should only focus on
the rename.
Powered by blists - more mailing lists