lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <6EDE1C11-8654-404D-98AC-0D102090C15F@collabora.com>
Date: Wed, 30 Jul 2025 10:52:55 -0300
From: Daniel Almeida <daniel.almeida@...labora.com>
To: Michael Turquette <mturquette@...libre.com>,
 Stephen Boyd <sboyd@...nel.org>,
 Miguel Ojeda <ojeda@...nel.org>,
 Alex Gaynor <alex.gaynor@...il.com>,
 Boqun Feng <boqun.feng@...il.com>,
 Gary Guo <gary@...yguo.net>,
 Björn Roy Baron <bjorn3_gh@...tonmail.com>,
 Benno Lossin <lossin@...nel.org>,
 Andreas Hindborg <a.hindborg@...nel.org>,
 Alice Ryhl <aliceryhl@...gle.com>,
 Trevor Gross <tmgross@...ch.edu>,
 Danilo Krummrich <dakr@...nel.org>,
 "Rafael J. Wysocki" <rafael@...nel.org>,
 Viresh Kumar <viresh.kumar@...aro.org>
Cc: Alexandre Courbot <acourbot@...dia.com>,
 linux-clk@...r.kernel.org,
 rust-for-linux@...r.kernel.org,
 linux-kernel@...r.kernel.org,
 linux-pm@...r.kernel.org
Subject: Re: [PATCH] rust: clk: use the type-state pattern


[…]

>         }
> 
> -        /// Enable the clock.
> +        /// Attempts to convert the [`Clk`] to a [`Prepared`] state.
>         ///
> -        /// Equivalent to the kernel's [`clk_enable`] API.
> +        /// Equivalent to the kernel's [`clk_prepare`] API.
>         ///
> -        /// [`clk_enable`]: https://docs.kernel.org/core-api/kernel-api.html#c.clk_enable
> +        /// [`clk_prepare`]: https://docs.kernel.org/core-api/kernel-api.html#c.clk_prepare
>         #[inline]
> -        pub fn enable(&self) -> Result {
> -            // SAFETY: By the type invariants, self.as_raw() is a valid argument for
> -            // [`clk_enable`].
> -            to_result(unsafe { bindings::clk_enable(self.as_raw()) })
> +        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`].

I just noticed that some comments still refer to the old “self.0” field, but that doesn’t exist anymore.

I’ll fix that in v2.

> +            to_result(unsafe { bindings::clk_prepare(clk.as_raw()) })
> +                .map(|()| Clk {
> +                    inner: clk.inner,
> +                    _phantom: PhantomData,
> +                })
> +                .map_err(|error| Error {
> +                    error,
> +                    clk: ManuallyDrop::into_inner(clk),
> +                })
>         }
> +    }
> 

— Daniel


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ