Skip to content

Commit e68d341

Browse files
authored
Merge pull request #56 from Rust-for-Linux/release
Expose `release` method to file implementations.
2 parents 6e86a86 + 24cdb96 commit e68d341

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)