@@ -24,7 +24,7 @@ pub struct DriverRegistration {
24
24
this_module : & ' static crate :: ThisModule ,
25
25
registered : bool ,
26
26
name : CStr < ' static > ,
27
- spi_driver : Option < bindings:: spi_driver > ,
27
+ spi_driver : bindings:: spi_driver ,
28
28
}
29
29
30
30
pub struct ToUse {
@@ -42,15 +42,15 @@ pub const USE_NONE: ToUse = ToUse {
42
42
pub trait SpiMethods {
43
43
const TO_USE : ToUse ;
44
44
45
- fn probe ( _spi_dev : SpiDevice ) -> Result {
45
+ fn probe ( mut _spi_dev : SpiDevice ) -> Result {
46
46
Ok ( ( ) )
47
47
}
48
48
49
- fn remove ( _spi_dev : SpiDevice ) -> Result {
49
+ fn remove ( mut _spi_dev : SpiDevice ) -> Result {
50
50
Ok ( ( ) )
51
51
}
52
52
53
- fn shutdown ( _spi_dev : SpiDevice ) { }
53
+ fn shutdown ( mut _spi_dev : SpiDevice ) { }
54
54
}
55
55
56
56
/// Populate the TO_USE field in the `SpiMethods` implementer
@@ -97,7 +97,7 @@ impl DriverRegistration {
97
97
this_module,
98
98
name,
99
99
registered : false ,
100
- spi_driver : None ,
100
+ spi_driver : bindings :: spi_driver :: default ( ) ,
101
101
}
102
102
}
103
103
@@ -147,23 +147,23 @@ impl DriverRegistration {
147
147
}
148
148
}
149
149
150
- let mut spi_driver = bindings:: spi_driver:: default ( ) ;
151
- spi_driver. driver . name = self . name . as_ptr ( ) as * const c_types:: c_char ;
152
-
153
- spi_driver. probe = maybe_get_wrapper ( T :: TO_USE . probe , DriverRegistration :: probe_wrapper :: < T > ) ;
154
- spi_driver. remove = maybe_get_wrapper ( T :: TO_USE . remove , DriverRegistration :: remove_wrapper :: < T > ) ;
155
- spi_driver. shutdown = maybe_get_wrapper ( T :: TO_USE . shutdown , DriverRegistration :: shutdown_wrapper :: < T > ) ;
156
-
157
150
let this = unsafe { self . get_unchecked_mut ( ) } ;
158
151
if this. registered {
159
152
return Err ( Error :: EINVAL ) ;
160
153
}
161
154
162
- this. spi_driver = Some ( spi_driver) ;
155
+ this. spi_driver . driver . name = this. name . as_ptr ( ) as * const c_types:: c_char ;
156
+ this. spi_driver . probe =
157
+ maybe_get_wrapper ( T :: TO_USE . probe , DriverRegistration :: probe_wrapper :: < T > ) ;
158
+ this. spi_driver . remove =
159
+ maybe_get_wrapper ( T :: TO_USE . remove , DriverRegistration :: remove_wrapper :: < T > ) ;
160
+ this. spi_driver . shutdown = maybe_get_wrapper (
161
+ T :: TO_USE . shutdown ,
162
+ DriverRegistration :: shutdown_wrapper :: < T > ,
163
+ ) ;
163
164
164
- let res = unsafe {
165
- bindings:: __spi_register_driver ( this. this_module . 0 , this. spi_driver . as_mut ( ) . unwrap ( ) )
166
- } ;
165
+ let res =
166
+ unsafe { bindings:: __spi_register_driver ( this. this_module . 0 , & mut this. spi_driver ) } ;
167
167
168
168
match res {
169
169
0 => {
@@ -177,8 +177,7 @@ impl DriverRegistration {
177
177
178
178
impl Drop for DriverRegistration {
179
179
fn drop ( & mut self ) {
180
- unsafe { bindings:: driver_unregister ( & mut self . spi_driver . as_mut ( ) . unwrap ( ) . driver ) }
181
- // FIXME: No unwrap? But it's safe?
180
+ unsafe { bindings:: driver_unregister ( & mut self . spi_driver . driver ) }
182
181
}
183
182
}
184
183
0 commit comments