Skip to content

Commit f7fbf30

Browse files
danielalmeida-collaborabroonie
authored andcommitted
rust: regulator: remove needless &mut from member functions
Regulator functions like "regulator_enable()" and "regulator_disable()" already provide their own locking through "regulator_lock_dependent()", so we can safely call the Rust API with a shared reference. This was already the case with Regulator::set_voltage() on the Rust side, but it was forgotten for Regulator::enable() and Regulator::disable(). Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com> Link: https://patch.msgid.link/20250729-regulator-send-sync-v1-1-8bcbd546b940@collabora.com Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 8f5ae30 commit f7fbf30

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

rust/kernel/regulator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,20 @@ pub struct Error<State: RegulatorState> {
203203
/// // A fictictious probe function that obtains a regulator and sets it up.
204204
/// fn probe(dev: &Device) -> Result<PrivateData> {
205205
/// // Obtain a reference to a (fictitious) regulator.
206-
/// let mut regulator = Regulator::<Dynamic>::get(dev, c_str!("vcc"))?;
206+
/// let regulator = Regulator::<Dynamic>::get(dev, c_str!("vcc"))?;
207207
///
208208
/// Ok(PrivateData { regulator })
209209
/// }
210210
///
211211
/// // A fictictious function that indicates that the device is going to be used.
212-
/// fn open(dev: &Device, data: &mut PrivateData) -> Result {
212+
/// fn open(dev: &Device, data: &PrivateData) -> Result {
213213
/// // Increase the `enabled` reference count.
214214
/// data.regulator.enable()?;
215215
///
216216
/// Ok(())
217217
/// }
218218
///
219-
/// fn close(dev: &Device, data: &mut PrivateData) -> Result {
219+
/// fn close(dev: &Device, data: &PrivateData) -> Result {
220220
/// // Decrease the `enabled` reference count.
221221
/// data.regulator.disable()?;
222222
///
@@ -289,12 +289,12 @@ impl<T: RegulatorState> Regulator<T> {
289289
})
290290
}
291291

292-
fn enable_internal(&mut self) -> Result {
292+
fn enable_internal(&self) -> Result {
293293
// SAFETY: Safe as per the type invariants of `Regulator`.
294294
to_result(unsafe { bindings::regulator_enable(self.inner.as_ptr()) })
295295
}
296296

297-
fn disable_internal(&mut self) -> Result {
297+
fn disable_internal(&self) -> Result {
298298
// SAFETY: Safe as per the type invariants of `Regulator`.
299299
to_result(unsafe { bindings::regulator_disable(self.inner.as_ptr()) })
300300
}
@@ -310,7 +310,7 @@ impl Regulator<Disabled> {
310310
pub fn try_into_enabled(self) -> Result<Regulator<Enabled>, Error<Disabled>> {
311311
// We will be transferring the ownership of our `regulator_get()` count to
312312
// `Regulator<Enabled>`.
313-
let mut regulator = ManuallyDrop::new(self);
313+
let regulator = ManuallyDrop::new(self);
314314

315315
regulator
316316
.enable_internal()
@@ -339,7 +339,7 @@ impl Regulator<Enabled> {
339339
pub fn try_into_disabled(self) -> Result<Regulator<Disabled>, Error<Enabled>> {
340340
// We will be transferring the ownership of our `regulator_get()` count
341341
// to `Regulator<Disabled>`.
342-
let mut regulator = ManuallyDrop::new(self);
342+
let regulator = ManuallyDrop::new(self);
343343

344344
regulator
345345
.disable_internal()
@@ -366,12 +366,12 @@ impl Regulator<Dynamic> {
366366
}
367367

368368
/// Increases the `enabled` reference count.
369-
pub fn enable(&mut self) -> Result {
369+
pub fn enable(&self) -> Result {
370370
self.enable_internal()
371371
}
372372

373373
/// Decreases the `enabled` reference count.
374-
pub fn disable(&mut self) -> Result {
374+
pub fn disable(&self) -> Result {
375375
self.disable_internal()
376376
}
377377
}

0 commit comments

Comments
 (0)