File tree 4 files changed +10
-15
lines changed 4 files changed +10
-15
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use core:: num:: TryFromIntError ;
4
4
5
+ use alloc:: alloc:: AllocError ;
6
+
5
7
use crate :: bindings;
6
8
use crate :: c_types;
7
9
@@ -30,3 +32,9 @@ impl From<TryFromIntError> for Error {
30
32
}
31
33
32
34
pub type KernelResult < T > = Result < T , Error > ;
35
+
36
+ impl From < AllocError > for Error {
37
+ fn from ( _: AllocError ) -> Error {
38
+ Error :: ENOMEM
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -59,15 +59,3 @@ fn panic(_info: &PanicInfo) -> ! {
59
59
60
60
#[ global_allocator]
61
61
static ALLOCATOR : allocator:: KernelAllocator = allocator:: KernelAllocator ;
62
-
63
- /// Attempts to allocate memory for `value` using the global allocator. On success, `value` is
64
- /// moved into it and returned to the caller wrapped in a `Box`.
65
- pub fn try_alloc < T > ( value : T ) -> KernelResult < Box < T > > {
66
- Box :: try_new ( value) . map_err ( |_| Error :: ENOMEM )
67
- }
68
-
69
- /// Attempts to allocate memory for `value` using the global allocator. On success, `value` is
70
- /// moved into it and returned to the caller wrapped in a pinned `Box`.
71
- pub fn try_alloc_pinned < T > ( value : T ) -> KernelResult < Pin < Box < T > > > {
72
- Ok ( Pin :: from ( try_alloc ( value) ?) )
73
- }
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ impl Registration {
28
28
name : CStr < ' static > ,
29
29
minor : Option < i32 > ,
30
30
) -> KernelResult < Pin < Box < Self > > > {
31
- let mut r = crate :: try_alloc_pinned ( Self :: new ( ) ) ?;
31
+ let mut r = Pin :: from ( Box :: try_new ( Self :: new ( ) ) ?) ;
32
32
r. as_mut ( ) . register :: < T > ( name, minor) ?;
33
33
Ok ( r)
34
34
}
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ use core::sync::atomic;
9
9
use crate :: bindings;
10
10
use crate :: c_types;
11
11
use crate :: error;
12
- use crate :: try_alloc;
13
12
use crate :: types;
14
13
use crate :: user_ptr:: { UserSlicePtr , UserSlicePtrWriter } ;
15
14
@@ -130,7 +129,7 @@ impl<T: SysctlStorage> Sysctl<T> {
130
129
return Err ( error:: Error :: EINVAL ) ;
131
130
}
132
131
133
- let storage = try_alloc ( storage) ?;
132
+ let storage = Box :: try_new ( storage) ?;
134
133
let mut table = vec ! [
135
134
bindings:: ctl_table {
136
135
procname: name. as_ptr( ) as * const i8 ,
You can’t perform that action at this time.
0 commit comments