File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Expand file tree Collapse file tree 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;
88use crate :: bindings;
99use crate :: c_types;
1010use crate :: error:: { Error , KernelResult } ;
11+ use crate :: try_alloc;
1112use crate :: user_ptr:: { UserSlicePtr , UserSlicePtrReader , UserSlicePtrWriter } ;
1213
1314bitflags:: bitflags! {
@@ -65,7 +66,7 @@ unsafe extern "C" fn open_callback<T: FileOperations>(
6566 file : * mut bindings:: file ,
6667) -> c_types:: c_int {
6768 from_kernel_result ! {
68- let f = Box :: new ( T :: open( ) ?) ;
69+ let f = try_alloc ( T :: open( ) ?) ? ;
6970 ( * file) . private_data = Box :: into_raw( f) as * mut c_types:: c_void;
7071 Ok ( 0 )
7172 }
@@ -232,7 +233,7 @@ pub trait FileOperations: Sync + Sized {
232233 /// pointer in `struct file_operations`.
233234 const SEEK : SeekFn < Self > = None ;
234235
235- /// Syncs pending changes to this file. Corresponds to the `fsync` function
236+ /// Syncs pending changes to this file. Corresponds to the `fsync` function
236237 /// pointer in the `struct file_operations`.
237238 const FSYNC : FSync < Self > = None ;
238239}
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ pub fn try_alloc<T>(value: T) -> KernelResult<Box<T>> {
6868 let layout = Layout :: new :: < MaybeUninit < T > > ( ) ;
6969 let ptr: NonNull < MaybeUninit < T > > = if layout. size ( ) == 0 {
7070 NonNull :: dangling ( )
71- // SAFETY: We checked that the layout size is nonzero.
71+ // SAFETY: We checked that the layout size is nonzero.
7272 } else if let Some ( nn) = NonNull :: new ( unsafe { alloc:: alloc:: alloc ( layout) } ) {
7373 nn. cast ( )
7474 } else {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ use core::sync::atomic;
99use crate :: bindings;
1010use crate :: c_types;
1111use crate :: error;
12+ use crate :: try_alloc;
1213use crate :: types;
1314use crate :: user_ptr:: { UserSlicePtr , UserSlicePtrWriter } ;
1415
@@ -129,7 +130,7 @@ impl<T: SysctlStorage> Sysctl<T> {
129130 return Err ( error:: Error :: EINVAL ) ;
130131 }
131132
132- let storage = Box :: new ( storage) ;
133+ let storage = try_alloc ( storage) ? ;
133134 let mut table = vec ! [
134135 bindings:: ctl_table {
135136 procname: name. as_ptr( ) as * const i8 ,
You can’t perform that action at this time.
0 commit comments