Skip to content

Commit e632fe9

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

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

rust/kernel/lib.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,44 @@ impl ThisModule {
123123
/// Locks the module parameters to access them.
124124
///
125125
/// Returns a [`KParamGuard`] that will release the lock when dropped.
126+
#[cfg(CONFIG_SYSFS)]
126127
pub fn kernel_param_lock(&self) -> KParamGuard<'_> {
127128
// SAFETY: `kernel_param_lock` will check if the pointer is null and
128129
// use the built-in mutex in that case.
129-
#[cfg(CONFIG_SYSFS)]
130-
unsafe {
131-
bindings::kernel_param_lock(self.0)
132-
}
130+
unsafe { bindings::kernel_param_lock(self.0) }
133131

134132
KParamGuard { this_module: self }
135133
}
134+
135+
/// Locks the module parameters to access them.
136+
///
137+
/// Returns a [`KParamGuard`] that will release the lock when dropped.
138+
#[cfg(not(CONFIG_SYSFS))]
139+
pub fn kernel_param_lock(&self) -> KParamGuard {
140+
// empty KParamGuard to keep the api uniform
141+
KParamGuard { _private: () }
142+
}
136143
}
137144

138145
/// Scoped lock on the kernel parameters of [`ThisModule`].
139146
///
140147
/// Lock will be released when this struct is dropped.
148+
#[cfg(CONFIG_SYSFS)]
149+
#[repr(transparent)]
141150
pub struct KParamGuard<'a> {
142151
this_module: &'a ThisModule,
143152
}
144153

154+
/// Scoped lock on the kernel parameters of [`ThisModule`].
155+
///
156+
/// Lock will be released when this struct is dropped.
157+
#[cfg(not(CONFIG_SYSFS))]
158+
pub struct KParamGuard {
159+
// private field, so this struct can not be constructed from outside this crate
160+
#[cfg(not(CONFIG_SYSFS))]
161+
_private: (),
162+
}
163+
145164
#[cfg(CONFIG_SYSFS)]
146165
impl<'a> Drop for KParamGuard<'a> {
147166
fn drop(&mut self) {

0 commit comments

Comments
 (0)