Skip to content

Commit 22763c3

Browse files
onur-ozkanvireshk
authored andcommitted
rust: opp: use to_result for error handling
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>
1 parent 8f5ae30 commit 22763c3

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

rust/kernel/opp.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
clk::Hertz,
1313
cpumask::{Cpumask, CpumaskVar},
1414
device::Device,
15-
error::{code::*, from_err_ptr, from_result, to_result, Error, Result, VTABLE_DEFAULT_ERROR},
15+
error::{code::*, from_err_ptr, from_result, to_result, Result, VTABLE_DEFAULT_ERROR},
1616
ffi::c_ulong,
1717
prelude::*,
1818
str::CString,
@@ -500,11 +500,8 @@ impl<T: ConfigOps + Default> Config<T> {
500500
// requirements. The OPP core guarantees not to access fields of [`Config`] after this call
501501
// and so we don't need to save a copy of them for future use.
502502
let ret = unsafe { bindings::dev_pm_opp_set_config(dev.as_raw(), &mut config) };
503-
if ret < 0 {
504-
Err(Error::from_errno(ret))
505-
} else {
506-
Ok(ConfigToken(ret))
507-
}
503+
504+
to_result(ret).map(|()| ConfigToken(ret))
508505
}
509506

510507
/// Config's clk callback.
@@ -713,11 +710,8 @@ impl Table {
713710
// SAFETY: The requirements are satisfied by the existence of [`Device`] and its safety
714711
// requirements.
715712
let ret = unsafe { bindings::dev_pm_opp_get_opp_count(self.dev.as_raw()) };
716-
if ret < 0 {
717-
Err(Error::from_errno(ret))
718-
} else {
719-
Ok(ret as u32)
720-
}
713+
714+
to_result(ret).map(|()| ret as u32)
721715
}
722716

723717
/// Returns max clock latency (in nanoseconds) of the [`OPP`]s in the [`Table`].

0 commit comments

Comments
 (0)