rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: shorten `con_id`s in `get` methods in clk module
@ 2025-06-18  9:35 Onur Özkan
  2025-06-19 10:34 ` Viresh Kumar
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Onur Özkan @ 2025-06-18  9:35 UTC (permalink / raw)
  To: rust-for-linux, linux-clk, linux-kernel
  Cc: mturquette, sboyd, ojeda, alex.gaynor, boqun.feng, gary,
	bjorn3_gh, lossin, a.hindborg, aliceryhl, tmgross, dakr,
	Onur Özkan

Converts `if-else` blocks into one line code using `map_or`
for simplicity.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
---
 rust/kernel/clk.rs | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/rust/kernel/clk.rs b/rust/kernel/clk.rs
index 6041c6d07527..b09f295addce 100644
--- a/rust/kernel/clk.rs
+++ b/rust/kernel/clk.rs
@@ -132,11 +132,7 @@ impl Clk {
         ///
         /// [`clk_get`]: https://docs.kernel.org/core-api/kernel-api.html#c.clk_get
         pub fn get(dev: &Device, name: Option<&CStr>) -> Result<Self> {
-            let con_id = if let Some(name) = name {
-                name.as_ptr()
-            } else {
-                ptr::null()
-            };
+            let con_id = name.map_or(ptr::null(), |n| n.as_ptr());

             // SAFETY: It is safe to call [`clk_get`] for a valid device pointer.
             //
@@ -304,11 +300,7 @@ impl OptionalClk {
         /// [`clk_get_optional`]:
         /// https://docs.kernel.org/core-api/kernel-api.html#c.clk_get_optional
         pub fn get(dev: &Device, name: Option<&CStr>) -> Result<Self> {
-            let con_id = if let Some(name) = name {
-                name.as_ptr()
-            } else {
-                ptr::null()
-            };
+            let con_id = name.map_or(ptr::null(), |n| n.as_ptr());

             // SAFETY: It is safe to call [`clk_get_optional`] for a valid device pointer.
             //
2.49.0


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

end of thread, other threads:[~2025-06-19 19:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18  9:35 [PATCH] rust: shorten `con_id`s in `get` methods in clk module Onur Özkan
2025-06-19 10:34 ` Viresh Kumar
2025-06-19 13:42 ` Alexandre Courbot
2025-06-19 19:42 ` Stephen Boyd

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).