[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <533CE7C2-A42A-43DF-8D23-B7D6AE346C4E@collabora.com>
Date: Mon, 19 Jan 2026 12:44:47 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Gary Guo <gary@...yguo.net>
Cc: Maxime Ripard <mripard@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Viresh Kumar <viresh.kumar@...aro.org>, Danilo Krummrich <dakr@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Thomas Zimmermann <tzimmermann@...e.de>, David Airlie <airlied@...il.com>,
Simona Vetter <simona@...ll.ch>, Drew Fustini <fustini@...nel.org>,
Ren Guo <guoren@...nel.org>, Wei Fu <wefu@...hat.com>,
Uwe Kleine-König <ukleinek@...nel.org>,
Michael Turquette <mturquette@...libre.com>,
Stephen Boyd <sboyd@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Boqun Feng <boqun.feng@...il.com>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <lossin@...nel.org>, Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org, dri-devel@...ts.freedesktop.org,
linux-riscv@...ts.infradead.org, linux-pwm@...r.kernel.org,
linux-clk@...r.kernel.org, rust-for-linux@...r.kernel.org,
Gary Guo <gary@...yguo.net>
Subject: Re: [PATCH v3 1/3] rust: clk: use the type-state pattern
>> Yes, that would be great. I do wonder though if it wouldn't make sense
>> to turn it the other way around. It creates a fair share of boilerplate
>> for a number of drivers. Can't we keep Clk the way it is as a
>> lower-level type, and crate a ManagedClk (or whatever name you prefer)
>> that drivers can use, and would be returned by higher-level helpers, if
>> they so choose?
>>
>> That way, we do have the typestate API for whoever wants to, without
>> creating too much boilerplate for everybody else.
>
> One solution is to have a new typestate `Dynamic` which opts to track things
> using variables.
>
> struct Dynamic {
> enabled: bool,
> prepared: bool,
> }
>
> trait ClkState {
> // Change to methods
> fn disable_on_drop(&self) -> bool;
> }
>
> struct Clk<State> {
> ...
> // Keep an instance, which is zero-sized for everything except `Dynamic`
> state: State,
> }
>
> this way we can have runtime-checked state conversions.
>
> Best,
> Gary
There used to be a Dynamic state in the past in a similar setting. That was removed after some thorough discussion. I’d say we should refrain from going back to this. Specially considering that the current design works fine.
I can remove the turbofish if you want, even though I think they’re useful so that we have the same API for all states.
— Daniel
Powered by blists - more mailing lists