Skip to content

Expose release method to file implementations. #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rust/kernel/src/file_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ unsafe extern "C" fn release_callback<T: FileOperations>(
file: *mut bindings::file,
) -> c_types::c_int {
let ptr = mem::replace(&mut (*file).private_data, ptr::null_mut());
drop(T::Wrapper::from_pointer(ptr as _));
T::release(T::Wrapper::from_pointer(ptr as _), &File::from_ptr(file));
0
}

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

/// Cleans up after the last reference to the file goes away. Note that the object is moved, so
/// it will be freed automatically unless the implemention moves it elsewhere. Corresponds to
/// the `release` function pointer in `struct file_operations`.
fn release(_obj: Self::Wrapper, _file: &File) {}

/// Reads data from this file to userspace. Corresponds to the `read`
/// function pointer in `struct file_operations`.
const READ: ReadFn<Self> = None;
Expand Down