libfdt: Replace helper functions with FdtRawResult
Move all FFI interfaces to the newly-introduced FdtRawResult,
implementing TryFrom<FdtRawResult> as needed, and remove the
now-obsolete helper functions.
Note that all low-level libfdt wrappers now simply return
FdtRawResult::from(ret).try_into()
Test: m pvmfw
Test: atest liblibfdt.integration_test
Change-Id: I54ee0330556533a7a8d0ce07f15fed50849260eb
diff --git a/libs/libfdt/src/result.rs b/libs/libfdt/src/result.rs
index 65ef55d..52291ca 100644
--- a/libs/libfdt/src/result.rs
+++ b/libs/libfdt/src/result.rs
@@ -14,7 +14,7 @@
//! Rust types related to the libfdt C integer results.
-use core::ffi::c_int;
+use core::ffi::{c_int, c_uint};
use core::fmt;
use core::result;
@@ -94,18 +94,6 @@
/// Result type with FdtError enum.
pub type Result<T> = result::Result<T, FdtError>;
-pub(crate) fn fdt_err(val: c_int) -> Result<c_int> {
- FdtRawResult::from(val).try_into()
-}
-
-pub(crate) fn fdt_err_expect_zero(val: c_int) -> Result<()> {
- FdtRawResult::from(val).try_into()
-}
-
-pub(crate) fn fdt_err_or_option(val: c_int) -> Result<Option<c_int>> {
- FdtRawResult::from(val).try_into()
-}
-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct FdtRawResult(c_int);
@@ -164,6 +152,34 @@
}
}
+impl TryFrom<FdtRawResult> for c_uint {
+ type Error = FdtError;
+
+ fn try_from(res: FdtRawResult) -> Result<Self> {
+ Ok(c_int::try_from(res)?.try_into().unwrap())
+ }
+}
+
+impl TryFrom<FdtRawResult> for usize {
+ type Error = FdtError;
+
+ fn try_from(res: FdtRawResult) -> Result<Self> {
+ Ok(c_int::try_from(res)?.try_into().unwrap())
+ }
+}
+
+impl TryFrom<FdtRawResult> for Option<usize> {
+ type Error = FdtError;
+
+ fn try_from(res: FdtRawResult) -> Result<Self> {
+ match res.try_into() {
+ Ok(n) => Ok(Some(n)),
+ Err(FdtError::NotFound) => Ok(None),
+ Err(e) => Err(e),
+ }
+ }
+}
+
impl TryFrom<FdtRawResult> for () {
type Error = FdtError;