@@ -123,25 +123,44 @@ impl ThisModule {
123
123
/// Locks the module parameters to access them.
124
124
///
125
125
/// Returns a [`KParamGuard`] that will release the lock when dropped.
126
+ #[ cfg( CONFIG_SYSFS ) ]
126
127
pub fn kernel_param_lock ( & self ) -> KParamGuard < ' _ > {
127
128
// SAFETY: `kernel_param_lock` will check if the pointer is null and
128
129
// 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 ) }
133
131
134
132
KParamGuard { this_module : self }
135
133
}
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
+ }
136
143
}
137
144
138
145
/// Scoped lock on the kernel parameters of [`ThisModule`].
139
146
///
140
147
/// Lock will be released when this struct is dropped.
148
+ #[ cfg( CONFIG_SYSFS ) ]
149
+ #[ repr( transparent) ]
141
150
pub struct KParamGuard < ' a > {
142
151
this_module : & ' a ThisModule ,
143
152
}
144
153
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
+
145
164
#[ cfg( CONFIG_SYSFS ) ]
146
165
impl < ' a > Drop for KParamGuard < ' a > {
147
166
fn drop ( & mut self ) {
0 commit comments