Skip to content

Commit 4b191e1

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

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
@@ -138,18 +138,26 @@ impl ThisModule {
138138
/// Scoped lock on the kernel parameters of [`ThisModule`].
139139
///
140140
/// Lock will be released when this struct is dropped.
141+
#[repr(transparent)]
141142
pub struct KParamGuard<'a> {
142143
this_module: &'a ThisModule,
143144
}
144145

145-
#[cfg(CONFIG_SYSFS)]
146146
impl<'a> Drop for KParamGuard<'a> {
147+
#[cfg(CONFIG_SYSFS)]
147148
fn drop(&mut self) {
148149
// SAFETY: `kernel_param_lock` will check if the pointer is null and
149150
// use the built-in mutex in that case. The existance of `self`
150151
// guarantees that the lock is held.
151152
unsafe { bindings::kernel_param_unlock(self.this_module.0) }
152153
}
154+
155+
#[cfg(not(CONFIG_SYSFS))]
156+
fn drop(&mut self) {
157+
// This just touches the `this_module` field, so the compiler cannot optimize it away,
158+
// and so that we don't get a dead_code warning´
159+
let _ = self.this_module;
160+
}
153161
}
154162

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

0 commit comments

Comments
 (0)