summaryrefslogtreecommitdiff
path: root/rust/kernel/alloc.rs
diff options
context:
space:
mode:
authorBenno Lossin <benno.lossin@proton.me>2024-10-04 17:41:19 +0200
committerMiguel Ojeda <ojeda@kernel.org>2024-10-15 22:56:59 +0200
commit9e7bbfa182767f638ba61dba3518ff78da9f31ff (patch)
tree14eb2ad72802d1ca4a23f31b2a66250deb105cbd /rust/kernel/alloc.rs
parente1044c2238f54ae5bd902cac6d12e48835df418b (diff)
rust: alloc: introduce `ArrayLayout`
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>
Diffstat (limited to 'rust/kernel/alloc.rs')
-rw-r--r--rust/kernel/alloc.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/rust/kernel/alloc.rs b/rust/kernel/alloc.rs
index 94f4de5e0cdc..c679d93b0523 100644
--- a/rust/kernel/alloc.rs
+++ b/rust/kernel/alloc.rs
@@ -5,6 +5,7 @@
#[cfg(not(any(test, testlib)))]
pub mod allocator;
pub mod kbox;
+pub mod layout;
pub mod vec_ext;
#[cfg(any(test, testlib))]