public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] rust: uaccess: generalize write_dma() to accept any Coherent<T>
@ 2026-03-25  0:39 Danilo Krummrich
  2026-03-25  0:39 ` [PATCH 2/3] rust: dma: generalize BinaryWriter impl for Coherent<T> Danilo Krummrich
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Danilo Krummrich @ 2026-03-25  0:39 UTC (permalink / raw)
  To: acourbot, aliceryhl, abdiel.janulgue, daniel.almeida,
	robin.murphy, a.hindborg, ojeda, boqun, gary, bjorn3_gh, lossin,
	tmgross, ttabi
  Cc: nouveau, dri-devel, linux-kernel, driver-core, rust-for-linux,
	Danilo Krummrich

Generalize write_dma() from &Coherent<[u8]> to &Coherent<T> where
T: KnownSize + AsBytes + ?Sized. The function body only uses as_ptr()
and size(), which work for any such T, so there is no reason to
restrict it to byte slices.

Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
 rust/kernel/uaccess.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs
index e26ef90ba8ad..6c9c1cce3c63 100644
--- a/rust/kernel/uaccess.rs
+++ b/rust/kernel/uaccess.rs
@@ -12,6 +12,7 @@
     ffi::{c_char, c_void},
     fs::file,
     prelude::*,
+    ptr::KnownSize,
     transmute::{AsBytes, FromBytes},
 };
 use core::mem::{size_of, MaybeUninit};
@@ -524,7 +525,12 @@ pub fn write_slice(&mut self, data: &[u8]) -> Result {
     ///     writer.write_dma(alloc, 0, 256)
     /// }
     /// ```
-    pub fn write_dma(&mut self, alloc: &Coherent<[u8]>, offset: usize, count: usize) -> Result {
+    pub fn write_dma<T: KnownSize + AsBytes + ?Sized>(
+        &mut self,
+        alloc: &Coherent<T>,
+        offset: usize,
+        count: usize,
+    ) -> Result {
         let len = alloc.size();
         if offset.checked_add(count).ok_or(EOVERFLOW)? > len {
             return Err(ERANGE);

base-commit: dff8302ca1d0e773c90dbeeb05e759f995c95482
-- 
2.53.0


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

end of thread, other threads:[~2026-03-26 18:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-25  0:39 [PATCH 1/3] rust: uaccess: generalize write_dma() to accept any Coherent<T> Danilo Krummrich
2026-03-25  0:39 ` [PATCH 2/3] rust: dma: generalize BinaryWriter impl for Coherent<T> Danilo Krummrich
2026-03-25  0:39 ` [PATCH 3/3] gpu: nova-core: use sized array for GSP log buffers Danilo Krummrich
2026-03-25 11:44 ` [PATCH 1/3] rust: uaccess: generalize write_dma() to accept any Coherent<T> Alice Ryhl
2026-03-25 13:01 ` Gary Guo
2026-03-25 13:46   ` Danilo Krummrich
2026-03-25 14:55     ` Gary Guo
2026-03-26  0:39 ` Alexandre Courbot
2026-03-26 13:33 ` Gary Guo
2026-03-26 18:17 ` Miguel Ojeda

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