Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: regulator: remove Regulator<Dynamic>

After some experimenting and further discussion, it is starting to look
like Regulator<Dynamic> might be a footgun. It turns out that one can
get the same behavior by correctly using just Regulator<Enabled> and
Regulator<Disabled>, so there is no need to directly expose the manual
refcounting ability of Regulator<Dynamic> to clients.

Remove it while we do not have any other users.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Link: https://patch.msgid.link/20250910-regulator-remove-dynamic-v3-1-07af4dfa97cc@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Daniel Almeida and committed by
Mark Brown
b87ecbc5 5bad1648

+1 -87
+1 -87
rust/kernel/regulator.rs
··· 30 30 31 31 impl Sealed for super::Enabled {} 32 32 impl Sealed for super::Disabled {} 33 - impl Sealed for super::Dynamic {} 34 33 } 35 34 36 35 /// A trait representing the different states a [`Regulator`] can be in. ··· 49 50 /// own an `enable` reference count, but the regulator may still be on. 50 51 pub struct Disabled; 51 52 52 - /// A state that models the C API. The [`Regulator`] can be either enabled or 53 - /// disabled, and the user is in control of the reference count. This is also 54 - /// the default state. 55 - /// 56 - /// Use [`Regulator::is_enabled`] to check the regulator's current state. 57 - pub struct Dynamic; 58 - 59 53 impl RegulatorState for Enabled { 60 54 const DISABLE_ON_DROP: bool = true; 61 55 } ··· 57 65 const DISABLE_ON_DROP: bool = false; 58 66 } 59 67 60 - impl RegulatorState for Dynamic { 61 - const DISABLE_ON_DROP: bool = false; 62 - } 63 - 64 68 /// A trait that abstracts the ability to check if a [`Regulator`] is enabled. 65 69 pub trait IsEnabled: RegulatorState {} 66 70 impl IsEnabled for Disabled {} 67 - impl IsEnabled for Dynamic {} 68 71 69 72 /// An error that can occur when trying to convert a [`Regulator`] between states. 70 73 pub struct Error<State: RegulatorState> { ··· 170 183 /// } 171 184 /// ``` 172 185 /// 173 - /// ## Using [`Regulator<Dynamic>`] 174 - /// 175 - /// This example mimics the behavior of the C API, where the user is in 176 - /// control of the enabled reference count. This is useful for drivers that 177 - /// might call enable and disable to manage the `enable` reference count at 178 - /// runtime, perhaps as a result of `open()` and `close()` calls or whatever 179 - /// other driver-specific or subsystem-specific hooks. 180 - /// 181 - /// ``` 182 - /// # use kernel::prelude::*; 183 - /// # use kernel::c_str; 184 - /// # use kernel::device::Device; 185 - /// # use kernel::regulator::{Regulator, Dynamic}; 186 - /// struct PrivateData { 187 - /// regulator: Regulator<Dynamic>, 188 - /// } 189 - /// 190 - /// // A fictictious probe function that obtains a regulator and sets it up. 191 - /// fn probe(dev: &Device) -> Result<PrivateData> { 192 - /// // Obtain a reference to a (fictitious) regulator. 193 - /// let regulator = Regulator::<Dynamic>::get(dev, c_str!("vcc"))?; 194 - /// 195 - /// Ok(PrivateData { regulator }) 196 - /// } 197 - /// 198 - /// // A fictictious function that indicates that the device is going to be used. 199 - /// fn open(dev: &Device, data: &PrivateData) -> Result { 200 - /// // Increase the `enabled` reference count. 201 - /// data.regulator.enable()?; 202 - /// 203 - /// Ok(()) 204 - /// } 205 - /// 206 - /// fn close(dev: &Device, data: &PrivateData) -> Result { 207 - /// // Decrease the `enabled` reference count. 208 - /// data.regulator.disable()?; 209 - /// 210 - /// Ok(()) 211 - /// } 212 - /// 213 - /// fn remove(dev: &Device, data: PrivateData) -> Result { 214 - /// // `PrivateData` is dropped here, which will drop the 215 - /// // `Regulator<Dynamic>` in turn. 216 - /// // 217 - /// // The reference that was obtained by `regulator_get()` will be 218 - /// // released, but it is up to the user to make sure that the number of calls 219 - /// // to `enable()` and `disabled()` are balanced before this point. 220 - /// Ok(()) 221 - /// } 222 - /// ``` 223 - /// 224 186 /// # Invariants 225 187 /// 226 188 /// - `inner` is a non-null wrapper over a pointer to a `struct 227 189 /// regulator` obtained from [`regulator_get()`]. 228 190 /// 229 191 /// [`regulator_get()`]: https://docs.kernel.org/driver-api/regulator.html#c.regulator_get 230 - pub struct Regulator<State = Dynamic> 192 + pub struct Regulator<State> 231 193 where 232 194 State: RegulatorState, 233 195 { ··· 284 348 error, 285 349 regulator: ManuallyDrop::into_inner(regulator), 286 350 }) 287 - } 288 - } 289 - 290 - impl Regulator<Dynamic> { 291 - /// Obtains a [`Regulator`] instance from the system. The current state of 292 - /// the regulator is unknown and it is up to the user to manage the enabled 293 - /// reference count. 294 - /// 295 - /// This closely mimics the behavior of the C API and can be used to 296 - /// dynamically manage the enabled reference count at runtime. 297 - pub fn get(dev: &Device, name: &CStr) -> Result<Self> { 298 - Regulator::get_internal(dev, name) 299 - } 300 - 301 - /// Increases the `enabled` reference count. 302 - pub fn enable(&self) -> Result { 303 - self.enable_internal() 304 - } 305 - 306 - /// Decreases the `enabled` reference count. 307 - pub fn disable(&self) -> Result { 308 - self.disable_internal() 309 351 } 310 352 } 311 353