Re: [PATCH] rust: alloc: add missing trait item MIN_ALIGN to Cmalloc
From: Alice Ryhl <aliceryhl@google.com>
Date: 2025-08-24 12:36:42
Also in:
linux-mm
On Sun, Aug 24, 2025 at 2:07 PM Danilo Krummrich [off-list ref] wrote:
Cmalloc is missing the trait item MIN_ALIGN introduced by commit
1b1a946dc2b5 ("rust: alloc: specify the minimum alignment of each
allocator"), causing the following error on the `rusttest` make target.
error[E0046]: not all trait items implemented, missing: `MIN_ALIGN`
--> rust/kernel/alloc/allocator_test.rs:37:1
|
37 | unsafe impl Allocator for Cmalloc {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `MIN_ALIGN` in implementation
|
::: rust/kernel/alloc.rs:146:5
|
146 | const MIN_ALIGN: usize;
| ---------------------- `MIN_ALIGN` from trait
Implement MIN_ALIGN for Cmalloc to fix this.
Reported-by: Miguel Ojeda <redacted>
Closes: https://lore.kernel.org/all/CANiq72k0FSBTB2yOjiAy9PnAuyM=-PHxL3uQQ_Cv+zwswnr_bA@mail.gmail.com/ (local)
Fixes: 1b1a946dc2b5 ("rust: alloc: specify the minimum alignment of each allocator")
Signed-off-by: Danilo Krummrich <dakr@kernel.org>Thanks for taking of it. Assuming a satisfactory answer to the quesiton below: Reviewed-by: Alice Ryhl <aliceryhl@google.com>
quoted hunk ↗ jump to hunk
--- rust/kernel/alloc/allocator_test.rs | 2 ++ 1 file changed, 2 insertions(+)diff --git a/rust/kernel/alloc/allocator_test.rs b/rust/kernel/alloc/allocator_test.rs index a3074480bd8d..0d3c78ddcd69 100644 --- a/rust/kernel/alloc/allocator_test.rs +++ b/rust/kernel/alloc/allocator_test.rs@@ -35,6 +35,8 @@ // - passing a pointer to a valid memory allocation created by this `Allocator` is always OK, // - `realloc` provides the guarantees as provided in the `# Guarantees` section. unsafe impl Allocator for Cmalloc { + const MIN_ALIGN: usize = bindings::ARCH_KMALLOC_MINALIGN;
Is this the right value for normal malloc? Alice