浏览代码

fix(core/usbd_core): fix two bugs

- fix current_desc_len += p[DESC_bLength] before p+= p[DESC_bLength]
- fix reset all eps when alt_setting=0

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 10 月之前
父节点
当前提交
e581097309
共有 1 个文件被更改,包括 3 次插入5 次删除
  1. 3 5
      core/usbd_core.c

+ 3 - 5
core/usbd_core.c

@@ -446,8 +446,8 @@ static bool usbd_set_configuration(uint8_t busid, uint8_t config_index, uint8_t
         }
 
         /* skip to next descriptor */
-        p += p[DESC_bLength];
         current_desc_len += p[DESC_bLength];
+        p += p[DESC_bLength];
         if (current_desc_len >= desc_len && desc_len) {
             break;
         }
@@ -512,7 +512,6 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
 
                     if (alt_setting == 0) {
                         ret = usbd_reset_endpoint(busid, ep_desc);
-                        goto find_end;
                     } else if (cur_alt_setting == alt_setting) {
                         ret = usbd_set_endpoint(busid, ep_desc);
                     } else {
@@ -526,14 +525,13 @@ static bool usbd_set_interface(uint8_t busid, uint8_t iface, uint8_t alt_setting
         }
 
         /* skip to next descriptor */
-        p += p[DESC_bLength];
         current_desc_len += p[DESC_bLength];
+        p += p[DESC_bLength];
         if (current_desc_len >= desc_len && desc_len) {
             break;
         }
     }
 
-find_end:
     usbd_class_event_notify_handler(busid, USBD_EVENT_SET_INTERFACE, (void *)if_desc);
 
     return ret;
@@ -700,8 +698,8 @@ static bool usbd_std_interface_req_handler(uint8_t busid, struct usb_setup_packe
                     }
 
                     /* skip to next descriptor */
-                    p += p[DESC_bLength];
                     current_desc_len += p[DESC_bLength];
+                    p += p[DESC_bLength];
                     if (current_desc_len >= desc_len && desc_len) {
                         break;
                     }