Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+7 -1
+7 -1
rust/kernel/uaccess.rs
··· 12 12 ffi::{c_char, c_void}, 13 13 fs::file, 14 14 prelude::*, 15 + ptr::KnownSize, 15 16 transmute::{AsBytes, FromBytes}, 16 17 }; 17 18 use core::mem::{size_of, MaybeUninit}; ··· 525 524 /// writer.write_dma(alloc, 0, 256) 526 525 /// } 527 526 /// ``` 528 - pub fn write_dma(&mut self, alloc: &Coherent<[u8]>, offset: usize, count: usize) -> Result { 527 + pub fn write_dma<T: KnownSize + AsBytes + ?Sized>( 528 + &mut self, 529 + alloc: &Coherent<T>, 530 + offset: usize, 531 + count: usize, 532 + ) -> Result { 529 533 let len = alloc.size(); 530 534 if offset.checked_add(count).ok_or(EOVERFLOW)? > len { 531 535 return Err(ERANGE);