]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: uaccess: generalize write_dma() to accept any Coherent<T>
authorDanilo Krummrich <dakr@kernel.org>
Wed, 25 Mar 2026 00:39:15 +0000 (01:39 +0100)
committerDanilo Krummrich <dakr@kernel.org>
Fri, 27 Mar 2026 20:48:09 +0000 (21:48 +0100)
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.

Acked-by: Miguel Ojeda <ojeda@kernel.org>
Acked-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260325003921.3420-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/uaccess.rs

index e26ef90ba8adf9182e727a6e071f3e5f1ca0f5ab..6c9c1cce3c63f906a49f6e466d8f155912864918 100644 (file)
@@ -12,6 +12,7 @@ use crate::{
     ffi::{c_char, c_void},
     fs::file,
     prelude::*,
+    ptr::KnownSize,
     transmute::{AsBytes, FromBytes},
 };
 use core::mem::{size_of, MaybeUninit};
@@ -524,7 +525,12 @@ impl UserSliceWriter {
     ///     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);