Skip to content

Commit 2ce3372

Browse files
author
Sven Van Asbroeck
committed
rust/kernel: document from_kernel_result! macro
This is required to pass the CI. Signed-off-by: Sven Van Asbroeck <thesven73@gmail.com>
1 parent 7dbb95f commit 2ce3372

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rust/kernel/error.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl From<AllocError> for Error {
106106
}
107107
}
108108

109+
#[doc(hidden)]
109110
pub fn from_kernel_result_helper<T>(r: Result<T>) -> T
110111
where
111112
T: TryFrom<c_types::c_int>,
@@ -117,6 +118,27 @@ where
117118
}
118119
}
119120

121+
/// Transforms a [`crate::error::Result<T>`] to a kernel C integer result.
122+
///
123+
/// This is useful when calling Rust functions that return [`crate::error::Result<T>`]
124+
/// from inside `extern "C"` functions that need to return an integer
125+
/// error result.
126+
///
127+
/// `T` should be convertible to an integer via `TryFrom<c_types::c_int>`.
128+
///
129+
/// # Examples
130+
///
131+
/// ```rust,no_run
132+
/// unsafe extern "C" fn probe_callback(
133+
/// pdev: *mut bindings::platform_device,
134+
/// ) -> c_types::c_int {
135+
/// from_kernel_result! {
136+
/// let ptr = devm_alloc(pdev)?;
137+
/// rust_helper_platform_set_drvdata(pdev, ptr);
138+
/// Ok(0)
139+
/// }
140+
/// }
141+
/// ```
120142
#[macro_export]
121143
macro_rules! from_kernel_result {
122144
($($tt:tt)*) => {{

0 commit comments

Comments
 (0)