]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rust: alloc: introduce `ArrayLayout`
authorBenno Lossin <benno.lossin@proton.me>
Fri, 7 Mar 2025 22:49:41 +0000 (23:49 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 12:01:45 +0000 (13:01 +0100)
commit2dbf251264980198d6cc559e8d4d608ae6a3aa7a
treec093373bdddf94ba4ed021a354a7daeea78c44d6
parent22e1e850e24f3fa8e4df713e651f15cbdc89dd6b
rust: alloc: introduce `ArrayLayout`

commit 9e7bbfa182767f638ba61dba3518ff78da9f31ff upstream.

When allocating memory for arrays using allocators, the `Layout::array`
function is typically used. It returns a result, since the given size
might be too big. However, `Vec` and its iterators store their allocated
capacity and thus they already did check that the size is not too big.

The `ArrayLayout` type provides this exact behavior, as it can be
infallibly converted into a `Layout`. Instead of a `usize` capacity,
`Vec` and other similar array-storing types can use `ArrayLayout`
instead.

Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20241004154149.93856-16-dakr@kernel.org
[ Formatted a few comments. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/kernel/alloc.rs
rust/kernel/alloc/layout.rs [new file with mode: 0644]