File tree 3 files changed +6
-4
lines changed
3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use alloc::boxed::Box;
8
8
use crate :: bindings;
9
9
use crate :: c_types;
10
10
use crate :: error:: { Error , KernelResult } ;
11
+ use crate :: try_alloc;
11
12
use crate :: user_ptr:: { UserSlicePtr , UserSlicePtrReader , UserSlicePtrWriter } ;
12
13
13
14
bitflags:: bitflags! {
@@ -65,7 +66,7 @@ unsafe extern "C" fn open_callback<T: FileOperations>(
65
66
file : * mut bindings:: file ,
66
67
) -> c_types:: c_int {
67
68
from_kernel_result ! {
68
- let f = Box :: new ( T :: open( ) ?) ;
69
+ let f = try_alloc ( T :: open( ) ?) ? ;
69
70
( * file) . private_data = Box :: into_raw( f) as * mut c_types:: c_void;
70
71
Ok ( 0 )
71
72
}
@@ -232,7 +233,7 @@ pub trait FileOperations: Sync + Sized {
232
233
/// pointer in `struct file_operations`.
233
234
const SEEK : SeekFn < Self > = None ;
234
235
235
- /// Syncs pending changes to this file. Corresponds to the `fsync` function
236
+ /// Syncs pending changes to this file. Corresponds to the `fsync` function
236
237
/// pointer in the `struct file_operations`.
237
238
const FSYNC : FSync < Self > = None ;
238
239
}
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ pub fn try_alloc<T>(value: T) -> KernelResult<Box<T>> {
68
68
let layout = Layout :: new :: < MaybeUninit < T > > ( ) ;
69
69
let ptr: NonNull < MaybeUninit < T > > = if layout. size ( ) == 0 {
70
70
NonNull :: dangling ( )
71
- // SAFETY: We checked that the layout size is nonzero.
71
+ // SAFETY: We checked that the layout size is nonzero.
72
72
} else if let Some ( nn) = NonNull :: new ( unsafe { alloc:: alloc:: alloc ( layout) } ) {
73
73
nn. cast ( )
74
74
} else {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ 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;
12
13
use crate :: types;
13
14
use crate :: user_ptr:: { UserSlicePtr , UserSlicePtrWriter } ;
14
15
@@ -129,7 +130,7 @@ impl<T: SysctlStorage> Sysctl<T> {
129
130
return Err ( error:: Error :: EINVAL ) ;
130
131
}
131
132
132
- let storage = Box :: new ( storage) ;
133
+ let storage = try_alloc ( storage) ? ;
133
134
let mut table = vec ! [
134
135
bindings:: ctl_table {
135
136
procname: name. as_ptr( ) as * const i8 ,
You can’t perform that action at this time.
0 commit comments