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

Daniel Almeida daniel.almeida at collabora.com
Tue Feb 3 11:26:22 PST 2026


> 
> I think it's fine to have all of these:
> * `Clone` impl
> * `enable` which consumes `Clk<Prepared>` by value and spit out `Clk<Enabled>`
> * `with_enabled` that gives `&Clk<Enabled>`
> 
> This way, if you only want to enable in short time, you can do `with_enabled`.
> If the closure callback wants to keep clock enabled for longer, it can just do
> `.clone()` inside the closure and obtain an owned `Clk<Enabled>`.
> 
> If the user just have a reference and want to enable the callback they can do
> `prepared_clk.clone().enable()` which gives an owned `Clk<Enabled>`. Thoughts?
> 
> Best,
> Gary


I’m ok with what you proposed above. The only problem is that implementing
clone() is done through an Arc<*mut bindings::clk>  in Boris’ current
design, so this requires an extra allocation.

— Daniel


More information about the linux-riscv mailing list