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: <CAJ-ks9mKiXR-8m_9x_k6YcL64h+QWExkiWCHMFNJbdUYQvPsNA@mail.gmail.com>
Date: Wed, 22 Oct 2025 07:22:30 -0400
From: Tamir Duberstein <tamird@...nel.org>
To: Viresh Kumar <viresh.kumar@...aro.org>
Cc: Viresh Kumar <vireshk@...nel.org>, Nishanth Menon <nm@...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>, linux-pm@...r.kernel.org, rust-for-linux@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: opp: simplify callers of `to_c_str_array`

Hi Viresh,

On Wed, Oct 22, 2025 at 1:40 AM Viresh Kumar <viresh.kumar@...aro.org> wrote:
>
> Hi Tamir,
>
> On 20-10-25, 09:07, Tamir Duberstein wrote:
> > Use `Option` combinators to make this a bit less noisy.
> >
> > Signed-off-by: Tamir Duberstein <tamird@...nel.org>
> > ---
> >  rust/kernel/opp.rs | 25 ++++++++-----------------
> >  1 file changed, 8 insertions(+), 17 deletions(-)
> >
> > diff --git a/rust/kernel/opp.rs b/rust/kernel/opp.rs
> > index 9d6c58178a6f..b84786f45522 100644
> > --- a/rust/kernel/opp.rs
> > +++ b/rust/kernel/opp.rs
> > @@ -443,23 +443,14 @@ pub fn set_supported_hw(mut self, hw: KVec<u32>) -> Result<Self> {
> >      ///
> >      /// The returned [`ConfigToken`] will remove the configuration when dropped.
> >      pub fn set(self, dev: &Device) -> Result<ConfigToken> {
> > -        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()),
> > -        };
> > -
> > -        let (_regulator_list, regulator_names) = match &self.regulator_names {
> > -            Some(x) => {
> > -                let list = to_c_str_array(x)?;
> > -                let ptr = list.as_ptr();
> > -                (Some(list), ptr)
> > -            }
> > -            None => (None, ptr::null()),
> > -        };
> > +        let clk_names = self.clk_names.as_deref().map(to_c_str_array).transpose()?;
> > +        let clk_names = clk_names.map_or(ptr::null(), |c| c.as_ptr());
> > +        let regulator_names = self
> > +            .regulator_names
> > +            .as_deref()
> > +            .map(to_c_str_array)
> > +            .transpose()?;
> > +        let regulator_names = regulator_names.map_or(ptr::null(), |c| c.as_ptr());
>
> I had to keep _clk_list and _regulator_list earlier to make sure the list isn't
> freed while its pointer is still used (sent to dev_pm_opp_set_config()). Won't
> this change cause an issue here ?

I believe the `{clk,regulator}_names` vector bindings remain alive for
the whole scope, even if they are shadowed. See
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=800b334c514c2024d7b5e47fc54c1f2d.

Cheers.
Tamir

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ