Re: [PATCH v3] rust: regulator: add a bare minimum regulator abstraction

From: Benno Lossin
Date: Sun May 18 2025 - 10:06:26 EST


On Sun May 18, 2025 at 1:12 PM CEST, Alexandre Courbot wrote:
> On Sun May 18, 2025 at 6:57 PM JST, Benno Lossin wrote:
>> So just let users ensure that they always match each `enable` call with
>> a `disable` call in the `Dynamic` typestate?
>>
>> That is ok, if no memory issues can arise from forgetting to do so,
>> otherwise those functions need to be `unsafe`.
>
> There shouldn't be any, the only side effect would be that the regulator
> stays enabled when it shouldn't.
>
> It's also easy to implement more behaviors using more states. For
> instance, `Dynamic` just proxies the C API. But if we also think it its
> useful to have a regulator which use count is clamped to 0 and 1, you
> could have another state that includes a boolean (instead of being empty
> lke the others) to track whether the regulator is enabled or not, and an
> `enable` method that only calls the C `regulator_enable` if that boolean
> is not already true. That way you remove the need to mirror the calls to
> enable and disable, while only paying the memory overhead for doing so
> when you explicitly state you want this behavior.

Aren't we then duplicating the refcount from the C side?

---
Cheers,
Benno