All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: alloc: Fix `ArrayLayout` allocations
@ 2024-11-23 10:29 Asahi Lina
  2024-11-23 10:47 ` Neal Gompa
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Asahi Lina @ 2024-11-23 10:29 UTC (permalink / raw)
  To: Danilo Krummrich, Miguel Ojeda, Alex Gaynor, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross
  Cc: Janne Grunau, rust-for-linux, linux-kernel, asahi, Asahi Lina

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: 9e7bbfa18276 ("rust: alloc: introduce `ArrayLayout`")
Signed-off-by: Asahi Lina <lina@asahilina.net>
---
 rust/kernel/alloc/layout.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/alloc/layout.rs b/rust/kernel/alloc/layout.rs
index 7e0c2f46157b772248450a77ff445091e17fdfd7..4b3cd7fdc816c158e63ac74014cbfc0794547e81 100644
--- a/rust/kernel/alloc/layout.rs
+++ b/rust/kernel/alloc/layout.rs
@@ -45,7 +45,7 @@ pub const fn empty() -> Self {
     /// 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,

---
base-commit: b2603f8ac8217bc59f5c7f248ac248423b9b99cb
change-id: 20241123-rust-fix-arraylayout-0b1009d89fb7

Cheers,
~~ Lina


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-11-25 16:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-23 10:29 [PATCH] rust: alloc: Fix `ArrayLayout` allocations Asahi Lina
2024-11-23 10:47 ` Neal Gompa
2024-11-23 17:39 ` Miguel Ojeda
2024-11-23 17:49   ` Miguel Ojeda
2024-11-25 16:20   ` Boqun Feng
2024-11-25 16:26     ` Miguel Ojeda
2024-11-23 20:08 ` Danilo Krummrich
2024-11-23 21:55   ` Janne Grunau
2024-11-24 23:56 ` Miguel Ojeda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.