Skip to content

Fix dead_code in rust KParamGuard. #448

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

Open
wants to merge 1 commit into
base: rust
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,22 @@ pub struct KParamGuard<'a> {
this_module: &'a ThisModule,
}

#[cfg(CONFIG_SYSFS)]
impl<'a> Drop for KParamGuard<'a> {
#[cfg(CONFIG_SYSFS)]
fn drop(&mut self) {
// SAFETY: `kernel_param_lock` will check if the pointer is null and
// use the built-in mutex in that case. The existance of `self`
// guarantees that the lock is held.
unsafe { bindings::kernel_param_unlock(self.this_module.0) }
}

// This "empty" `Drop` implementation is kept so that the behavior remains
// the same with and without `CONFIG_SYSFS` with respect to `dropck`.
#[cfg(not(CONFIG_SYSFS))]
fn drop(&mut self) {
// Touches the `this_module` field, to prevent dead_code warnings.
let _ = self.this_module;
}
}

/// Calculates the offset of a field from the beginning of the struct it belongs to.
Expand Down