[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ms55ue7qqbvoyfhptzu2a5cuthusihtobremhuqfm7lyu7b62o@qasunalgkptl>
Date: Wed, 22 Oct 2025 11:10:33 +0530
From: Viresh Kumar <viresh.kumar@...aro.org>
To: Tamir Duberstein <tamird@...nel.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 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 ?
--
viresh
Powered by blists - more mailing lists