@@ -11,7 +11,6 @@ use crate::{
1111 prelude:: * ,
1212 transmute:: { AsBytes , FromBytes } ,
1313} ;
14- use alloc:: vec:: Vec ;
1514use core:: ffi:: { c_ulong, c_void} ;
1615use core:: mem:: { size_of, MaybeUninit } ;
1716
@@ -46,15 +45,14 @@ pub type UserPtr = usize;
4645/// every byte in the region.
4746///
4847/// ```no_run
49- /// use alloc::vec::Vec;
5048/// use core::ffi::c_void;
5149/// use kernel::error::Result;
5250/// use kernel::uaccess::{UserPtr, UserSlice};
5351///
5452/// fn bytes_add_one(uptr: UserPtr, len: usize) -> Result<()> {
5553/// let (read, mut write) = UserSlice::new(uptr, len).reader_writer();
5654///
57- /// let mut buf = Vec ::new();
55+ /// let mut buf = KVec ::new();
5856/// read.read_all(&mut buf, GFP_KERNEL)?;
5957///
6058/// for b in &mut buf {
@@ -69,7 +67,6 @@ pub type UserPtr = usize;
6967/// Example illustrating a TOCTOU (time-of-check to time-of-use) bug.
7068///
7169/// ```no_run
72- /// use alloc::vec::Vec;
7370/// use core::ffi::c_void;
7471/// use kernel::error::{code::EINVAL, Result};
7572/// use kernel::uaccess::{UserPtr, UserSlice};
@@ -78,21 +75,21 @@ pub type UserPtr = usize;
7875/// fn is_valid(uptr: UserPtr, len: usize) -> Result<bool> {
7976/// let read = UserSlice::new(uptr, len).reader();
8077///
81- /// let mut buf = Vec ::new();
78+ /// let mut buf = KVec ::new();
8279/// read.read_all(&mut buf, GFP_KERNEL)?;
8380///
8481/// todo!()
8582/// }
8683///
8784/// /// Returns the bytes behind this user pointer if they are valid.
88- /// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<Vec <u8>> {
85+ /// fn get_bytes_if_valid(uptr: UserPtr, len: usize) -> Result<KVec <u8>> {
8986/// if !is_valid(uptr, len)? {
9087/// return Err(EINVAL);
9188/// }
9289///
9390/// let read = UserSlice::new(uptr, len).reader();
9491///
95- /// let mut buf = Vec ::new();
92+ /// let mut buf = KVec ::new();
9693/// read.read_all(&mut buf, GFP_KERNEL)?;
9794///
9895/// // THIS IS A BUG! The bytes could have changed since we checked them.
@@ -130,7 +127,7 @@ impl UserSlice {
130127 /// Reads the entirety of the user slice, appending it to the end of the provided buffer.
131128 ///
132129 /// Fails with [`EFAULT`] if the read happens on a bad address.
133- pub fn read_all ( self , buf : & mut Vec < u8 > , flags : Flags ) -> Result {
130+ pub fn read_all ( self , buf : & mut KVec < u8 > , flags : Flags ) -> Result {
134131 self . reader ( ) . read_all ( buf, flags)
135132 }
136133
@@ -291,9 +288,9 @@ impl UserSliceReader {
291288 /// Reads the entirety of the user slice, appending it to the end of the provided buffer.
292289 ///
293290 /// Fails with [`EFAULT`] if the read happens on a bad address.
294- pub fn read_all ( mut self , buf : & mut Vec < u8 > , flags : Flags ) -> Result {
291+ pub fn read_all ( mut self , buf : & mut KVec < u8 > , flags : Flags ) -> Result {
295292 let len = self . length ;
296- VecExt :: < u8 > :: reserve ( buf , len, flags) ?;
293+ buf . reserve ( len, flags) ?;
297294
298295 // The call to `try_reserve` was successful, so the spare capacity is at least `len` bytes
299296 // long.
0 commit comments