Skip to content

Commit 4218de6

Browse files
Darksonnjannau
authored andcommitted
rust: alloc: add Vec::push_within_capacity
This introduces a new method called `push_within_capacity` for appending to a vector without attempting to allocate if the capacity is full. Rust Binder will use this in various places to safely push to a vector while holding a spinlock. The implementation is moved to a push_within_capacity_unchecked method. This is preferred over having push() call push_within_capacity() followed by an unwrap_unchecked() for simpler unsafe. Panics in the kernel are best avoided when possible, so an error is returned if the vector does not have sufficient capacity. An error type is used rather than just returning Result<(),T> to make it more convenient for callers (i.e. they can use ? or unwrap). Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Benno Lossin <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Remove public visibility from `Vec::push_within_capacity_unchecked()`. - Danilo ] Signed-off-by: Danilo Krummrich <[email protected]>
1 parent 3fba873 commit 4218de6

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

rust/kernel/alloc/kvec.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change

rust/kernel/alloc/kvec/errors.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change

0 commit comments

Comments
 (0)