rust: shorten `con_id`s in `get` methods in clk module
Subsystems (2)
Onur Özkan
reviewerPATCH 1/1 rust: shorten `con_id`s in `get` methods in clk module
Converts if-else blocks into one line code using map_or for simplicity.
Signed-off-by Onur Özkan <[email protected]>
--- rust/kernel/clk.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
rust/kernel/clk.rs +2 -10
@@ -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
Quoted 8 lines · Onur Özkan
Converts
if-elseblocks into one line code usingmap_orfor simplicity.Signed-off-by Onur Özkan <[email protected]>--- rust/kernel/clk.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
Acked-by Viresh Kumar <[email protected]>
Quoted 4 lines · Onur Özkan
Converts
if-elseblocks into one line code usingmap_orfor simplicity.Signed-off-by Onur Özkan <[email protected]>
FWIW,
Reviewed-by Alexandre Courbot <[email protected]>
Quoting Onur Özkan (2025-06-18 02:35:08)
Quoted 5 lines
Converts
if-elseblocks into one line code usingmap_orfor simplicity.Signed-off-by Onur Özkan <[email protected]>---
Applied to clk-next