@@ -126,18 +126,19 @@ impl<B: UsbBus> ControlPipe<'_, B> {
126126 None
127127 }
128128
129- pub fn handle_out ( & mut self ) -> Option < Request > {
129+ pub fn handle_out ( & mut self ) -> Result < Option < Request > > {
130130 match self . state {
131131 ControlState :: DataOut ( req) => {
132132 let i = self . i ;
133133 let count = match self . ep_out . read ( & mut self . buf [ i..] ) {
134134 Ok ( count) => count,
135- Err ( UsbError :: WouldBlock ) => return None ,
136- Err ( _ ) => {
135+ Err ( UsbError :: WouldBlock ) => return Ok ( None ) ,
136+ Err ( _err ) => {
137137 // Failed to read or buffer overflow (overflow is only possible if the host
138138 // sends more data than it indicated in the SETUP request)
139+ usb_debug ! ( "Failed EP0 read: {:?}" , _err) ;
139140 self . set_error ( ) ;
140- return None ;
141+ return Ok ( None ) ;
141142 }
142143 } ;
143144
@@ -151,7 +152,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
151152 if self . i >= self . len {
152153 usb_debug ! ( "Request OUT complete: {:?}" , req) ;
153154 self . state = ControlState :: CompleteOut ;
154- return Some ( req) ;
155+ return Ok ( Some ( req) ) ;
155156 }
156157 }
157158 // The host may terminate a DATA stage early by sending a zero-length status packet
@@ -164,7 +165,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
164165 "Control transfer completed. Current state: {:?}" ,
165166 self . state
166167 ) ;
167- let _ = self . ep_out . read ( & mut [ ] ) ;
168+ self . ep_out . read ( & mut [ ] ) ? ;
168169 self . state = ControlState :: Idle ;
169170 }
170171 _ => {
@@ -173,28 +174,23 @@ impl<B: UsbBus> ControlPipe<'_, B> {
173174 "Discarding EP0 data due to unexpected state. Current state: {:?}" ,
174175 self . state
175176 ) ;
176- let _ = self . ep_out . read ( & mut [ ] ) ;
177+ self . ep_out . read ( & mut [ ] ) ? ;
177178
178179 // Unexpected OUT packet
179180 self . set_error ( )
180181 }
181182 }
182183
183- None
184+ Ok ( None )
184185 }
185186
186- pub fn handle_in_complete ( & mut self ) -> bool {
187+ pub fn handle_in_complete ( & mut self ) -> Result < bool > {
187188 match self . state {
188189 ControlState :: DataIn => {
189- self . write_in_chunk ( ) ;
190+ self . write_in_chunk ( ) ? ;
190191 }
191192 ControlState :: DataInZlp => {
192- if self . ep_in . write ( & [ ] ) . is_err ( ) {
193- // There isn't much we can do if the write fails, except to wait for another
194- // poll or for the host to resend the request.
195- return false ;
196- }
197-
193+ self . ep_in . write ( & [ ] ) ?;
198194 usb_trace ! ( "wrote EP0: ZLP" ) ;
199195 self . state = ControlState :: DataInLast ;
200196 }
@@ -204,7 +200,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
204200 }
205201 ControlState :: StatusIn => {
206202 self . state = ControlState :: Idle ;
207- return true ;
203+ return Ok ( true ) ;
208204 }
209205 ControlState :: Idle => {
210206 // If we received a message on EP0 while sending the last portion of an IN
@@ -218,23 +214,14 @@ impl<B: UsbBus> ControlPipe<'_, B> {
218214 }
219215 } ;
220216
221- false
217+ Ok ( false )
222218 }
223219
224- fn write_in_chunk ( & mut self ) {
220+ fn write_in_chunk ( & mut self ) -> Result < ( ) > {
225221 let count = min ( self . len - self . i , self . ep_in . max_packet_size ( ) as usize ) ;
226222
227223 let buffer = self . static_in_buf . unwrap_or ( & self . buf ) ;
228- let count = match self . ep_in . write ( & buffer[ self . i ..( self . i + count) ] ) {
229- Ok ( c) => c,
230- // There isn't much we can do if the write fails, except to wait for another poll or for
231- // the host to resend the request.
232- Err ( _err) => {
233- usb_debug ! ( "Failed to write EP0: {:?}" , _err) ;
234- return ;
235- }
236- } ;
237-
224+ let count = self . ep_in . write ( & buffer[ self . i ..( self . i + count) ] ) ?;
238225 usb_trace ! ( "wrote EP0: {:?}" , & buffer[ self . i..( self . i + count) ] ) ;
239226
240227 self . i += count;
@@ -248,6 +235,8 @@ impl<B: UsbBus> ControlPipe<'_, B> {
248235 ControlState :: DataInLast
249236 } ;
250237 }
238+
239+ Ok ( ( ) )
251240 }
252241
253242 pub fn accept_out ( & mut self ) -> Result < ( ) > {
@@ -259,7 +248,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
259248 }
260249 } ;
261250
262- let _ = self . ep_in . write ( & [ ] ) ;
251+ self . ep_in . write ( & [ ] ) ? ;
263252 self . state = ControlState :: StatusIn ;
264253 Ok ( ( ) )
265254 }
@@ -301,7 +290,7 @@ impl<B: UsbBus> ControlPipe<'_, B> {
301290 self . len = min ( data_len, req. length as usize ) ;
302291 self . i = 0 ;
303292 self . state = ControlState :: DataIn ;
304- self . write_in_chunk ( ) ;
293+ self . write_in_chunk ( ) ? ;
305294
306295 Ok ( ( ) )
307296 }
0 commit comments