Skip to content

Commit c80dd3f

Browse files
felipeaggerojeda
authored andcommitted
rust: uaccess: generalize userSliceReader to support any Vec
The UserSliceReader::read_all function is currently restricted to use only Vec with the kmalloc allocator. However, there is no reason for this limitation. This patch generalizes the function to accept any Vec regardless of the allocator used. There's a use-case for a KVVec in Binder to avoid maximum sizes for a certain array. Link: #1136 Signed-off-by: Filipe Xavier <felipeaggger@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Link: https://lore.kernel.org/r/20250107-gen-userslice-readall-alloc-v2-1-d7fe4d19241a@gmail.com [ Reflowed and slightly reworded title. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent c27e705 commit c80dd3f

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

rust/kernel/uaccess.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! C header: [`include/linux/uaccess.h`](srctree/include/linux/uaccess.h)
66
77
use crate::{
8-
alloc::Flags,
8+
alloc::{Allocator, Flags},
99
bindings,
1010
error::Result,
1111
ffi::c_void,
@@ -127,7 +127,7 @@ impl UserSlice {
127127
/// Reads the entirety of the user slice, appending it to the end of the provided buffer.
128128
///
129129
/// Fails with [`EFAULT`] if the read happens on a bad address.
130-
pub fn read_all(self, buf: &mut KVec<u8>, flags: Flags) -> Result {
130+
pub fn read_all<A: Allocator>(self, buf: &mut Vec<u8, A>, flags: Flags) -> Result {
131131
self.reader().read_all(buf, flags)
132132
}
133133

@@ -281,7 +281,7 @@ impl UserSliceReader {
281281
/// Reads the entirety of the user slice, appending it to the end of the provided buffer.
282282
///
283283
/// Fails with [`EFAULT`] if the read happens on a bad address.
284-
pub fn read_all(mut self, buf: &mut KVec<u8>, flags: Flags) -> Result {
284+
pub fn read_all<A: Allocator>(mut self, buf: &mut Vec<u8, A>, flags: Flags) -> Result {
285285
let len = self.length;
286286
buf.reserve(len, flags)?;
287287

0 commit comments

Comments
 (0)