public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: dma: return EOVERFLOW instead of ENOMEM on size overflow
@ 2026-04-03 21:28 Aditya Rajan
  2026-04-04 13:15 ` Gary Guo
  2026-04-05  9:51 ` kernel test robot
  0 siblings, 2 replies; 7+ messages in thread
From: Aditya Rajan @ 2026-04-03 21:28 UTC (permalink / raw)
  To: dakr, ojeda
  Cc: abdiel.janulgue, daniel.almeida, robin.murphy, a.hindborg, boqun,
	gary, bjorn3_gh, lossin, aliceryhl, tmgross, driver-core,
	rust-for-linux, linux-kernel, Aditya Rajan

In alloc_slice_with_attrs(), the checked_mul() guards against
arithmetic overflow when computing the total byte size
(size_of::<T>() * len). If this overflows, the current code returns
ENOMEM, which is misleading -- the system is not out of memory, the
requested size simply cannot be represented in a usize.

Return EOVERFLOW instead, which accurately describes the failure. This
also distinguishes it from the actual allocation failure two lines
below, which correctly returns ENOMEM when dma_alloc_attrs() yields a
null pointer.

Fixes: d9aee73c56ee ("rust: dma: add generalized container for types other than slices")
Link: https://lore.kernel.org/all/20260320194626.36263-3-dakr@kernel.org/

Signed-off-by: Aditya Rajan <adi.dev.github@gmail.com>
---
 rust/kernel/dma.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 4995ee5dc689..179bc8832947 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -832,7 +832,7 @@ fn alloc_slice_with_attrs(
             Err(EINVAL)?;
         }
 
-        let size = core::mem::size_of::<T>().checked_mul(len).ok_or(ENOMEM)?;
+        let size = core::mem::size_of::<T>().checked_mul(len).ok_or(EOVERFLOW)?;
         let mut dma_handle = 0;
         // SAFETY: Device pointer is guaranteed as valid by the type invariant on `Device`.
         let addr = unsafe {
-- 
2.53.0


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

end of thread, other threads:[~2026-04-05  9:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03 21:28 [PATCH] rust: dma: return EOVERFLOW instead of ENOMEM on size overflow Aditya Rajan
2026-04-04 13:15 ` Gary Guo
2026-04-04 17:24   ` Aditya Rajan
2026-04-04 19:43     ` Danilo Krummrich
2026-04-04 20:13     ` Gary Guo
2026-04-04 20:28       ` Danilo Krummrich
2026-04-05  9:51 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox