File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ impl From<AllocError> for Error {
106106 }
107107}
108108
109+ #[ doc( hidden) ]
109110pub fn from_kernel_result_helper < T > ( r : Result < T > ) -> T
110111where
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]
121143macro_rules! from_kernel_result {
122144 ( $( $tt: tt) * ) => { {
You can’t perform that action at this time.
0 commit comments