@@ -230,11 +230,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
230230 Some ( req) if req. direction == UsbDirection :: In => {
231231 if let Err ( _err) = self . control_in ( classes, req) {
232232 // TODO: Propagate error out of `poll()`
233- usb_debug ! ( "Failed to handle control request: {:?}" , _err) ;
233+ usb_debug ! ( "Failed to handle input control request: {:?}" , _err) ;
234234 }
235235 }
236236 Some ( req) if req. direction == UsbDirection :: Out => {
237- self . control_out ( classes, req)
237+ if let Err ( _err) = self . control_out ( classes, req) {
238+ // TODO: Propagate error out of `poll()`
239+ usb_debug ! ( "Failed to handle output control request: {:?}" , _err) ;
240+ }
238241 }
239242
240243 None if ( ( ep_in_complete & 1 ) != 0 ) => {
@@ -380,7 +383,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
380383
381384 ( Recipient :: Device , Request :: GET_DESCRIPTOR ) => {
382385 usb_trace ! ( "Processing Device::GetDescriptor" ) ;
383- UsbDevice :: get_descriptor ( & self . config , classes, xfer)
386+ UsbDevice :: get_descriptor ( & self . config , classes, xfer) ? ;
384387 }
385388
386389 ( Recipient :: Device , Request :: GET_CONFIGURATION ) => {
@@ -425,14 +428,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
425428 Ok ( ( ) )
426429 }
427430
428- fn control_out ( & mut self , classes : & mut ClassList < ' _ , B > , req : control:: Request ) {
431+ fn control_out ( & mut self , classes : & mut ClassList < ' _ , B > , req : control:: Request ) -> Result < ( ) > {
429432 use crate :: control:: { Recipient , Request } ;
430433
431434 for cls in classes. iter_mut ( ) {
432435 cls. control_out ( ControlOut :: new ( & mut self . control , & req) ) ;
433436
434437 if !self . control . waiting_for_response ( ) {
435- return ;
438+ return Ok ( ( ) ) ;
436439 }
437440 }
438441
@@ -451,14 +454,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
451454 ) => {
452455 usb_debug ! ( "Remote wakeup disabled" ) ;
453456 self . remote_wakeup_enabled = false ;
454- let _ = xfer. accept ( ) ;
457+ xfer. accept ( ) ? ;
455458 }
456459
457460 ( Recipient :: Endpoint , Request :: CLEAR_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
458461 usb_debug ! ( "EP{} halt removed" , req. index & 0x8f ) ;
459462 self . bus
460463 . set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , false ) ;
461- let _ = xfer. accept ( ) ;
464+ xfer. accept ( ) ? ;
462465 }
463466
464467 (
@@ -468,14 +471,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
468471 ) => {
469472 usb_debug ! ( "Remote wakeup enabled" ) ;
470473 self . remote_wakeup_enabled = true ;
471- let _ = xfer. accept ( ) ;
474+ xfer. accept ( ) ? ;
472475 }
473476
474477 ( Recipient :: Endpoint , Request :: SET_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
475478 usb_debug ! ( "EP{} halted" , req. index & 0x8f ) ;
476479 self . bus
477480 . set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , true ) ;
478- let _ = xfer. accept ( ) ;
481+ xfer. accept ( ) ? ;
479482 }
480483
481484 ( Recipient :: Device , Request :: SET_ADDRESS , 1 ..=127 ) => {
@@ -486,81 +489,89 @@ impl<B: UsbBus> UsbDevice<'_, B> {
486489 } else {
487490 self . pending_address = req. value as u8 ;
488491 }
489- let _ = xfer. accept ( ) ;
492+ xfer. accept ( ) ? ;
490493 }
491494
492495 ( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_VALUE_U16 ) => {
493496 usb_debug ! ( "Device configured" ) ;
494497 self . device_state = UsbDeviceState :: Configured ;
495- let _ = xfer. accept ( ) ;
498+ xfer. accept ( ) ? ;
496499 }
497500
498501 ( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_NONE_U16 ) => {
499502 usb_debug ! ( "Device deconfigured" ) ;
500503 match self . device_state {
501504 UsbDeviceState :: Default => {
502- let _ = xfer. accept ( ) ;
505+ xfer. accept ( ) ? ;
503506 }
504507 _ => {
505508 self . device_state = UsbDeviceState :: Addressed ;
506- let _ = xfer. accept ( ) ;
509+ xfer. accept ( ) ? ;
507510 }
508511 }
509512 }
510513
511514 ( Recipient :: Interface , Request :: SET_INTERFACE , alt_setting) => {
512515 // Reject interface numbers and alt settings bigger than 255
513516 if req. index > core:: u8:: MAX . into ( ) || alt_setting > core:: u8:: MAX . into ( ) {
514- let _ = xfer. reject ( ) ;
515- return ;
517+ xfer. reject ( ) ? ;
518+ return Ok ( ( ) ) ;
516519 }
517520
518521 // Ask class implementations, whether they accept the alternate interface setting.
519522 for cls in classes {
520523 if cls. set_alt_setting ( InterfaceNumber ( req. index as u8 ) , alt_setting as u8 )
521524 {
522- let _ = xfer. accept ( ) ;
523- return ;
525+ xfer. accept ( ) ? ;
526+ return Ok ( ( ) ) ;
524527 }
525528 }
526529
527530 // Default behaviour, if no class implementation accepted the alternate setting.
528531 if alt_setting == DEFAULT_ALTERNATE_SETTING_U16 {
529532 usb_debug ! ( "Accepting unused alternate settings" ) ;
530- let _ = xfer. accept ( ) ;
533+ xfer. accept ( ) ? ;
531534 } else {
532535 usb_debug ! ( "Rejecting unused alternate settings" ) ;
533- let _ = xfer. reject ( ) ;
536+ xfer. reject ( ) ? ;
534537 }
535538 }
536539
537540 _ => {
538- let _ = xfer. reject ( ) ;
539- return ;
541+ xfer. reject ( ) ? ;
542+ return Ok ( ( ) ) ;
540543 }
541544 }
542545 }
543546
544547 if self . control . waiting_for_response ( ) {
545548 usb_debug ! ( "Rejecting control transfer due to waiting response" ) ;
546- let _ = self . control . reject ( ) ;
549+ self . control . reject ( ) ? ;
547550 }
551+
552+ Ok ( ( ) )
548553 }
549554
550- fn get_descriptor ( config : & Config , classes : & mut ClassList < ' _ , B > , xfer : ControlIn < B > ) {
555+ fn get_descriptor (
556+ config : & Config ,
557+ classes : & mut ClassList < ' _ , B > ,
558+ xfer : ControlIn < B > ,
559+ ) -> Result < ( ) > {
551560 let req = * xfer. request ( ) ;
552561
553562 let ( dtype, index) = req. descriptor_type_index ( ) ;
554563
555564 fn accept_writer < B : UsbBus > (
556565 xfer : ControlIn < B > ,
557566 f : impl FnOnce ( & mut DescriptorWriter ) -> Result < ( ) > ,
558- ) {
559- let _ = xfer. accept ( |buf| {
567+ ) -> Result < ( ) > {
568+ xfer. accept ( |buf| {
560569 let mut writer = DescriptorWriter :: new ( buf) ;
561570 f ( & mut writer) ?;
562571 Ok ( writer. position ( ) )
563- } ) ;
572+ } ) ?;
573+
574+ Ok ( ( ) )
564575 }
565576
566577 match dtype {
@@ -575,9 +586,9 @@ impl<B: UsbBus> UsbDevice<'_, B> {
575586 bw. end_bos ( ) ;
576587
577588 Ok ( ( ) )
578- } ) ,
589+ } ) ? ,
579590
580- descriptor_type:: DEVICE => accept_writer ( xfer, |w| w. device ( config) ) ,
591+ descriptor_type:: DEVICE => accept_writer ( xfer, |w| w. device ( config) ) ? ,
581592
582593 descriptor_type:: CONFIGURATION => accept_writer ( xfer, |w| {
583594 w. configuration ( config) ?;
@@ -590,7 +601,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
590601 w. end_configuration ( ) ;
591602
592603 Ok ( ( ) )
593- } ) ,
604+ } ) ? ,
594605
595606 descriptor_type:: STRING => match index {
596607 // first STRING Request
@@ -608,7 +619,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
608619 descriptor_type:: STRING ,
609620 & lang_id_bytes[ ..config. string_descriptors . len ( ) * 2 ] ,
610621 )
611- } )
622+ } ) ? ;
612623 }
613624
614625 // rest STRING Requests
@@ -623,8 +634,8 @@ impl<B: UsbBus> UsbDevice<'_, B> {
623634 . iter ( )
624635 . find ( |lang| lang. id == lang_id)
625636 else {
626- xfer. reject ( ) . ok ( ) ;
627- return ;
637+ xfer. reject ( ) ? ;
638+ return Ok ( ( ) ) ;
628639 } ;
629640
630641 match index {
@@ -643,17 +654,19 @@ impl<B: UsbBus> UsbDevice<'_, B> {
643654 } ;
644655
645656 if let Some ( string_descriptor) = string {
646- accept_writer ( xfer, |w| w. string ( string_descriptor) ) ;
657+ accept_writer ( xfer, |w| w. string ( string_descriptor) ) ? ;
647658 } else {
648- let _ = xfer. reject ( ) ;
659+ xfer. reject ( ) ? ;
649660 }
650661 }
651662 } ,
652663
653664 _ => {
654- let _ = xfer. reject ( ) ;
665+ xfer. reject ( ) ? ;
655666 }
656- }
667+ } ;
668+
669+ Ok ( ( ) )
657670 }
658671
659672 fn reset ( & mut self , classes : & mut ClassList < ' _ , B > ) {
0 commit comments