linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benno Lossin <benno.lossin@proton.me>
To: "Viresh Kumar" <viresh.kumar@linaro.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"Alice Ryhl" <aliceryhl@google.com>
Cc: linux-pm@vger.kernel.org,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Stephen Boyd" <sboyd@kernel.org>, "Nishanth Menon" <nm@ti.com>,
	rust-for-linux@vger.kernel.org,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Erik Schilling" <erik.schilling@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Joakim Bech" <joakim.bech@linaro.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/3] rust: Add bindings for OPP framework
Date: Sun, 07 Apr 2024 09:54:19 +0000	[thread overview]
Message-ID: <ff6c7d5e-d6e9-4331-b8cc-eab139160e59@proton.me> (raw)
In-Reply-To: <06bb914eae00671a69b393bf86bb01ddec86c16f.1712314032.git.viresh.kumar@linaro.org>

Hi,

I took a quick look and left some comments from the Rust side of view.

On 05.04.24 13:09, Viresh Kumar wrote:
> +/// Equivalent to `struct dev_pm_opp_config` in the C Code.
> +pub struct Config<T: ConfigOps> {
> +    token: Option<i32>,
> +    clk_names: Option<Pin<Vec<CString>>>,

Why are you using `Pin<Vec<_>>`? The vector may reallocate the backing
storage at any point in time.

> +    prop_name: Option<Pin<CString>>,
> +    regulator_names: Option<Pin<Vec<CString>>>,
> +    genpd_names: Option<Pin<Vec<CString>>>,
> +    supported_hw: Option<Pin<Vec<u32>>>,
> +    required_devs: Option<Pin<Vec<Device>>>,
> +    _data: PhantomData<T>,
> +}

[...]

> +    /// Sets the configuration with the OPP core.
> +    pub fn set(&mut self, dev: &Device) -> Result<()> {
> +        // Already configured.
> +        if self.token.is_some() {

Why does the config hold onto this token? Would it make sense to consume
the config and return a `Handle` or `Token` abstraction? Then you don't
need to check if the config has been "used" before.

> +            return Err(EBUSY);
> +        }
> +
> +        let (_clk_list, clk_names) = match &self.clk_names {
> +            Some(x) => {
> +                let list = to_c_str_array(x)?;
> +                let ptr = list.as_ptr();
> +                (Some(list), ptr)
> +            }
> +            None => (None, ptr::null()),
> +        };

[...]

> +/// Operating performance point (OPP).
> +///
> +/// # Invariants
> +///
> +/// `ptr` is valid, non-null, and has a non-zero reference count. One of the references is owned by
> +/// `self`, and will be decremented when `self` is dropped.
> +#[repr(transparent)]
> +pub struct OPP(*mut bindings::dev_pm_opp);

I think you should use the `ARef` pattern instead:

     #[repr(transparent)]
     pub struct OPP(Opaque<bindings::dev_pm_opp>);

     unsafe impl AlwaysRefCounted for OPP {
         // ...
     }

Then you can use `ARef<OPP>` everywhere you use `OPP` currently.

-- 
Cheers,
Benno


  reply	other threads:[~2024-04-07  9:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-05 11:09 [RFC PATCH 0/3] Rust bindings for cpufreq and OPP core + sample driver Viresh Kumar
2024-04-05 11:09 ` [RFC PATCH 1/3] rust: Add bindings for OPP framework Viresh Kumar
2024-04-07  9:54   ` Benno Lossin [this message]
2024-04-22 10:24     ` Viresh Kumar
2024-04-25 15:51       ` Benno Lossin
2024-04-05 11:09 ` [RFC PATCH 2/3] rust: Add bindings for cpufreq framework Viresh Kumar
2024-04-05 11:09 ` [RFC PATCH 3/3] cpufreq: Add Rust based cpufreq-dt driver Viresh Kumar
2024-04-07  9:54   ` Benno Lossin
2024-04-07 10:17     ` Benno Lossin
2024-04-22 10:30       ` Viresh Kumar
2024-04-25 15:54         ` Benno Lossin

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=ff6c7d5e-d6e9-4331-b8cc-eab139160e59@proton.me \
    --to=benno.lossin@proton.me \
    --cc=a.hindborg@samsung.com \
    --cc=alex.bennee@linaro.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=erik.schilling@linaro.org \
    --cc=gary@garyguo.net \
    --cc=joakim.bech@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=nm@ti.com \
    --cc=ojeda@kernel.org \
    --cc=rafael@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=wedsonaf@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).