]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: opp: use to_result for error handling
authorOnur Özkan <work@onurozkan.dev>
Thu, 21 Aug 2025 09:16:05 +0000 (12:16 +0300)
committerViresh Kumar <viresh.kumar@linaro.org>
Tue, 26 Aug 2025 05:10:45 +0000 (10:40 +0530)
Simplifies error handling by replacing the manual check
of the return value with the `to_result` helper.

Signed-off-by: Onur Özkan <work@onurozkan.dev>
Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
rust/kernel/opp.rs

index 08126035d2c66f849e4893ff2418d46d28bee84c..9d79c2816af5ccf4168830c8416c450d8523a362 100644 (file)
@@ -12,7 +12,7 @@ use crate::{
     clk::Hertz,
     cpumask::{Cpumask, CpumaskVar},
     device::Device,
-    error::{code::*, from_err_ptr, from_result, to_result, Error, Result, VTABLE_DEFAULT_ERROR},
+    error::{code::*, from_err_ptr, from_result, to_result, Result, VTABLE_DEFAULT_ERROR},
     ffi::c_ulong,
     prelude::*,
     str::CString,
@@ -500,11 +500,8 @@ impl<T: ConfigOps + Default> Config<T> {
         // requirements. The OPP core guarantees not to access fields of [`Config`] after this call
         // and so we don't need to save a copy of them for future use.
         let ret = unsafe { bindings::dev_pm_opp_set_config(dev.as_raw(), &mut config) };
-        if ret < 0 {
-            Err(Error::from_errno(ret))
-        } else {
-            Ok(ConfigToken(ret))
-        }
+
+        to_result(ret).map(|()| ConfigToken(ret))
     }
 
     /// Config's clk callback.
@@ -713,11 +710,8 @@ impl Table {
         // SAFETY: The requirements are satisfied by the existence of [`Device`] and its safety
         // requirements.
         let ret = unsafe { bindings::dev_pm_opp_get_opp_count(self.dev.as_raw()) };
-        if ret < 0 {
-            Err(Error::from_errno(ret))
-        } else {
-            Ok(ret as u32)
-        }
+
+        to_result(ret).map(|()| ret as u32)
     }
 
     /// Returns max clock latency (in nanoseconds) of the [`OPP`]s in the [`Table`].