UPSTREAM: 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: https://github.com/Rust-for-Linux/linux/issues/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> Bug: 414994413 (cherry picked from commit c80dd3fc45d573458bc763d599d97c82cf5dc212) Change-Id: Idecc14884233ada0eeae3e4adefcd1205fdbf0fb Signed-off-by: Alice Ryhl <aliceryhl@google.com>
This commit is contained in:
committed by
Matthew Maurer
parent
0690b3438b
commit
615a5b6d7e
@@ -5,7 +5,7 @@
|
||||
//! C header: [`include/linux/uaccess.h`](srctree/include/linux/uaccess.h)
|
||||
|
||||
use crate::{
|
||||
alloc::Flags,
|
||||
alloc::{Allocator, Flags},
|
||||
bindings,
|
||||
error::Result,
|
||||
ffi::c_void,
|
||||
@@ -127,7 +127,7 @@ impl UserSlice {
|
||||
/// Reads the entirety of the user slice, appending it to the end of the provided buffer.
|
||||
///
|
||||
/// Fails with [`EFAULT`] if the read happens on a bad address.
|
||||
pub fn read_all(self, buf: &mut KVec<u8>, flags: Flags) -> Result {
|
||||
pub fn read_all<A: Allocator>(self, buf: &mut Vec<u8, A>, flags: Flags) -> Result {
|
||||
self.reader().read_all(buf, flags)
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ impl UserSliceReader {
|
||||
/// Reads the entirety of the user slice, appending it to the end of the provided buffer.
|
||||
///
|
||||
/// Fails with [`EFAULT`] if the read happens on a bad address.
|
||||
pub fn read_all(mut self, buf: &mut KVec<u8>, flags: Flags) -> Result {
|
||||
pub fn read_all<A: Allocator>(mut self, buf: &mut Vec<u8, A>, flags: Flags) -> Result {
|
||||
let len = self.length;
|
||||
buf.reserve(len, flags)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user