The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] rust: dma: return zero for Coherent reads past EOF
@ 2026-07-20 19:21 Younes Akhouayri via B4 Relay
  2026-07-23 16:15 ` Miguel Ojeda
  2026-07-23 23:32 ` Gary Guo
  0 siblings, 2 replies; 9+ messages in thread
From: Younes Akhouayri via B4 Relay @ 2026-07-20 19:21 UTC (permalink / raw)
  To: Danilo Krummrich, Abdiel Janulgue, Daniel Almeida, Robin Murphy,
	Andreas Hindborg, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
	Tamir Duberstein, Alexandre Courbot, Onur Özkan, Timur Tabi
  Cc: driver-core, rust-for-linux, linux-kernel, Younes Akhouayri

From: Younes Akhouayri <git@younes.io>

Coherent<T>::write_to_slice() calculates a zero-byte copy when the file
offset is beyond the allocation, but still calls
UserSliceWriter::write_dma(). The latter rejects offsets beyond the
allocation even when the copy length is zero, so a debugfs read past EOF
returns -ERANGE.

Return before calling write_dma() when the offset is at or beyond the
allocation, matching simple_read_from_buffer() EOF semantics.

Fixes: 016818513936 ("rust: dma: implement BinaryWriter for Coherent<[u8]>")
Signed-off-by: Younes Akhouayri <git@younes.io>
---
 rust/kernel/dma.rs | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/rust/kernel/dma.rs b/rust/kernel/dma.rs
index 200def84fb69..36b72fb9ab46 100644
--- a/rust/kernel/dma.rs
+++ b/rust/kernel/dma.rs
@@ -1005,6 +1005,10 @@ fn write_to_slice(
             return Ok(0);
         };
 
+        if offset_val >= self.size() {
+            return Ok(0);
+        }
+
         let count = self.size().saturating_sub(offset_val).min(writer.len());
 
         writer.write_dma(self, offset_val, count)?;

---
base-commit: 880c43b185ca52239e75bc546cc4f4d9154d0fed
change-id: 20260720-fix-dma-coherent-eof-d0d08c91e013

Best regards,
--  
Younes Akhouayri <git@younes.io>



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

end of thread, other threads:[~2026-07-24  5:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 19:21 [PATCH] rust: dma: return zero for Coherent reads past EOF Younes Akhouayri via B4 Relay
2026-07-23 16:15 ` Miguel Ojeda
2026-07-23 23:32 ` Gary Guo
2026-07-24  0:18   ` Alexandre Courbot
2026-07-24  0:46     ` Gary Guo
2026-07-24  1:19       ` Alexandre Courbot
2026-07-24  2:12         ` Gary Guo
2026-07-24  1:22       ` Danilo Krummrich
2026-07-24  5:14         ` Alexandre Courbot

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