File tree 3 files changed +14
-10
lines changed
3 files changed +14
-10
lines changed Original file line number Diff line number Diff line change 4
4
//!
5
5
//! C header: [`include/uapi/asm-generic/errno-base.h`](../../../include/uapi/asm-generic/errno-base.h)
6
6
7
- use core:: num:: TryFromIntError ;
8
- use core:: str:: Utf8Error ;
9
-
10
- use alloc:: alloc:: AllocError ;
11
-
12
- use crate :: bindings;
13
- use crate :: c_types;
7
+ use crate :: { bindings, c_types} ;
8
+ use alloc:: { alloc:: AllocError , collections:: TryReserveError } ;
9
+ use core:: { num:: TryFromIntError , str:: Utf8Error } ;
14
10
15
11
/// Generic integer kernel error.
16
12
///
@@ -57,6 +53,12 @@ impl From<Utf8Error> for Error {
57
53
}
58
54
}
59
55
56
+ impl From < TryReserveError > for Error {
57
+ fn from ( _: TryReserveError ) -> Error {
58
+ Error :: ENOMEM
59
+ }
60
+ }
61
+
60
62
/// A [`Result`] with an [`Error`] error type.
61
63
///
62
64
/// To be used as the return type for functions that may fail.
Original file line number Diff line number Diff line change 12
12
//! do so first instead of bypassing this crate.
13
13
14
14
#![ no_std]
15
- #![ feature( allocator_api, alloc_error_handler) ]
15
+ #![ feature( allocator_api, alloc_error_handler, try_reserve ) ]
16
16
#![ deny( clippy:: complexity) ]
17
17
#![ deny( clippy:: correctness) ]
18
18
#![ deny( clippy:: perf) ]
Original file line number Diff line number Diff line change 5
5
//! C header: [`include/linux/uaccess.h`](../../../../include/linux/uaccess.h)
6
6
7
7
use crate :: { c_types, error, KernelResult } ;
8
- use alloc:: { vec, vec :: Vec } ;
8
+ use alloc:: vec:: Vec ;
9
9
use core:: mem:: { size_of, MaybeUninit } ;
10
10
11
11
extern "C" {
@@ -143,7 +143,9 @@ impl UserSlicePtrReader {
143
143
/// Returns `EFAULT` if the address does not currently point to
144
144
/// mapped, readable memory.
145
145
pub fn read_all ( & mut self ) -> KernelResult < Vec < u8 > > {
146
- let mut data = vec ! [ 0 ; self . 1 ] ;
146
+ let mut data = Vec :: < u8 > :: new ( ) ;
147
+ data. try_reserve_exact ( self . 1 ) ?;
148
+ data. resize ( self . 1 , 0 ) ;
147
149
// SAFETY: The output buffer is valid as we just allocated it.
148
150
unsafe { self . read_raw ( data. as_mut_ptr ( ) , data. len ( ) ) ? } ;
149
151
Ok ( data)
You can’t perform that action at this time.
0 commit comments