summaryrefslogtreecommitdiff
path: root/rust
diff options
context:
space:
mode:
authorDanilo Krummrich <dakr@kernel.org>2025-03-15 16:43:02 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-06-19 15:32:09 +0200
commit6635bb78eb7d7e6b61f11802b2b18858e8561c9a (patch)
tree1a40fb69e0292241615b90465bbfe96d31e6ac50 /rust
parent48ca7139ab7f0bbed95ff7a901ea497017769657 (diff)
downloadlinux-6635bb78eb7d7e6b61f11802b2b18858e8561c9a.tar.gz
linux-6635bb78eb7d7e6b61f11802b2b18858e8561c9a.tar.bz2
linux-6635bb78eb7d7e6b61f11802b2b18858e8561c9a.zip
rust: alloc: add missing invariant in Vec::set_len()
[ Upstream commit fb1bf1067de979c89ae33589e0466d6ce0dde204 ] When setting a new length, we have to justify that the set length represents the exact number of elements stored in the vector. Reviewed-by: Benno Lossin <benno.lossin@proton.me> Reported-by: Alice Ryhl <aliceryhl@google.com> Closes: https://lore.kernel.org/rust-for-linux/20250311-iov-iter-v1-4-f6c9134ea824@google.com Fixes: 2aac4cd7dae3 ("rust: alloc: implement kernel `Vec` type") Link: https://lore.kernel.org/r/20250315154436.65065-2-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'rust')
-rw-r--r--rust/kernel/alloc/kvec.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs
index 87a71fd40c3c..f62204fe563f 100644
--- a/rust/kernel/alloc/kvec.rs
+++ b/rust/kernel/alloc/kvec.rs
@@ -196,6 +196,9 @@ where
#[inline]
pub unsafe fn set_len(&mut self, new_len: usize) {
debug_assert!(new_len <= self.capacity());
+
+ // INVARIANT: By the safety requirements of this method `new_len` represents the exact
+ // number of elements stored within `self`.
self.len = new_len;
}