public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: opp: simplify callers of `to_c_str_array`
@ 2025-10-20 13:07 Tamir Duberstein
  2025-10-22  5:40 ` Viresh Kumar
  0 siblings, 1 reply; 5+ messages in thread
From: Tamir Duberstein @ 2025-10-20 13:07 UTC (permalink / raw)
  To: Viresh Kumar, Nishanth Menon, Stephen Boyd, Miguel Ojeda,
	Alex Gaynor, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich
  Cc: linux-pm, rust-for-linux, linux-kernel, Tamir Duberstein

Use `Option` combinators to make this a bit less noisy.

Signed-off-by: Tamir Duberstein <tamird@kernel.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());
 
         let prop_name = self
             .prop_name

---
base-commit: a1ec674cd709fec213acbb567e699c5f6f58cb60
change-id: 20251018-opp-simpler-code-58662c627bf4

Best regards,
--  
Tamir Duberstein <tamird@kernel.org>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-23 13:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-20 13:07 [PATCH] rust: opp: simplify callers of `to_c_str_array` Tamir Duberstein
2025-10-22  5:40 ` Viresh Kumar
2025-10-22 11:22   ` Tamir Duberstein
2025-10-23 11:32     ` Viresh Kumar
2025-10-23 13:24       ` Tamir Duberstein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox