Skip to content

Commit

Permalink
rust: alloc: Fix ArrayLayout allocations
Browse files Browse the repository at this point in the history
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: 9e7bbfa ("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]>
  • Loading branch information
asahilina authored and ojeda committed Nov 24, 2024
1 parent b160dc4 commit b7ed2b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rust/kernel/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b7ed2b6

Please sign in to comment.