Re: [PATCH v6 5/7] rust: clk: add devres-managed clks
From: Danilo Krummrich
Date: Thu Dec 03 2026 - 11:12:35 EST
On Fri Nov 27, 2026 at 8:04 PM CET, Gary Guo wrote:
> On Fri Nov 27, 2026 at 6:04 PM GMT, Jerome Brunet wrote:
>> On 2026-11-18 11:47 -0300, Daniel Almeida wrote:
>>>
>>>
>>> > On 18 Nov 2026, at 11:24, Gary Guo <gary@xxxxxxxxxxx> wrote:
>>> >
>>> > On Tue Oct 13, 2026 at 6:07 PM BST, Daniel Almeida wrote:
>>> >> Many drivers only need a clock running for as long as the device is
>>> >> bound and never touch it afterwards. In C, devm_clk_get_enabled() and
>>> >> devm_clk_get_optional_enabled() cover this case.
>>> >>
>>> >> Add devm_enable(), devm_enable_optional() and
>>> >> devm_enable_optional_with_rate(), which wrap the C helpers. They return
>>> >> no handle, so the driver keeps nothing in its data and cannot change the
>>> >> state of the clock. The clock is disabled, unprepared and put when the
>>> >> device is unbound.
>>> >>
>>> >> This mirrors regulator::devm_enable() and devm_enable_optional().
>>> >>
>>> >> Reviewed-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
>>> >> Signed-off-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
>>> >
>>> > Given all the device resource lifetime changes, do we still need this now, or
>>> > would putting a guard in driver private data to be dropped automatically upon
>>> > unbind be sufficient?
>>>
>>> I think we should still provide this. Many drivers only care that the clock be
>>> enabled at a given rate, and do not care about the handle. I think this has
>>> little to do with C or Rust and should be supported in Rust too.
>>>
>>> — Daniel
>>
>> Gary, is this OK with you ? if it is, I can take as it is.
>
> It's a bit against the trend that we're doing elsewhere where things that are
> managed APIs are changed to become guards that gets embedded in drivers (so the
> lifetime relationship is tracked by the type system). That said, clk/regulators
> usually don't interact with other device resources, so probably keeping devm is
> fine, so not a blocking concern from me.
>
> That said, I'd like to hear Danilo's thought on this one.
For clk and regulators specifically it is not a huge concern for me to have
devm_* helpers, but in general I don't want to add more of them.
I'd rather want to get rid of devres in Rust, as it can lead to subtle ordering
issues with the lifetime design we have for device resources.
So, if we don't think they add a lot of benefit, let's just avoid them so we
don't give people ideas. :)
Independent from that, both the clk and regulator APIs should be constrained by
the lifetime of their corresponding Device<Bound> they are associated with.
I'm fine if this is done as a follow up though.
Thanks,
Danilo