From: sashiko-bot@kernel.org
To: "Daniel Almeida" <daniel.almeida@collabora.com>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org
Subject: Re: [PATCH v4 1/3] rust: clk: use the type-state pattern
Date: Thu, 18 Jun 2026 03:56:59 +0000 [thread overview]
Message-ID: <20260618035659.BAD1C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260618-clk-type-state-v4-1-8be082786080@collabora.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] The clock rate configuration methods (`rate()` and `set_rate()`) have been restricted exclusively to `Clk<Enabled>`, breaking support for clocks with `CLK_SET_RATE_GATE` and preventing pre-enablement configuration.
- [Low] Missing `// INVARIANT:` comments when constructing `Clk` instances during state transitions, and safety comments incorrectly refer to a non-existent `self.0` field.
- [Low] `Clk::<Enabled>::disable()` incorrectly returns a `Result` despite being infallible, while `unprepare()` correctly returns the struct directly.
- [Low] Typo in the `# Invariants` documentation section regarding the `Prepared` and `Enabled` states.
--
commit c6dd3e4cdd99489c0a4f27adce8b4f6ceef42c51
Author: Daniel Almeida <daniel.almeida@collabora.com>
rust: clk: use the type-state pattern
This commit switches the clock abstraction to use the type-state pattern
to enforce valid state transitions and track reference counts automatically.
Link: https://crates.io/crates/sealed [1]
> diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
> index 7abbd0767d8cf..a62e4c7e252e3 100644
> --- a/rust/kernel/clk.rs
> +++ b/rust/kernel/clk.rs
[ ... ]
> + /// 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 [`Prepared`] state is associated with a
> + /// single count of `clk_prepare()` and `clk_enable()`.
[Severity: Low]
Is the last part of this sentence a typo? It attributes the dual count
requirement to the Prepared state again instead of the Enabled state.
[ ... ]
> + pub fn prepare(self) -> Result<Clk<Prepared>, Error<Unprepared>> {
> + // We will be transferring the ownership of our `clk_get()` count to
> + // `Clk<Prepared>`.
> + let clk = ManuallyDrop::new(self);
> +
> + // SAFETY: By the type invariants, `self.0` is a valid argument for
> + // [`clk_prepare`].
> + to_result(unsafe { bindings::clk_prepare(clk.as_raw()) })
> + .map(|()| Clk {
> + inner: clk.inner,
> + _phantom: PhantomData,
> + })
[Severity: Low]
Should there be an '// INVARIANT:' comment when constructing this new Clk,
similar to the initialization in get_unbound()?
Also, does the safety comment reference 'self.0' which no longer exists
after the struct was refactored to use named fields? The same stale reference
and missing invariant comment appears in unprepare(), enable(), and disable().
[ ... ]
> + pub fn disable(self) -> Result<Clk<Prepared>, Error<Enabled>> {
> + // We will be transferring the ownership of our `clk_get()` and
> + // `clk_enable()` counts to `Clk<Prepared>`.
> + let clk = ManuallyDrop::new(self);
> +
> + // SAFETY: By the type invariants, `self.0` is a valid argument for
> + // [`clk_disable`].
> + unsafe { bindings::clk_disable(clk.as_raw()) };
> +
> + Ok(Clk {
> + inner: clk.inner,
> + _phantom: PhantomData,
> + })
> + }
[Severity: Low]
Since clk_disable() is infallible, does this method need to return a Result?
The unprepare() method returns the struct directly, which avoids unnecessary
error handling for the caller.
[ ... ]
> + impl Clk<Enabled> {
[ ... ]
> pub fn set_rate(&self, rate: Hertz) -> Result {
> // SAFETY: By the type invariants, self.as_raw() is a valid argument for
> // [`clk_set_rate`].
> to_result(unsafe { bindings::clk_set_rate(self.as_raw(), rate.as_hz()) })
> }
> }
[Severity: High]
Does restricting set_rate() and rate() to the Enabled state prevent configuring
clocks that have the CLK_SET_RATE_GATE flag?
The C API requires clocks with this flag to be disabled before changing their
rate. Additionally, is it still possible to safely configure a clock's rate
before enabling it, which is often required to avoid running hardware at
incorrect frequencies?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260618-clk-type-state-v4-0-8be082786080@collabora.com?part=1
next prev parent reply other threads:[~2026-06-18 3:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 3:46 [PATCH v4 0/3] Clk improvements Daniel Almeida
2026-06-18 3:46 ` Daniel Almeida
2026-06-18 3:46 ` [PATCH v4 1/3] rust: clk: use the type-state pattern Daniel Almeida
2026-06-18 3:46 ` Daniel Almeida
2026-06-18 3:56 ` sashiko-bot [this message]
2026-06-18 8:10 ` Onur Özkan
2026-06-18 8:10 ` Onur Özkan
2026-06-28 20:15 ` Maurice
2026-06-28 20:15 ` Maurice
2026-06-18 3:46 ` [PATCH v4 2/3] rust: clk: add devres-managed clks Daniel Almeida
2026-06-18 3:46 ` Daniel Almeida
2026-06-18 3:57 ` sashiko-bot
2026-06-18 3:46 ` [PATCH v4 3/3] rust: clk: use 'kernel vertical style' for imports Daniel Almeida
2026-06-18 3:46 ` Daniel Almeida
2026-06-18 7:58 ` Onur Özkan
2026-06-18 7:58 ` Onur Özkan
2026-06-18 10:40 ` Miguel Ojeda
2026-06-18 10:40 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260618035659.BAD1C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.