Skip to content

Commit 24cdb96

Browse files
committed
Expose release method to file implementations.
This is useful for cases when the implementation needs to defer the actual freeing of the file object, for example, because it needs to perform expensive work that is better suited for worker threads than the current one. Signed-off-by: Wedson Almeida Filho <[email protected]>
1 parent 6e86a86 commit 24cdb96

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

rust/kernel/src/file_operations.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ unsafe extern "C" fn release_callback<T: FileOperations>(
113113
file: *mut bindings::file,
114114
) -> c_types::c_int {
115115
let ptr = mem::replace(&mut (*file).private_data, ptr::null_mut());
116-
drop(T::Wrapper::from_pointer(ptr as _));
116+
T::release(T::Wrapper::from_pointer(ptr as _), &File::from_ptr(file));
117117
0
118118
}
119119

@@ -223,6 +223,11 @@ pub trait FileOperations: Sync + Sized {
223223
/// pointer in `struct file_operations`.
224224
fn open() -> KernelResult<Self::Wrapper>;
225225

226+
/// Cleans up after the last reference to the file goes away. Note that the object is moved, so
227+
/// it will be freed automatically unless the implemention moves it elsewhere. Corresponds to
228+
/// the `release` function pointer in `struct file_operations`.
229+
fn release(_obj: Self::Wrapper, _file: &File) {}
230+
226231
/// Reads data from this file to userspace. Corresponds to the `read`
227232
/// function pointer in `struct file_operations`.
228233
const READ: ReadFn<Self> = None;

0 commit comments

Comments
 (0)