aboutsummaryrefslogtreecommitdiff
path: root/rust/kernel
diff options
context:
space:
mode:
authorAsahi Lina <[email protected]>2024-11-23 19:29:38 +0900
committerMiguel Ojeda <[email protected]>2024-11-25 00:11:07 +0100
commitb7ed2b6f4e8d7f64649795e76ee9db67300de8eb (patch)
tree6c52dd614e82d4577d777576a18f87d8d2751196 /rust/kernel
parentb160dc46dd9af4001c802cc9c7d68b6ba58d27c4 (diff)
rust: alloc: Fix `ArrayLayout` allocations
We were accidentally allocating a layout for the *square* of the object size due to a variable shadowing mishap. Fixes memory bloat and page allocation failures in drm/asahi. Reported-by: Janne Grunau <[email protected]> Fixes: 9e7bbfa18276 ("rust: alloc: introduce `ArrayLayout`") Signed-off-by: Asahi Lina <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Reviewed-by: Neal Gompa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
Diffstat (limited to 'rust/kernel')
-rw-r--r--rust/kernel/alloc/layout.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/rust/kernel/alloc/layout.rs b/rust/kernel/alloc/layout.rs
index 7e0c2f46157b..4b3cd7fdc816 100644
--- a/rust/kernel/alloc/layout.rs
+++ b/rust/kernel/alloc/layout.rs
@@ -45,7 +45,7 @@ impl<T> ArrayLayout<T> {
/// When `len * size_of::<T>()` overflows or when `len * size_of::<T>() > isize::MAX`.
pub const fn new(len: usize) -> Result<Self, LayoutError> {
match len.checked_mul(core::mem::size_of::<T>()) {
- Some(len) if len <= ISIZE_MAX => {
+ Some(size) if size <= ISIZE_MAX => {
// INVARIANT: We checked above that `len * size_of::<T>() <= isize::MAX`.
Ok(Self {
len,