]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: uaccess: add write_dma() for copying from DMA buffers to userspace
authorTimur Tabi <ttabi@nvidia.com>
Thu, 19 Mar 2026 21:26:54 +0000 (16:26 -0500)
committerDanilo Krummrich <dakr@kernel.org>
Wed, 25 Mar 2026 00:23:59 +0000 (01:23 +0100)
commit69bfce0f25c8f949f7a02c3ed93e36aadad3fa57
tree22c6bb62e40f52e644be16fb266c92c50f736ffb
parentd35ae50c5f48dfcd33cb24bf477ce912fa0af1f7
rust: uaccess: add write_dma() for copying from DMA buffers to userspace

Add UserSliceWriter::write_dma() to copy data from a Coherent<[u8]> to
userspace. This provides a safe interface for copying DMA buffer
contents to userspace without requiring callers to work with raw
pointers.

Because write_dma() and write_slice() have common code, factor that code
out into a helper function, write_raw().

The method handles bounds checking and offset calculation internally,
wrapping the unsafe copy_to_user() call.

Signed-off-by: Timur Tabi <ttabi@nvidia.com>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Tested-by: John Hubbard <jhubbard@nvidia.com>
Tested-by: Eliot Courtney <ecourtney@nvidia.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://patch.msgid.link/20260319212658.2541610-3-ttabi@nvidia.com
[ Rebase onto Coherent<T> changes; remove unnecessary turbofish from
  cast(). - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
rust/kernel/uaccess.rs