File tree 1 file changed +22
-0
lines changed 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 {
106
106
}
107
107
}
108
108
109
+ #[ doc( hidden) ]
109
110
pub fn from_kernel_result_helper < T > ( r : Result < T > ) -> T
110
111
where
111
112
T : TryFrom < c_types:: c_int > ,
@@ -117,6 +118,27 @@ where
117
118
}
118
119
}
119
120
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
+ /// ```
120
142
#[ macro_export]
121
143
macro_rules! from_kernel_result {
122
144
( $( $tt: tt) * ) => { {
You can’t perform that action at this time.
0 commit comments