File tree 2 files changed +16
-1
lines changed 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ pub struct FileDescriptorReservation {
95
95
impl FileDescriptorReservation {
96
96
/// Creates a new file descriptor reservation.
97
97
pub fn new ( flags : u32 ) -> Result < Self > {
98
+ // SAFETY: FFI call, there are no safety requirements on `flags`.
98
99
let fd = unsafe { bindings:: get_unused_fd_flags ( flags) } ;
99
100
if fd < 0 {
100
101
return Err ( Error :: from_kernel_errno ( fd) ) ;
Original file line number Diff line number Diff line change @@ -79,13 +79,26 @@ pub enum SeekFrom {
79
79
Current ( i64 ) ,
80
80
}
81
81
82
+ /// Called by the VFS when an inode should be opened.
83
+ ///
84
+ /// Calls `T::open` on the returned value of `A::convert`.
85
+ ///
86
+ /// # Safety
87
+ ///
88
+ /// The returned value of `A::convert` must be a valid non-null pointer and
89
+ /// `T:open` must return a valid non-null pointer on an `Ok` result.
82
90
unsafe extern "C" fn open_callback < A : FileOpenAdapter , T : FileOpener < A :: Arg > > (
83
91
inode : * mut bindings:: inode ,
84
92
file : * mut bindings:: file ,
85
93
) -> c_types:: c_int {
86
94
from_kernel_result ! {
95
+ // SAFETY: `A::convert` must return a valid non-null pointer
87
96
let arg = unsafe { A :: convert( inode, file) } ;
97
+ // SAFETY: `arg` was returned by `A::convert` and must be a valid
98
+ // non-null pointer
88
99
let ptr = T :: open( unsafe { & * arg } ) ?. into_pointer( ) ;
100
+ // SAFETY: `file` was returned by `T::open` and must be a valid
101
+ // non-null pointer.
89
102
unsafe { ( * file) . private_data = ptr as * mut c_types:: c_void } ;
90
103
Ok ( 0 )
91
104
}
@@ -500,7 +513,8 @@ pub trait FileOpenAdapter {
500
513
/// # Safety
501
514
///
502
515
/// This function must be called only when [`struct file_operations::open`] is being called for
503
- /// a file that was registered by the implementer.
516
+ /// a file that was registered by the implementer. The returned pointer must be valid and
517
+ /// not-null.
504
518
unsafe fn convert ( _inode : * mut bindings:: inode , _file : * mut bindings:: file )
505
519
-> * const Self :: Arg ;
506
520
}
You can’t perform that action at this time.
0 commit comments