rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rust: alloc: extend safety requirements of Vec::set_len()
@ 2025-03-15 15:43 Danilo Krummrich
  2025-03-15 15:43 ` [PATCH 2/2] rust: alloc: add missing invariant in Vec::set_len() Danilo Krummrich
                   ` (3 more replies)
  0 siblings, 4 replies; 34+ messages in thread
From: Danilo Krummrich @ 2025-03-15 15:43 UTC (permalink / raw)
  To: ojeda, alex.gaynor, boqun.feng, gary, bjorn3_gh, benno.lossin,
	a.hindborg, aliceryhl, tmgross
  Cc: andrewjballance, rust-for-linux, Danilo Krummrich

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.
     #[inline]
     pub unsafe fn set_len(&mut self, new_len: usize) {
         debug_assert!(new_len <= self.capacity());

base-commit: 80e54e84911a923c40d7bee33a34c1b4be148d7a
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2025-04-07 12:10 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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 NNTP newsgroup(s).