[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DCFSXTUVBKL0.2CTM31D8Q8QW2@kernel.org>
Date: Sat, 30 Aug 2025 15:38:12 +0200
From: "Danilo Krummrich" <dakr@...nel.org>
To: "Daniel Almeida" <daniel.almeida@...labora.com>
Cc: "Alexandre Courbot" <acourbot@...dia.com>, "Liam Girdwood"
<lgirdwood@...il.com>, "Mark Brown" <broonie@...nel.org>, "Miguel Ojeda"
<ojeda@...nel.org>, "Alex Gaynor" <alex.gaynor@...il.com>, "Boqun Feng"
<boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>, "Benno Lossin"
<lossin@...nel.org>, "Andreas Hindborg" <a.hindborg@...nel.org>, "Alice
Ryhl" <aliceryhl@...gle.com>, "Trevor Gross" <tmgross@...ch.edu>,
<linux-kernel@...r.kernel.org>, <rust-for-linux@...r.kernel.org>
Subject: Re: [PATCH 2/2] rust: regulator: add devm_regulator_get_enable API
On Sat Aug 30, 2025 at 3:13 PM CEST, Daniel Almeida wrote:
>> On 30 Aug 2025, at 02:20, Alexandre Courbot <acourbot@...dia.com> wrote:
>> On Sat Aug 30, 2025 at 6:11 AM JST, Daniel Almeida wrote:
>>> +/// Enables a regulator whose lifetime is tied to the lifetime of `dev`.
>>> +///
>>> +/// This calls `regulator_disable()` and `regulator_put()` automatically on
>>> +/// driver detach.
>>> +///
>>> +/// This API is identical to `devm_regulator_get_enable()`, and should be
>>> +/// preferred if the caller only cares about the regulator being on.
>>> +pub fn enable(dev: &Device<Bound>, name: &CStr) -> Result {
>>
>> The name `enable` sounds like it just enables a regulator, which is a bit
>> confusing IMHO. Maybe `get_enable` or `get_enable_for`? Not sure what
>> would be idiomatic here.
>
> So I thought about get_enabled, but I thought the "get" nomenclature was
> confusing. For example, "get" acquires a refcount, but for the devm_ version
> the refcount management is transparent. In this sense, I thought that just
> "enable" would convey the idea better, i.e. "enable this and forget about any
> lifetime management at all".
Technically, it does acquire a reference count, we just don't return the
corresponding regulator object to the caller, but leave the reference count to
devres.
> If you still think that using the "get" prefix is better, I can change it no
> worries :)
If we want to be extra correct, it should be devm_get_enable(). But the fact
that devres holds a reference count is an implementation detail not relevant to
the caller.
Hence, I think devm_enable() (and devm_enable_optional()) is enough. But we
should make it obvious that it's devres managed, i.e. "devm".
Powered by blists - more mailing lists