Skip to content

Commit 70720d8

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

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

rust/kernel/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,25 @@ 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, to prevent dead_code warnings.
158+
let _ = self.this_module;
159+
}
153160
}
154161

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

0 commit comments

Comments
 (0)