Re: [PATCH] rust: clk: use the type-state pattern

From: Viresh Kumar
Date: Wed Jul 30 2025 - 02:24:13 EST


On 29-07-25, 18:38, Daniel Almeida wrote:
> diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
> /// A reference-counted clock.
> ///
> /// Rust abstraction for the C [`struct clk`].
> ///
> + /// A [`Clk`] instance represents a clock that can be in one of several
> + /// states: [`Unprepared`], [`Prepared`], or [`Enabled`].
> + ///
> + /// No action needs to be taken when a [`Clk`] is dropped. The calls to
> + /// `clk_unprepare()` and `clk_disable()` will be placed as applicable.
> + ///
> + /// An optional [`Clk`] is treated just like a regular [`Clk`], but its
> + /// inner `struct clk` pointer is `NULL`. This interfaces correctly with the
> + /// C API and also exposes all the methods of a regular [`Clk`] to users.
> + ///
> /// # Invariants
> ///
> /// A [`Clk`] instance holds either a pointer to a valid [`struct clk`] created by the C
> @@ -99,20 +160,39 @@ mod common_clk {
> /// Instances of this type are reference-counted. Calling [`Clk::get`] ensures that the
> /// allocation remains valid for the lifetime of the [`Clk`].
> ///
> - /// ## Examples
> + /// The [`Prepared`] state is associated with a single count of
> + /// `clk_prepare()`, and the [`Enabled`] state is associated with a single
> + /// count of `clk_enable()`, and the [`Enabled`] state is associated with a
> + /// single count of `clk_prepare` and `clk_enable()`.

You have mentioned the `Enabled` state twice. Also clk_prepare() ?

No objections from my side. Thanks.

--
viresh