From: Danilo Krummrich Date: Wed, 25 Mar 2026 00:39:15 +0000 (+0100) Subject: rust: uaccess: generalize write_dma() to accept any Coherent X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25fe63db0024da172457055532c96bef924a8c78;p=thirdparty%2Flinux.git rust: uaccess: generalize write_dma() to accept any Coherent Generalize write_dma() from &Coherent<[u8]> to &Coherent 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 Acked-by: Gary Guo Reviewed-by: Alexandre Courbot Reviewed-by: Alice Ryhl Link: https://patch.msgid.link/20260325003921.3420-1-dakr@kernel.org Signed-off-by: Danilo Krummrich --- diff --git a/rust/kernel/uaccess.rs b/rust/kernel/uaccess.rs index e26ef90ba8adf..6c9c1cce3c63f 100644 --- a/rust/kernel/uaccess.rs +++ b/rust/kernel/uaccess.rs @@ -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( + &mut self, + alloc: &Coherent, + offset: usize, + count: usize, + ) -> Result { let len = alloc.size(); if offset.checked_add(count).ok_or(EOVERFLOW)? > len { return Err(ERANGE);