7
7
use crate :: { bindings, device:: Device , error:: Error , error:: Result , str:: CStr } ;
8
8
use core:: ptr:: NonNull ;
9
9
10
- // One of the following: `bindings::request_firmware`, `bindings::firmware_request_nowarn`,
11
- // `firmware_request_platform`, `bindings::request_firmware_direct`
12
- type FwFunc =
13
- unsafe extern "C" fn ( * mut * const bindings:: firmware , * const i8 , * mut bindings:: device ) -> i32 ;
10
+ /// # Invariants
11
+ ///
12
+ /// One of the following: `bindings::request_firmware`, `bindings::firmware_request_nowarn`,
13
+ /// `bindings::firmware_request_platform`, `bindings::request_firmware_direct`.
14
+ struct FwFunc (
15
+ unsafe extern "C" fn ( * mut * const bindings:: firmware , * const i8 , * mut bindings:: device ) -> i32 ,
16
+ ) ;
17
+
18
+ impl FwFunc {
19
+ fn request ( ) -> Self {
20
+ Self ( bindings:: request_firmware)
21
+ }
22
+
23
+ fn request_nowarn ( ) -> Self {
24
+ Self ( bindings:: firmware_request_nowarn)
25
+ }
26
+ }
14
27
15
28
/// Abstraction around a C `struct firmware`.
16
29
///
@@ -48,7 +61,7 @@ impl Firmware {
48
61
49
62
// SAFETY: `pfw` is a valid pointer to a NULL initialized `bindings::firmware` pointer.
50
63
// `name` and `dev` are valid as by their type invariants.
51
- let ret = unsafe { func ( pfw as _ , name. as_char_ptr ( ) , dev. as_raw ( ) ) } ;
64
+ let ret = unsafe { func. 0 ( pfw as _ , name. as_char_ptr ( ) , dev. as_raw ( ) ) } ;
52
65
if ret != 0 {
53
66
return Err ( Error :: from_errno ( ret) ) ;
54
67
}
@@ -60,13 +73,13 @@ impl Firmware {
60
73
61
74
/// Send a firmware request and wait for it. See also `bindings::request_firmware`.
62
75
pub fn request ( name : & CStr , dev : & Device ) -> Result < Self > {
63
- Self :: request_internal ( name, dev, bindings :: request_firmware )
76
+ Self :: request_internal ( name, dev, FwFunc :: request ( ) )
64
77
}
65
78
66
79
/// Send a request for an optional firmware module. See also
67
80
/// `bindings::firmware_request_nowarn`.
68
81
pub fn request_nowarn ( name : & CStr , dev : & Device ) -> Result < Self > {
69
- Self :: request_internal ( name, dev, bindings :: firmware_request_nowarn )
82
+ Self :: request_internal ( name, dev, FwFunc :: request_nowarn ( ) )
70
83
}
71
84
72
85
fn as_raw ( & self ) -> * mut bindings:: firmware {
0 commit comments