Skip to content

Commit 6b55976

Browse files
committed
Fix dead_code in rust KParamGuard.
Signed-off-by: Finn Behrens <[email protected]>
1 parent be91a55 commit 6b55976

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

rust/kernel/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,22 @@ pub struct KParamGuard<'a> {
149149
this_module: &'a ThisModule,
150150
}
151151

152-
#[cfg(CONFIG_SYSFS)]
153152
impl<'a> Drop for KParamGuard<'a> {
153+
#[cfg(CONFIG_SYSFS)]
154154
fn drop(&mut self) {
155155
// SAFETY: `kernel_param_lock` will check if the pointer is null and
156156
// use the built-in mutex in that case. The existance of `self`
157157
// guarantees that the lock is held.
158158
unsafe { bindings::kernel_param_unlock(self.this_module.0) }
159159
}
160+
161+
// This "empty" `Drop` implementation is kept so that the behavior remains
162+
// the same with and without `CONFIG_SYSFS` with respect to `dropck`.
163+
#[cfg(not(CONFIG_SYSFS))]
164+
fn drop(&mut self) {
165+
// Touches the `this_module` field, to prevent dead_code warnings.
166+
let _ = self.this_module;
167+
}
160168
}
161169

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

0 commit comments

Comments
 (0)