Skip to content

Commit b7ed2b6

Browse files
asahilinaojeda
authored andcommitted
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 <j@jannau.net> Fixes: 9e7bbfa ("rust: alloc: introduce `ArrayLayout`") Signed-off-by: Asahi Lina <lina@asahilina.net> Acked-by: Danilo Krummrich <dakr@kernel.org> Reviewed-by: Neal Gompa <neal@gompa.dev> Link: https://lore.kernel.org/r/20241123-rust-fix-arraylayout-v1-1-197e64c95bd4@asahilina.net Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent b160dc4 commit b7ed2b6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rust/kernel/alloc/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<T> ArrayLayout<T> {
4545
/// When `len * size_of::<T>()` overflows or when `len * size_of::<T>() > isize::MAX`.
4646
pub const fn new(len: usize) -> Result<Self, LayoutError> {
4747
match len.checked_mul(core::mem::size_of::<T>()) {
48-
Some(len) if len <= ISIZE_MAX => {
48+
Some(size) if size <= ISIZE_MAX => {
4949
// INVARIANT: We checked above that `len * size_of::<T>() <= isize::MAX`.
5050
Ok(Self {
5151
len,

0 commit comments

Comments
 (0)