Re: [PATCH v3 1/3] rust: clk: use the type-state pattern

Daniel Almeida
2026-01-08T14:19:37Z

> On 8 Jan 2026, at 10:57, Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Jan 8, 2026 at 9:07 AM Maxime Ripard <mripard@kernel.org> wrote:
>>
>> AFAIU, encoding the state of the clock into the Clk type (and thus
>> forcing the structure that holds it) prevents that mutation. If not, we
>> should make it clearer (by expanding the doc maybe?) how such a pattern
>> can be supported.
>
> One possibility to consider in cases like this is whether supporting
> both cases differently makes sense, i.e. one for that covers
> easily/safely/... the usual "80%" of cases, and another "advanced" one
> (possibly unsafe etc.) for the rest.
>
> While it may be a bit more to maintain, it may pay itself off by
> making it easier to review the easy ones if the majority only need
> that etc.
>
> Cheers,
> Miguel

This is already the case. The devm_* stuff in the next patch covers a lot of
simpler drivers (who might simply want to enable the clk, perhaps with a given
rate), while the typestate pattern allows for more control when needed. There
will be users for both, IMHO.

— Daniel