Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Onur Özkan and committed by
Viresh Kumar
22763c35 8f5ae30d

+5 -11
+5 -11
rust/kernel/opp.rs
··· 12 12 clk::Hertz, 13 13 cpumask::{Cpumask, CpumaskVar}, 14 14 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}, 16 16 ffi::c_ulong, 17 17 prelude::*, 18 18 str::CString, ··· 500 500 // requirements. The OPP core guarantees not to access fields of [`Config`] after this call 501 501 // and so we don't need to save a copy of them for future use. 502 502 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)) 508 505 } 509 506 510 507 /// Config's clk callback. ··· 710 713 // SAFETY: The requirements are satisfied by the existence of [`Device`] and its safety 711 714 // requirements. 712 715 let ret = unsafe { bindings::dev_pm_opp_get_opp_count(self.dev.as_raw()) }; 713 - if ret < 0 { 714 - Err(Error::from_errno(ret)) 715 - } else { 716 - Ok(ret as u32) 717 - } 716 + 717 + to_result(ret).map(|()| ret as u32) 718 718 } 719 719 720 720 /// Returns max clock latency (in nanoseconds) of the [`OPP`]s in the [`Table`].