Re: [RFC PATCH 1/3] rust: Add bindings for OPP framework

From: Benno Lossin
Date: Thu Apr 25 2024 - 11:51:57 EST


On 22.04.24 12:24, Viresh Kumar wrote:
> Thanks for the review Benno. I was waiting for more review comments to
> come in and hence didn't reply earlier with an update.
>
> On 07-04-24, 09:54, Benno Lossin wrote:
>> On 05.04.24 13:09, Viresh Kumar wrote:
>>> + clk_names: Option<Pin<Vec<CString>>>,
>>
>> Why are you using `Pin<Vec<_>>`? The vector may reallocate the backing
>> storage at any point in time.
>
>>> + /// 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.
>
>>> +#[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.
>
> All these comments look good to me. Updated the code with them (not
> reposting them for now)

I currently do not have a lot of time, so I will re-review it when you
post a new version.

> -------------------------8<-------------------------
>
> rust/bindings/bindings_helper.h | 1 +
> rust/kernel/lib.rs | 2 +
> rust/kernel/opp.rs | 888 ++++++++++++++++++++++++++++++++

One other nice thing that you could do would be to split this patch into
multiple smaller ones. That makes understanding the pieces a lot easier.

--
Cheers,
Benno