Skip to content

Commit 25fe63d

Browse files
author
Danilo Krummrich
committed
rust: uaccess: generalize write_dma() to accept any Coherent<T>
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>
1 parent 80df573 commit 25fe63d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

rust/kernel/uaccess.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
ffi::{c_char, c_void},
1313
fs::file,
1414
prelude::*,
15+
ptr::KnownSize,
1516
transmute::{AsBytes, FromBytes},
1617
};
1718
use core::mem::{size_of, MaybeUninit};
@@ -524,7 +525,12 @@ impl UserSliceWriter {
524525
/// writer.write_dma(alloc, 0, 256)
525526
/// }
526527
/// ```
527-
pub fn write_dma(&mut self, alloc: &Coherent<[u8]>, offset: usize, count: usize) -> Result {
528+
pub fn write_dma<T: KnownSize + AsBytes + ?Sized>(
529+
&mut self,
530+
alloc: &Coherent<T>,
531+
offset: usize,
532+
count: usize,
533+
) -> Result {
528534
let len = alloc.size();
529535
if offset.checked_add(count).ok_or(EOVERFLOW)? > len {
530536
return Err(ERANGE);

0 commit comments

Comments
 (0)