From: Stephen Boyd <sboyd@kernel.org>
To: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>,
Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Michael Turquette" <mturquette@baylibre.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <benno.lossin@proton.me>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Russell King" <linux@armlinux.org.uk>,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>
Subject: Re: [PATCH V3 2/2] rust: Add initial clk abstractions
Date: Wed, 05 Mar 2025 14:31:02 -0800 [thread overview]
Message-ID: <2c17361891c4eb7edd947e5384cc9741.sboyd@kernel.org> (raw)
In-Reply-To: <20250305114659.k5pptszvmusblynm@vireshk-i7>
Quoting Viresh Kumar (2025-03-05 03:46:59)
> On 04-03-25, 10:37, Miguel Ojeda wrote:
> > On Tue, Mar 4, 2025 at 9:53 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
> > > +/// clk.disable_unprepare();
> >
> > Looking at the example, a question that one may have is: should we
> > have something like a scope guard or a closure-passing API for this,
> > or does it not make sense in general?
>
> Something like this (untested) ?
>
> +/// Runs a cleanup function/closure when dropped.
> +///
> +/// The [`ClkGuard::dismiss`] function prevents the cleanup function from running.
> +///
> +pub type ClkGuard<'a> = ScopeGuard<&'a Clk, fn(&Clk)>;
> +
> /// A reference-counted clock.
> ///
> /// This represents the Rust abstraction for the C [`struct clk`].
> @@ -139,10 +146,12 @@ pub fn as_raw(&self) -> *mut bindings::clk {
> ///
> /// [`clk_enable`]: https://docs.kernel.org/core-api/kernel-api.html#c.clk_enable
> #[inline]
> - pub fn enable(&self) -> Result {
> + pub fn enable(&self) -> Result<ClkGuard<'_>> {
> // SAFETY: By the type invariants, it is safe to call clk APIs of the C code for a clock
> // pointer earlier returned by [`clk_get`].
> - to_result(unsafe { bindings::clk_enable(self.as_raw()) })
> + to_result(unsafe { bindings::clk_enable(self.as_raw()) })?;
> +
> + Ok(ClkGuard::new_with_data(self, Clk::disable))
Does this mean that a clk consumer has to keep the Result returned from
enable() in scope until they want to disable the clk? I don't see how
that makes sense, because most of the time a consumer will enable a clk
during probe and leave it enabled until system suspend or runtime PM
suspend time. At that point, they would disable the clk explicitly with
disable(), but now they would need to drop a reference to do that?
next prev parent reply other threads:[~2025-03-05 22:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 9:58 [PATCH V3 0/2] rust: Add basic clock abstractions Viresh Kumar
2025-03-03 9:58 ` [PATCH V3 1/2] rust: Add clk helpers Viresh Kumar
2025-03-03 10:05 ` Alice Ryhl
2025-03-03 11:15 ` Viresh Kumar
2025-03-03 9:58 ` [PATCH V3 2/2] rust: Add initial clk abstractions Viresh Kumar
2025-03-03 10:04 ` Alice Ryhl
2025-03-03 11:32 ` Viresh Kumar
2025-03-03 10:16 ` Miguel Ojeda
2025-03-03 11:44 ` Viresh Kumar
2025-03-03 15:50 ` Miguel Ojeda
2025-03-04 8:53 ` Viresh Kumar
2025-03-04 9:37 ` Miguel Ojeda
2025-03-05 11:46 ` Viresh Kumar
2025-03-05 22:31 ` Stephen Boyd [this message]
2025-03-06 4:40 ` Viresh Kumar
2025-03-06 20:58 ` Stephen Boyd
2025-03-07 7:23 ` Viresh Kumar
2025-03-06 12:33 ` Danilo Krummrich
2025-03-08 2:03 ` Daniel Almeida
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=2c17361891c4eb7edd947e5384cc9741.sboyd@kernel.org \
--to=sboyd@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=miguel.ojeda.sandonis@gmail.com \
--cc=mturquette@baylibre.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox