6
6
7
7
use alloc:: { boxed:: Box , slice:: from_raw_parts_mut} ;
8
8
9
+ use crate :: prelude:: * ;
9
10
use crate :: {
10
11
bindings, error:: code:: * , error:: from_kernel_result, str:: CString , to_result,
11
12
types:: PointerWrapper , Result , ScopeGuard ,
@@ -14,10 +15,8 @@ use crate::{
14
15
use core:: { cell:: UnsafeCell , fmt, marker:: PhantomData , pin:: Pin } ;
15
16
16
17
/// This trait is implemented in order to provide callbacks to `struct hwrng`.
18
+ #[ vtable]
17
19
pub trait Operations {
18
- /// The methods to use to populate [`struct hwrng`].
19
- const TO_USE : ToUse ;
20
-
21
20
/// The pointer type that will be used to hold user-defined data type.
22
21
type Data : PointerWrapper + Send + Sync = ( ) ;
23
22
@@ -122,12 +121,12 @@ impl<T: Operations> Registration<T> {
122
121
) {
123
122
hwrng. name = name. as_char_ptr ( ) ;
124
123
125
- hwrng. init = if T :: TO_USE . init {
124
+ hwrng. init = if T :: HAS_INIT {
126
125
Some ( Self :: init_callback)
127
126
} else {
128
127
None
129
128
} ;
130
- hwrng. cleanup = if T :: TO_USE . cleanup {
129
+ hwrng. cleanup = if T :: HAS_CLEANUP {
131
130
Some ( Self :: cleanup_callback)
132
131
} else {
133
132
None
@@ -190,38 +189,6 @@ impl<T: Operations> Default for Registration<T> {
190
189
}
191
190
}
192
191
193
- /// Represents which callbacks of [`struct hwrng`] should be populated with pointers.
194
- pub struct ToUse {
195
- /// The `init` field of [`struct hwrng`].
196
- pub init : bool ,
197
-
198
- /// The `cleanup` field of [`struct hwrng`].
199
- pub cleanup : bool ,
200
- }
201
-
202
- /// A constant version where all values are to set to `false`, that is, all supported fields will
203
- /// be set to null pointers.
204
- pub const USE_NONE : ToUse = ToUse {
205
- init : false ,
206
- cleanup : false ,
207
- } ;
208
-
209
- /// Defines the [`Operations::TO_USE`] field based on a list of fields to be populated.
210
- #[ macro_export]
211
- macro_rules! declare_hwrng_operations {
212
- ( ) => {
213
- const TO_USE : $crate:: hwrng:: ToUse = $crate:: hwrng:: USE_NONE ;
214
- } ;
215
- ( $( $i: ident) ,+) => {
216
- #[ allow( clippy:: needless_update) ]
217
- const TO_USE : kernel:: hwrng:: ToUse =
218
- $crate:: hwrng:: ToUse {
219
- $( $i: true ) ,+ ,
220
- ..$crate:: hwrng:: USE_NONE
221
- } ;
222
- } ;
223
- }
224
-
225
192
// SAFETY: `Registration` does not expose any of its state across threads.
226
193
unsafe impl < T : Operations > Sync for Registration < T > { }
227
194
0 commit comments