All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alice Ryhl <aliceryhl@google.com>
To: Danilo Krummrich <dakr@kernel.org>
Cc: ojeda@kernel.org, alex.gaynor@gmail.com, boqun.feng@gmail.com,
	 gary@garyguo.net, bjorn3_gh@protonmail.com,
	benno.lossin@proton.me,  a.hindborg@kernel.org,
	tmgross@umich.edu, andrewjballance@gmail.com,
	 rust-for-linux@vger.kernel.org
Subject: Re: [PATCH 1/2] rust: alloc: extend safety requirements of Vec::set_len()
Date: Mon, 17 Mar 2025 10:36:12 +0000	[thread overview]
Message-ID: <Z9f7HEpqiMNnwsLQ@google.com> (raw)
In-Reply-To: <20250315154436.65065-1-dakr@kernel.org>

On Sat, Mar 15, 2025 at 04:43:01PM +0100, Danilo Krummrich wrote:
> Extend the safety requirements of set_len() to consider the case when
> the new length is smaller than the old length.
> 
> Fixes: 2aac4cd7dae3 ("rust: alloc: implement kernel `Vec` type")
> Signed-off-by: Danilo Krummrich <dakr@kernel.org>
> ---
>  rust/kernel/alloc/kvec.rs | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
> index ae9d072741ce..8540d9e2b717 100644
> --- a/rust/kernel/alloc/kvec.rs
> +++ b/rust/kernel/alloc/kvec.rs
> @@ -189,7 +189,9 @@ pub fn len(&self) -> usize {
>      ///
>      /// - `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`,`new_len`) must be initialized,
> +    /// - if `new_len` is smaller than `self.len`, all elements within the interval
> +    ///   [`new_len`, `self.len`) must either be dropped or copied and taken ownership of.

This should not be a safety requirement. How about instead adding a
guarantee to the caller that the caller may safely take ownership of the
values?

Alice

  parent reply	other threads:[~2025-03-17 10:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-15 15:43 [PATCH 1/2] rust: alloc: extend safety requirements of Vec::set_len() Danilo Krummrich
2025-03-15 15:43 ` [PATCH 2/2] rust: alloc: add missing invariant in Vec::set_len() Danilo Krummrich
2025-03-15 15:52   ` Danilo Krummrich
2025-03-15 17:44   ` Benno Lossin
2025-04-07 12:10   ` Danilo Krummrich
2025-03-15 16:06 ` [PATCH 1/2] rust: alloc: extend safety requirements of Vec::set_len() Tamir Duberstein
2025-03-15 17:44 ` Benno Lossin
2025-03-15 18:36   ` Danilo Krummrich
2025-03-16  0:33     ` Tamir Duberstein
2025-03-16  9:38       ` Benno Lossin
2025-03-16 12:31         ` Danilo Krummrich
2025-03-16 12:42           ` Tamir Duberstein
2025-03-16 13:01             ` Danilo Krummrich
2025-03-16 13:13               ` Tamir Duberstein
2025-03-16 13:46                 ` Danilo Krummrich
2025-03-16 17:40                   ` Benno Lossin
2025-03-16 18:59                     ` Danilo Krummrich
2025-03-16 19:09                       ` Danilo Krummrich
2025-03-16 19:30                         ` Tamir Duberstein
2025-03-16 20:54                           ` Danilo Krummrich
2025-03-16 21:10                             ` Tamir Duberstein
2025-03-16 21:17                               ` Danilo Krummrich
2025-03-16 21:20                                 ` Tamir Duberstein
2025-03-16 21:52                                   ` Tamir Duberstein
2025-03-16 21:59                                     ` Danilo Krummrich
2025-03-17  9:52                         ` Benno Lossin
2025-03-17 11:12                           ` Danilo Krummrich
2025-03-17 14:57                             ` Benno Lossin
2025-03-17 15:57                               ` Danilo Krummrich
2025-03-17 16:03                                 ` Miguel Ojeda
2025-03-17 17:33                                 ` Benno Lossin
2025-03-17 18:28                                   ` Danilo Krummrich
2025-03-16 12:08       ` Danilo Krummrich
2025-03-17 10:36 ` Alice Ryhl [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-03-17  9:46 Benno Lossin

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=Z9f7HEpqiMNnwsLQ@google.com \
    --to=aliceryhl@google.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=andrewjballance@gmail.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=gary@garyguo.net \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.