summaryrefslogtreecommitdiff
path: root/class
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-11-18 21:03:04 +0800
committersakumisu <[email protected]>2026-11-18 21:03:04 +0800
commit62c3ff3c07b79dafbbd3dfaf0a354b9e718e31aa (patch)
tree5adef7a95dc97bdcfe22d73538c1443a1cb19d4f /class
parent738dedc6ec1968190ef17805fc4e37edbaec4ff3 (diff)
update(class): free class immediately in xxx_connect when return error
Signed-off-by: sakumisu <[email protected]>
Diffstat (limited to 'class')
-rw-r--r--class/aoa/usbh_aoa.c28
-rw-r--r--class/audio/usbh_audio.c70
-rw-r--r--class/cdc/usbh_cdc_ecm.c52
-rw-r--r--class/cdc/usbh_cdc_ncm.c47
-rw-r--r--class/hid/usbh_hid.c44
-rw-r--r--class/hub/usbh_hub.c69
-rw-r--r--class/msc/usbh_msc.c39
-rw-r--r--class/serial/usbh_cdc_acm.c7
-rw-r--r--class/serial/usbh_ch34x.c8
-rw-r--r--class/serial/usbh_cp210x.c7
-rw-r--r--class/serial/usbh_ftdi.c7
-rw-r--r--class/serial/usbh_gsm.c7
-rw-r--r--class/serial/usbh_pl2303.c8
-rw-r--r--class/serial/usbh_serial.c13
-rw-r--r--class/template/usbh_xxx.c38
-rw-r--r--class/vendor/net/usbh_asix.c49
-rw-r--r--class/vendor/net/usbh_rtl8152.c54
-rw-r--r--class/vendor/xbox/usbh_xbox.c30
-rw-r--r--class/video/usbh_video.c57
-rw-r--r--class/wireless/usbh_bluetooth.c66
-rw-r--r--class/wireless/usbh_rndis.c49
21 files changed, 389 insertions, 360 deletions
diff --git a/class/aoa/usbh_aoa.c b/class/aoa/usbh_aoa.c
index f5e798ef..e2a76615 100644
--- a/class/aoa/usbh_aoa.c
+++ b/class/aoa/usbh_aoa.c
@@ -227,7 +227,7 @@ static int usbh_aoa_connect(struct usbh_hubport *hport, uint8_t intf)
aoa_class->hport = hport;
aoa_class->intf = intf;
- hport->config.intf[intf].priv = aoa_class;
+ usbh_set_intf_data(hport, intf, aoa_class);
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
@@ -251,25 +251,21 @@ static int usbh_aoa_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_aoa *aoa_class = (struct usbh_aoa *)hport->config.intf[intf].priv;
+ struct usbh_aoa *aoa_class = (struct usbh_aoa *)usbh_get_intf_data(hport, intf);
- if (aoa_class) {
- if (aoa_class->bulkin) {
- usbh_kill_urb(&aoa_class->bulkin_urb);
- }
-
- if (aoa_class->bulkout) {
- usbh_kill_urb(&aoa_class->bulkout_urb);
- }
-
- if (hport->config.intf[intf].devname[0] != '\0') {
- USB_LOG_INFO("Unregister AOA Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_aoa_stop(aoa_class);
- }
+ if (aoa_class->bulkin) {
+ usbh_kill_urb(&aoa_class->bulkin_urb);
+ }
- memset(aoa_class, 0, sizeof(struct usbh_aoa));
+ if (aoa_class->bulkout) {
+ usbh_kill_urb(&aoa_class->bulkout_urb);
}
+ USB_LOG_INFO("Unregister AOA Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_aoa_stop(aoa_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(aoa_class, 0, sizeof(struct usbh_aoa));
return ret;
}
diff --git a/class/audio/usbh_audio.c b/class/audio/usbh_audio.c
index df41899d..9acd4d9d 100644
--- a/class/audio/usbh_audio.c
+++ b/class/audio/usbh_audio.c
@@ -735,7 +735,7 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
audio_class->hport = hport;
audio_class->ctrl_intf = intf;
- hport->config.intf[intf].priv = audio_class;
+ usbh_set_intf_data(hport, intf, audio_class);
p = hport->raw_config_desc;
while (desc_len < hport->config.config_desc.wTotalLength) {
@@ -746,7 +746,8 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
if ((cur_iface_count - 1) > CONFIG_USBHOST_AUDIO_MAX_STREAMS) {
USB_LOG_ERR("Audio stream %u exceeds max %u\r\n", (cur_iface_count - 1), CONFIG_USBHOST_AUDIO_MAX_STREAMS);
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
}
break;
@@ -772,7 +773,8 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
switch (p[DESC_bDescriptorSubType]) {
case AUDIO_CONTROL_HEADER: {
if (p[DESC_bLength] < sizeof(struct audio_cs_if_ac_header_descriptor)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
struct audio_cs_if_ac_header_descriptor *desc = (struct audio_cs_if_ac_header_descriptor *)p;
@@ -780,12 +782,13 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
if (desc->bInCollection == 0 ||
desc->bInCollection > CONFIG_USBHOST_AUDIO_MAX_STREAMS ||
desc->bcdADC >= 0x0200) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
ret = usbh_audio_check_ac_descriptors(p, hport->config.config_desc.wTotalLength - desc_len);
if (ret < 0) {
- return ret;
+ goto errout;
}
audio_class->bcdADC = desc->bcdADC;
@@ -801,7 +804,8 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
switch (p[DESC_bDescriptorSubType]) {
case AUDIO_STREAMING_GENERAL: {
if (p[DESC_bLength] < sizeof(struct audio_cs_if_as_general_descriptor)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
struct audio_cs_if_as_general_descriptor *desc = (struct audio_cs_if_as_general_descriptor *)p;
@@ -812,7 +816,8 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
} break;
case AUDIO_STREAMING_FORMAT_TYPE: {
if (p[DESC_bLength] < 8) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
struct audio_cs_if_as_format_type_descriptor *desc = (struct audio_cs_if_as_format_type_descriptor *)p;
@@ -821,11 +826,13 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
desc->bSamFreqType > CONFIG_USBHOST_AUDIO_MAX_SAMPLE_FREQ_NUM ||
desc->bNrChannels == 0 || desc->bNrChannels > CONFIG_USBHOST_AUDIO_MAX_CHANNELS ||
cur_alt_setting >= CONFIG_USBHOST_MAX_INTF_ALTSETTINGS) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
if (p[DESC_bLength] < AUDIO_SIZEOF_FORMAT_TYPE_DESC(desc->bSamFreqType)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
audio_class->as_msg_table[cur_iface - audio_class->ctrl_intf - 1].bNrChannels = desc->bNrChannels;
@@ -840,7 +847,8 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
if ((cur_iface > audio_class->ctrl_intf) && (cur_iface < (audio_class->ctrl_intf + cur_iface_count))) {
if (p[DESC_bDescriptorSubType] == AUDIO_ENDPOINT_GENERAL) {
if (p[DESC_bLength] < sizeof(struct audio_cs_ep_ep_general_descriptor)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
struct audio_cs_ep_ep_general_descriptor *desc = (struct audio_cs_ep_ep_general_descriptor *)p;
@@ -859,20 +867,23 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
if (p_ac_desc == NULL) {
USB_LOG_ERR("Fail to find audio control header descriptor\r\n");
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
for (uint8_t i = 0; i < audio_class->bInCollection; i++) {
feature_desc = usbh_audio_find_feature_unit(p_ac_desc, ac_desc_length, audio_class->as_msg_table[i].bTerminalLink, audio_class->as_msg_table[i].is_tx);
if (feature_desc == NULL) {
USB_LOG_ERR("Fail to find feature unit for stream %s\r\n", audio_class->as_msg_table[i].is_tx ? "tx" : "rx");
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
if ((feature_desc->bLength < 7) ||
(feature_desc->bLength > (sizeof(audio_class->as_msg_table[i].bmaControls) + 7)) ||
(feature_desc->bControlSize != 1)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
audio_class->as_msg_table[i].feature_unit_id = feature_desc->bUnitID;
@@ -883,7 +894,7 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_audio_close(audio_class, audio_class->as_msg_table[i].is_tx);
if (ret < 0) {
USB_LOG_ERR("Fail to close stream %s\r\n", audio_class->as_msg_table[i].is_tx ? "tx" : "rx");
- return ret;
+ goto errout;
}
}
@@ -894,30 +905,30 @@ static int usbh_audio_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
usbh_audio_run(audio_class);
return 0;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_audio_class_free(audio_class);
+ return ret;
}
static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_audio *audio_class = (struct usbh_audio *)hport->config.intf[intf].priv;
-
- if (audio_class) {
- if (audio_class->isoin) {
- }
-
- if (audio_class->isoout) {
- }
+ struct usbh_audio *audio_class = (struct usbh_audio *)usbh_get_intf_data(hport, intf);
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister Audio Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_audio_stop(audio_class);
- }
+ if (audio_class->isoin) {
+ }
- usbh_audio_class_free(audio_class);
+ if (audio_class->isoout) {
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister Audio Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_audio_stop(audio_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_audio_class_free(audio_class);
return ret;
}
@@ -930,8 +941,7 @@ static int usbh_audio_data_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_audio_data_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- (void)hport;
- (void)intf;
+ usbh_set_intf_data(hport, intf, NULL);
return 0;
}
diff --git a/class/cdc/usbh_cdc_ecm.c b/class/cdc/usbh_cdc_ecm.c
index 248b942b..f1fc95ba 100644
--- a/class/cdc/usbh_cdc_ecm.c
+++ b/class/cdc/usbh_cdc_ecm.c
@@ -89,11 +89,12 @@ static int usbh_cdc_ecm_connect(struct usbh_hubport *hport, uint8_t intf)
cdc_ecm_class->ctrl_intf = intf;
cdc_ecm_class->data_intf = intf + 1;
- hport->config.intf[intf].priv = cdc_ecm_class;
- hport->config.intf[intf + 1].priv = NULL;
+ usbh_set_intf_data(hport, intf, cdc_ecm_class);
+ usbh_set_intf_data(hport, intf + 1, NULL);
if (hport->config.intf[intf + 1].altsetting[0].intf_desc.bInterfaceClass != USB_DEVICE_CLASS_CDC_DATA) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
p = hport->raw_config_desc;
@@ -125,13 +126,14 @@ static int usbh_cdc_ecm_connect(struct usbh_hubport *hport, uint8_t intf)
get_mac:
if (mac_str_idx == 0xff) {
USB_LOG_ERR("Do not find cdc ecm mac string\r\n");
- return -1;
+ ret = -1;
+ goto errout;
}
memset(mac_buffer, 0, 12);
ret = usbh_get_string_desc(cdc_ecm_class->hport, mac_str_idx, (uint8_t *)mac_buffer, 12);
if (ret < 0) {
- return ret;
+ goto errout;
}
for (int i = 0, j = 0; i < 12; i += 2, j++) {
@@ -197,7 +199,7 @@ get_mac:
*/
ret = usbh_cdc_ecm_set_eth_packet_filter(cdc_ecm_class, CONFIG_USBHOST_CDC_ECM_PKT_FILTER);
if (ret < 0) {
- return ret;
+ goto errout;
}
USB_LOG_INFO("Set CDC ECM packet filter:%04x\r\n", CONFIG_USBHOST_CDC_ECM_PKT_FILTER);
@@ -207,36 +209,36 @@ get_mac:
usbh_cdc_ecm_run(cdc_ecm_class);
return ret;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(cdc_ecm_class, 0, sizeof(struct usbh_cdc_ecm));
+ return ret;
}
static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_cdc_ecm *cdc_ecm_class = (struct usbh_cdc_ecm *)hport->config.intf[intf].priv;
-
- if (cdc_ecm_class) {
- if (cdc_ecm_class->bulkin) {
- usbh_kill_urb(&cdc_ecm_class->bulkin_urb);
- }
+ struct usbh_cdc_ecm *cdc_ecm_class = (struct usbh_cdc_ecm *)usbh_get_intf_data(hport, intf);
- if (cdc_ecm_class->bulkout) {
- usbh_kill_urb(&cdc_ecm_class->bulkout_urb);
- }
-
- if (cdc_ecm_class->intin) {
- usbh_kill_urb(&cdc_ecm_class->intin_urb);
- }
+ if (cdc_ecm_class->bulkin) {
+ usbh_kill_urb(&cdc_ecm_class->bulkin_urb);
+ }
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister CDC ECM Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_cdc_ecm_stop(cdc_ecm_class);
- }
+ if (cdc_ecm_class->bulkout) {
+ usbh_kill_urb(&cdc_ecm_class->bulkout_urb);
+ }
- memset(cdc_ecm_class, 0, sizeof(struct usbh_cdc_ecm));
+ if (cdc_ecm_class->intin) {
+ usbh_kill_urb(&cdc_ecm_class->intin_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister CDC ECM Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_cdc_ecm_stop(cdc_ecm_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(cdc_ecm_class, 0, sizeof(struct usbh_cdc_ecm));
return ret;
}
diff --git a/class/cdc/usbh_cdc_ncm.c b/class/cdc/usbh_cdc_ncm.c
index e763d1ae..7976b71b 100644
--- a/class/cdc/usbh_cdc_ncm.c
+++ b/class/cdc/usbh_cdc_ncm.c
@@ -120,8 +120,8 @@ static int usbh_cdc_ncm_connect(struct usbh_hubport *hport, uint8_t intf)
cdc_ncm_class->ctrl_intf = intf;
cdc_ncm_class->data_intf = intf + 1;
- hport->config.intf[intf].priv = cdc_ncm_class;
- hport->config.intf[intf + 1].priv = NULL;
+ usbh_set_intf_data(hport, intf, cdc_ncm_class);
+ usbh_set_intf_data(hport, intf + 1, NULL);
p = hport->raw_config_desc;
while (desc_len < hport->config.config_desc.wTotalLength) {
@@ -152,13 +152,14 @@ static int usbh_cdc_ncm_connect(struct usbh_hubport *hport, uint8_t intf)
get_mac:
if (mac_str_idx == 0xff) {
USB_LOG_ERR("Do not find cdc ncm mac string\r\n");
- return -1;
+ ret = -1;
+ goto errout;
}
memset(mac_buffer, 0, 12);
ret = usbh_get_string_desc(cdc_ncm_class->hport, mac_str_idx, (uint8_t *)mac_buffer, 12);
if (ret < 0) {
- return ret;
+ goto errout;
}
for (int i = 0, j = 0; i < 12; i += 2, j++) {
@@ -225,36 +226,36 @@ get_mac:
usbh_cdc_ncm_run(cdc_ncm_class);
return ret;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(cdc_ncm_class, 0, sizeof(struct usbh_cdc_ncm));
+ return ret;
}
static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_cdc_ncm *cdc_ncm_class = (struct usbh_cdc_ncm *)hport->config.intf[intf].priv;
-
- if (cdc_ncm_class) {
- if (cdc_ncm_class->bulkin) {
- usbh_kill_urb(&cdc_ncm_class->bulkin_urb);
- }
-
- if (cdc_ncm_class->bulkout) {
- usbh_kill_urb(&cdc_ncm_class->bulkout_urb);
- }
+ struct usbh_cdc_ncm *cdc_ncm_class = (struct usbh_cdc_ncm *)usbh_get_intf_data(hport, intf);
- if (cdc_ncm_class->intin) {
- usbh_kill_urb(&cdc_ncm_class->intin_urb);
- }
+ if (cdc_ncm_class->bulkin) {
+ usbh_kill_urb(&cdc_ncm_class->bulkin_urb);
+ }
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister CDC NCM Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_cdc_ncm_stop(cdc_ncm_class);
- }
+ if (cdc_ncm_class->bulkout) {
+ usbh_kill_urb(&cdc_ncm_class->bulkout_urb);
+ }
- memset(cdc_ncm_class, 0, sizeof(struct usbh_cdc_ncm));
+ if (cdc_ncm_class->intin) {
+ usbh_kill_urb(&cdc_ncm_class->intin_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister CDC NCM Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_cdc_ncm_stop(cdc_ncm_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(cdc_ncm_class, 0, sizeof(struct usbh_cdc_ncm));
return ret;
}
diff --git a/class/hid/usbh_hid.c b/class/hid/usbh_hid.c
index 941e5877..39d89ced 100644
--- a/class/hid/usbh_hid.c
+++ b/class/hid/usbh_hid.c
@@ -191,6 +191,7 @@ int usbh_hid_get_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t
int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
{
struct usb_endpoint_descriptor *ep_desc;
+ int ret;
uint8_t cur_iface = 0xff;
uint8_t *p;
bool found = false;
@@ -205,7 +206,7 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
hid_class->hport = hport;
hid_class->intf = intf;
- hport->config.intf[intf].priv = hid_class;
+ usbh_set_intf_data(hport, intf, hid_class);
p = hport->raw_config_desc;
while (desc_len < hport->config.config_desc.wTotalLength) {
@@ -220,7 +221,8 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
if (desc->subdesc[0].bDescriptorType != HID_DESCRIPTOR_TYPE_HID_REPORT) {
USB_LOG_ERR("invalid bDescriptorType\r\n");
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
hid_class->report_size = desc->subdesc[0].wDescriptorLength;
@@ -238,14 +240,16 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
if (found == false) {
USB_LOG_ERR("HID report descriptor not found\r\n");
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
found:
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
if (USB_GET_ENDPOINT_TYPE(ep_desc->bmAttributes) != USB_ENDPOINT_TYPE_INTERRUPT) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
if (ep_desc->bEndpointAddress & 0x80) {
@@ -261,32 +265,32 @@ found:
usbh_hid_run(hid_class);
return 0;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_hid_class_free(hid_class);
+ return ret;
}
int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_hid *hid_class = (struct usbh_hid *)hport->config.intf[intf].priv;
-
- if (hid_class) {
- if (hid_class->intin) {
- usbh_kill_urb(&hid_class->intin_urb);
- }
-
- if (hid_class->intout) {
- usbh_kill_urb(&hid_class->intout_urb);
- }
+ struct usbh_hid *hid_class = (struct usbh_hid *)usbh_get_intf_data(hport, intf);
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister HID Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_hid_stop(hid_class);
- }
+ if (hid_class->intin) {
+ usbh_kill_urb(&hid_class->intin_urb);
+ }
- usbh_hid_class_free(hid_class);
+ if (hid_class->intout) {
+ usbh_kill_urb(&hid_class->intout_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister HID Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_hid_stop(hid_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_hid_class_free(hid_class);
return ret;
}
diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c
index ef31d5cb..05264d93 100644
--- a/class/hub/usbh_hub.c
+++ b/class/hub/usbh_hub.c
@@ -344,11 +344,12 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
hub->speed = hport->speed;
hport->self = hub;
- hport->config.intf[intf].priv = hub;
+ usbh_set_intf_data(hport, intf, hub);
if (hport->depth > HUB_MAX_DEPTH) {
USB_LOG_ERR("Hub depth(%d) is overflow\r\n", hport->depth);
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
/*
@@ -361,7 +362,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_hub_set_depth(hub, hport->depth - 1);
if (ret < 0) {
USB_LOG_ERR("Unable to set hub depth \r\n");
- return ret;
+ goto errout;
}
}
@@ -369,12 +370,12 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
if (hport->speed == USB_SPEED_SUPER) {
ret = _usbh_hub_get_hub_ss_descriptor(hub, (uint8_t *)&hub->hub_ss_desc);
if (ret < 0) {
- return ret;
+ goto errout;
}
ret = parse_hub_ss_descriptor(&hub->hub_ss_desc, USB_SIZEOF_HUB_SS_DESC);
if (ret < 0) {
- return ret;
+ goto errout;
}
nports = hub->hub_ss_desc.bNbrPorts;
@@ -383,12 +384,12 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
} else {
ret = _usbh_hub_get_hub_descriptor(hub, (uint8_t *)&hub->hub_desc);
if (ret < 0) {
- return ret;
+ goto errout;
}
ret = parse_hub_descriptor(&hub->hub_desc, USB_SIZEOF_HUB_DESC);
if (ret < 0) {
- return ret;
+ goto errout;
}
nports = hub->hub_desc.bNbrPorts;
hub->powerdelay = hub->hub_desc.bPwrOn2PwrGood * 2;
@@ -397,7 +398,8 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
if (nports > CONFIG_USBHOST_MAX_EHPORTS) {
USB_LOG_ERR("Hub nports %u overflow\r\n", nports);
- return -USB_ERR_NOMEM;
+ ret = -USB_ERR_NOMEM;
+ goto errout;
}
hub->nports = nports;
@@ -415,19 +417,21 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc;
if (USB_GET_ENDPOINT_TYPE(ep_desc->bmAttributes) != USB_ENDPOINT_TYPE_INTERRUPT) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
if (ep_desc->bEndpointAddress & 0x80) {
USBH_EP_INIT(hub->intin, ep_desc);
} else {
- return -1;
+ ret = -1;
+ goto errout;
}
for (uint8_t port = 0; port < hub->nports; port++) {
ret = usbh_hub_set_feature(hub, port + 1, HUB_PORT_FEATURE_POWER);
if (ret < 0) {
- return ret;
+ goto errout;
}
}
@@ -437,7 +441,7 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_hub_get_portstatus(hub, port + 1, &port_status);
USB_LOG_DBG("port %u, status:0x%03x, change:0x%02x\r\n", port + 1, port_status.wPortStatus, port_status.wPortChange);
if (ret < 0) {
- return ret;
+ goto errout;
}
}
@@ -451,10 +455,16 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
hub->int_timer = usb_osal_timer_create("hubint_tim", USBH_GET_URB_INTERVAL(hub->intin->bInterval, hport->speed) / 1000, hub_int_timeout, hub, 0);
if (hub->int_timer == NULL) {
USB_LOG_ERR("No memory to alloc int_timer\r\n");
- return -USB_ERR_NOMEM;
+ ret = -USB_ERR_NOMEM;
+ goto errout;
}
usb_osal_timer_start(hub->int_timer);
return 0;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ hport->self = NULL;
+ usbh_hub_class_free(hub);
+ return ret;
}
static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
@@ -462,29 +472,26 @@ static int usbh_hub_disconnect(struct usbh_hubport *hport, uint8_t intf)
struct usbh_hubport *child;
int ret = 0;
- struct usbh_hub *hub = (struct usbh_hub *)hport->config.intf[intf].priv;
+ struct usbh_hub *hub = (struct usbh_hub *)usbh_get_intf_data(hport, intf);
- if (hub) {
- if (hub->intin) {
- usbh_kill_urb(&hub->intin_urb);
- }
+ if (hub->intin) {
+ usbh_kill_urb(&hub->intin_urb);
+ }
- if (hub->int_timer) {
- usb_osal_timer_delete(hub->int_timer);
- }
+ if (hub->int_timer) {
+ usb_osal_timer_delete(hub->int_timer);
+ }
- for (uint8_t port = 0; port < hub->nports; port++) {
- child = &hub->child[port];
- usbh_hubport_release(child);
- child->parent = NULL;
- }
+ for (uint8_t port = 0; port < hub->nports; port++) {
+ child = &hub->child[port];
+ usbh_hubport_release(child);
+ child->parent = NULL;
+ }
- if (hport->config.intf[intf].devname[0] != '\0') {
- USB_LOG_INFO("Unregister HUB Class:%s\r\n", hport->config.intf[intf].devname);
- }
+ USB_LOG_INFO("Unregister HUB Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_hub_class_free(hub);
- }
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_hub_class_free(hub);
return ret;
}
#endif
diff --git a/class/msc/usbh_msc.c b/class/msc/usbh_msc.c
index 83b73229..ecda660e 100644
--- a/class/msc/usbh_msc.c
+++ b/class/msc/usbh_msc.c
@@ -293,7 +293,7 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
msc_class->hport = hport;
msc_class->intf = intf;
- hport->config.intf[intf].priv = msc_class;
+ usbh_set_intf_data(hport, intf, msc_class);
ret = usbh_msc_get_maxlun(msc_class, g_msc_buf[msc_class->sdchar - 'a']);
if (ret < 0) {
@@ -302,7 +302,7 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
g_msc_buf[msc_class->sdchar - 'a'][0] = 0;
ret = 0;
} else {
- return ret;
+ goto errout;
}
}
@@ -326,7 +326,8 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
(hport->device_desc.idProduct == config->pid)) {
USB_LOG_INFO("%s usb_modeswitch enable\r\n", config->name);
usbh_msc_modeswitch(msc_class, config->message_content);
- return 0;
+ ret = -USB_ERR_NODEV;
+ goto errout;
}
num++;
} else {
@@ -341,32 +342,32 @@ static int usbh_msc_connect(struct usbh_hubport *hport, uint8_t intf)
usbh_msc_run(msc_class);
return ret;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_msc_class_free(msc_class);
+ return ret;
}
static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_msc *msc_class = (struct usbh_msc *)hport->config.intf[intf].priv;
-
- if (msc_class) {
- if (msc_class->bulkin) {
- usbh_kill_urb(&msc_class->bulkin_urb);
- }
-
- if (msc_class->bulkout) {
- usbh_kill_urb(&msc_class->bulkout_urb);
- }
+ struct usbh_msc *msc_class = (struct usbh_msc *)usbh_get_intf_data(hport, intf);
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister MSC Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_msc_stop(msc_class);
- }
+ if (msc_class->bulkin) {
+ usbh_kill_urb(&msc_class->bulkin_urb);
+ }
- usbh_msc_class_free(msc_class);
+ if (msc_class->bulkout) {
+ usbh_kill_urb(&msc_class->bulkout_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister MSC Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_msc_stop(msc_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_msc_class_free(msc_class);
return ret;
}
diff --git a/class/serial/usbh_cdc_acm.c b/class/serial/usbh_cdc_acm.c
index 48643cb3..69ea1d27 100644
--- a/class/serial/usbh_cdc_acm.c
+++ b/class/serial/usbh_cdc_acm.c
@@ -233,11 +233,10 @@ static int usbh_cdc_acm_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usbh_serial *serial = (struct usbh_serial *)hport->config.intf[intf].priv;
+ struct usbh_serial *serial = (struct usbh_serial *)usbh_get_intf_data(hport, intf);
- if (serial) {
- usbh_serial_remove(serial);
- }
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_serial_remove(serial);
return 0;
}
diff --git a/class/serial/usbh_ch34x.c b/class/serial/usbh_ch34x.c
index 317930e5..bc934c68 100644
--- a/class/serial/usbh_ch34x.c
+++ b/class/serial/usbh_ch34x.c
@@ -379,12 +379,10 @@ static int usbh_ch34x_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_ch34x_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usbh_serial *serial = (struct usbh_serial *)hport->config.intf[intf].priv;
-
- if (serial) {
- usbh_serial_remove(serial);
- }
+ struct usbh_serial *serial = (struct usbh_serial *)usbh_get_intf_data(hport, intf);
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_serial_remove(serial);
return 0;
}
diff --git a/class/serial/usbh_cp210x.c b/class/serial/usbh_cp210x.c
index e72d3cd4..175b183c 100644
--- a/class/serial/usbh_cp210x.c
+++ b/class/serial/usbh_cp210x.c
@@ -483,11 +483,10 @@ static int usbh_cp210x_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_cp210x_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usbh_serial *serial = (struct usbh_serial *)hport->config.intf[intf].priv;
+ struct usbh_serial *serial = (struct usbh_serial *)usbh_get_intf_data(hport, intf);
- if (serial) {
- usbh_serial_remove(serial);
- }
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_serial_remove(serial);
return 0;
}
diff --git a/class/serial/usbh_ftdi.c b/class/serial/usbh_ftdi.c
index 5ed9191f..a8ad52d7 100644
--- a/class/serial/usbh_ftdi.c
+++ b/class/serial/usbh_ftdi.c
@@ -376,11 +376,10 @@ static int usbh_ftdi_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_ftdi_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usbh_serial *serial = (struct usbh_serial *)hport->config.intf[intf].priv;
+ struct usbh_serial *serial = (struct usbh_serial *)usbh_get_intf_data(hport, intf);
- if (serial) {
- usbh_serial_remove(serial);
- }
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_serial_remove(serial);
return 0;
}
diff --git a/class/serial/usbh_gsm.c b/class/serial/usbh_gsm.c
index 63418736..054ddbc5 100644
--- a/class/serial/usbh_gsm.c
+++ b/class/serial/usbh_gsm.c
@@ -95,11 +95,10 @@ static int usbh_gsm_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_gsm_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usbh_serial *serial = (struct usbh_serial *)hport->config.intf[intf].priv;
+ struct usbh_serial *serial = (struct usbh_serial *)usbh_get_intf_data(hport, intf);
- if (serial) {
- usbh_serial_remove(serial);
- }
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_serial_remove(serial);
return 0;
}
diff --git a/class/serial/usbh_pl2303.c b/class/serial/usbh_pl2303.c
index e3b6a307..b4657894 100644
--- a/class/serial/usbh_pl2303.c
+++ b/class/serial/usbh_pl2303.c
@@ -689,12 +689,10 @@ static int usbh_pl2303_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_pl2303_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usbh_serial *serial = (struct usbh_serial *)hport->config.intf[intf].priv;
-
- if (serial) {
- usbh_serial_remove(serial);
- }
+ struct usbh_serial *serial = (struct usbh_serial *)usbh_get_intf_data(hport, intf);
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_serial_remove(serial);
return 0;
}
diff --git a/class/serial/usbh_serial.c b/class/serial/usbh_serial.c
index e92e6a70..40e5394f 100644
--- a/class/serial/usbh_serial.c
+++ b/class/serial/usbh_serial.c
@@ -205,7 +205,7 @@ struct usbh_serial *usbh_serial_probe(struct usbh_hubport *hport, uint8_t intf,
snprintf(hport->config.intf[intf].devname, CONFIG_USBHOST_DEV_NAMELEN, DEV_FORMAT_VENDOR, serial->minor);
}
- hport->config.intf[intf].priv = serial;
+ usbh_set_intf_data(hport, intf, serial);
USB_LOG_INFO("Register Serial Class: %s (%s)\r\n", hport->config.intf[intf].devname, driver->driver_name);
usbh_serial_run(serial);
@@ -224,11 +224,9 @@ void usbh_serial_remove(struct usbh_serial *serial)
serial->driver->detach(serial);
}
- if (serial->hport->config.intf[serial->intf].priv) {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister Serial Class: %s (%s)\r\n", serial->hport->config.intf[serial->intf].devname, serial->driver->driver_name);
- usbh_serial_stop(serial);
- }
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister Serial Class: %s (%s)\r\n", serial->hport->config.intf[serial->intf].devname, serial->driver->driver_name);
+ usbh_serial_stop(serial);
usbh_serial_free(serial);
}
@@ -689,8 +687,7 @@ static int usbh_cdc_data_connect(struct usbh_hubport *hport, uint8_t intf)
static int usbh_cdc_data_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- (void)hport;
- (void)intf;
+ usbh_set_intf_data(hport, intf, NULL);
return 0;
}
diff --git a/class/template/usbh_xxx.c b/class/template/usbh_xxx.c
index 4456b3c4..b0a995ca 100644
--- a/class/template/usbh_xxx.c
+++ b/class/template/usbh_xxx.c
@@ -34,16 +34,20 @@ static void usbh_xxx_class_free(struct usbh_xxx *xxx_class)
static int usbh_xxx_connect(struct usbh_hubport *hport, uint8_t intf)
{
- struct usb_endpoint_descriptor *ep_desc;
- int ret;
-
struct usbh_xxx *xxx_class = usbh_xxx_class_alloc();
if (xxx_class == NULL) {
USB_LOG_ERR("Fail to alloc xxx_class\r\n");
return -USB_ERR_NOMEM;
}
- return ret;
+ xxx_class->hport = hport;
+ xxx_class->intf = intf;
+ usbh_set_intf_data(hport, intf, xxx_class);
+
+ strncpy(hport->config.intf[intf].devname, DEV_FORMAT, CONFIG_USBHOST_DEV_NAMELEN);
+ USB_LOG_INFO("Register xxx Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_xxx_run(xxx_class);
+ return 0;
}
@@ -51,25 +55,21 @@ static int usbh_xxx_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_xxx *xxx_class = (struct usbh_xxx *)hport->config.intf[intf].priv;
-
- if (xxx_class) {
- if (xxx_class->xxxin) {
- usbh_kill_urb(&xxx_class->xxxin_urb);
- }
-
- if (xxx_class->xxxout) {
- usbh_kill_urb(&xxx_class->xxxout_urb);
- }
+ struct usbh_xxx *xxx_class = (struct usbh_xxx *)usbh_get_intf_data(hport, intf);
- if (hport->config.intf[intf].devname[0] != '\0') {
- USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_xxx_stop(xxx_class);
- }
+ if (xxx_class->xxxin) {
+ usbh_kill_urb(&xxx_class->xxxin_urb);
+ }
- usbh_xxx_class_free(xxx_class);
+ if (xxx_class->xxxout) {
+ usbh_kill_urb(&xxx_class->xxxout_urb);
}
+ USB_LOG_INFO("Unregister xxx Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_xxx_stop(xxx_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_xxx_class_free(xxx_class);
return ret;
}
diff --git a/class/vendor/net/usbh_asix.c b/class/vendor/net/usbh_asix.c
index d5f949ed..413486d1 100644
--- a/class/vendor/net/usbh_asix.c
+++ b/class/vendor/net/usbh_asix.c
@@ -527,7 +527,7 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
asix_class->hport = hport;
asix_class->intf = intf;
- hport->config.intf[intf].priv = asix_class;
+ usbh_set_intf_data(hport, intf, asix_class);
if ((hport->device_desc.idVendor == 0x0b95) && (hport->device_desc.idProduct == 0x772b)) {
asix_class->name = "ASIX AX88772B";
@@ -541,7 +541,7 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_asix_read_cmd(asix_class, AX_CMD_READ_EEPROM,
0x04 + i, 0, &asix_class->mac[i * 2], 2);
if (ret < 0) {
- return ret;
+ goto errout;
}
}
@@ -556,7 +556,7 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_asix_read_phy_addr(asix_class, true);
if (ret < 0) {
USB_LOG_ERR("Failed to read phy addr: %d\r\n", ret);
- return ret;
+ goto errout;
}
asix_class->phy_addr = ret;
asix_class->embd_phy = ((ret & 0x1f) == AX_EMBD_PHY_ADDR);
@@ -564,7 +564,7 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_asix_read_cmd(asix_class, AX_CMD_STATMNGSTS_REG, 0, 0, &asix_class->chipcode, 1);
if (ret < 0) {
USB_LOG_ERR("Failed to read STATMNGSTS_REG: %d\r\n", ret);
- return ret;
+ goto errout;
}
asix_class->chipcode &= AX_CHIPCODE_MASK;
@@ -582,7 +582,8 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
if (ep_desc->bEndpointAddress & 0x80) {
USBH_EP_INIT(asix_class->intin, ep_desc);
} else {
- return -USB_ERR_NOTSUPP;
+ ret = -USB_ERR_NOTSUPP;
+ goto errout;
}
} else {
if (ep_desc->bEndpointAddress & 0x80) {
@@ -620,36 +621,36 @@ static int usbh_asix_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register ASIX Class:%s\r\n", hport->config.intf[intf].devname);
usbh_asix_run(asix_class);
return ret;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(asix_class, 0, sizeof(struct usbh_asix));
+ return ret;
}
static int usbh_asix_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_asix *asix_class = (struct usbh_asix *)hport->config.intf[intf].priv;
-
- if (asix_class) {
- if (asix_class->bulkin) {
- usbh_kill_urb(&asix_class->bulkin_urb);
- }
+ struct usbh_asix *asix_class = (struct usbh_asix *)usbh_get_intf_data(hport, intf);
- if (asix_class->bulkout) {
- usbh_kill_urb(&asix_class->bulkout_urb);
- }
-
- if (asix_class->intin) {
- usbh_kill_urb(&asix_class->intin_urb);
- }
+ if (asix_class->bulkin) {
+ usbh_kill_urb(&asix_class->bulkin_urb);
+ }
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister ASIX Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_asix_stop(asix_class);
- }
+ if (asix_class->bulkout) {
+ usbh_kill_urb(&asix_class->bulkout_urb);
+ }
- memset(asix_class, 0, sizeof(struct usbh_asix));
+ if (asix_class->intin) {
+ usbh_kill_urb(&asix_class->intin_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister ASIX Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_asix_stop(asix_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(asix_class, 0, sizeof(struct usbh_asix));
return ret;
}
diff --git a/class/vendor/net/usbh_rtl8152.c b/class/vendor/net/usbh_rtl8152.c
index f6d4cef5..cec511ab 100644
--- a/class/vendor/net/usbh_rtl8152.c
+++ b/class/vendor/net/usbh_rtl8152.c
@@ -2000,13 +2000,14 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf)
rtl8152_class->hport = hport;
rtl8152_class->intf = intf;
- hport->config.intf[intf].priv = rtl8152_class;
+ usbh_set_intf_data(hport, intf, rtl8152_class);
rtl8152_class->version = usbh_rtl8152_get_version(rtl8152_class);
if (rtl8152_class->version == RTL_VER_UNKNOWN) {
USB_LOG_ERR("Unknown version 0x%04x\r\n", rtl8152_class->version);
- return -USB_ERR_NOTSUPP;
+ ret = -USB_ERR_NOTSUPP;
+ goto errout;
} else {
USB_LOG_INFO("rtl8152 version 0x%04x\r\n", rtl8152_class->version);
}
@@ -2042,7 +2043,8 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf)
rtl8152_class->saved_wolopts = __rtl_get_wol(rtl8152_class);
if (rtl_ops_init(rtl8152_class) < 0) {
- return -USB_ERR_NODEV;
+ ret = -USB_ERR_NODEV;
+ goto errout;
}
rtl8152_class->rtl_ops.init(rtl8152_class);
@@ -2050,13 +2052,14 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf)
if (rtl8152_class->rx_buf_sz > CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE) {
USB_LOG_ERR("rx_buf_sz is overflow, default is %d\r\n", (unsigned int)CONFIG_USBHOST_RTL8152_ETH_MAX_RX_SIZE);
- return -USB_ERR_NOMEM;
+ ret = -USB_ERR_NOMEM;
+ goto errout;
}
memset(mac_buffer, 0, 12);
ret = usbh_get_string_desc(rtl8152_class->hport, 3, (uint8_t *)mac_buffer, 12);
if (ret < 0) {
- return ret;
+ goto errout;
}
for (int i = 0, j = 0; i < 12; i += 2, j++) {
@@ -2086,7 +2089,8 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf)
if (ep_desc->bEndpointAddress & 0x80) {
USBH_EP_INIT(rtl8152_class->intin, ep_desc);
} else {
- return -USB_ERR_NOTSUPP;
+ ret = -USB_ERR_NOTSUPP;
+ goto errout;
}
} else {
if (ep_desc->bEndpointAddress & 0x80) {
@@ -2103,36 +2107,36 @@ static int usbh_rtl8152_connect(struct usbh_hubport *hport, uint8_t intf)
usbh_rtl8152_run(rtl8152_class);
return 0;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(rtl8152_class, 0, sizeof(struct usbh_rtl8152));
+ return ret;
}
static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_rtl8152 *rtl8152_class = (struct usbh_rtl8152 *)hport->config.intf[intf].priv;
-
- if (rtl8152_class) {
- if (rtl8152_class->bulkin) {
- usbh_kill_urb(&rtl8152_class->bulkin_urb);
- }
-
- if (rtl8152_class->bulkout) {
- usbh_kill_urb(&rtl8152_class->bulkout_urb);
- }
+ struct usbh_rtl8152 *rtl8152_class = (struct usbh_rtl8152 *)usbh_get_intf_data(hport, intf);
- if (rtl8152_class->intin) {
- usbh_kill_urb(&rtl8152_class->intin_urb);
- }
+ if (rtl8152_class->bulkin) {
+ usbh_kill_urb(&rtl8152_class->bulkin_urb);
+ }
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister rtl8152 Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_rtl8152_stop(rtl8152_class);
- }
+ if (rtl8152_class->bulkout) {
+ usbh_kill_urb(&rtl8152_class->bulkout_urb);
+ }
- memset(rtl8152_class, 0, sizeof(struct usbh_rtl8152));
+ if (rtl8152_class->intin) {
+ usbh_kill_urb(&rtl8152_class->intin_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister rtl8152 Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_rtl8152_stop(rtl8152_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(rtl8152_class, 0, sizeof(struct usbh_rtl8152));
return ret;
}
diff --git a/class/vendor/xbox/usbh_xbox.c b/class/vendor/xbox/usbh_xbox.c
index 364ca27c..f9a97882 100644
--- a/class/vendor/xbox/usbh_xbox.c
+++ b/class/vendor/xbox/usbh_xbox.c
@@ -51,7 +51,7 @@ int usbh_xbox_connect(struct usbh_hubport *hport, uint8_t intf)
xbox_class->hport = hport;
xbox_class->intf = intf;
- hport->config.intf[intf].priv = xbox_class;
+ usbh_set_intf_data(hport, intf, xbox_class);
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
@@ -74,26 +74,22 @@ int usbh_xbox_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_xbox *xbox_class = (struct usbh_xbox *)hport->config.intf[intf].priv;
+ struct usbh_xbox *xbox_class = (struct usbh_xbox *)usbh_get_intf_data(hport, intf);
- if (xbox_class) {
- if (xbox_class->intin) {
- usbh_kill_urb(&xbox_class->intin_urb);
- }
-
- if (xbox_class->intout) {
- usbh_kill_urb(&xbox_class->intout_urb);
- }
-
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister XBOX Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_xbox_stop(xbox_class);
- }
+ if (xbox_class->intin) {
+ usbh_kill_urb(&xbox_class->intin_urb);
+ }
- usbh_xbox_class_free(xbox_class);
+ if (xbox_class->intout) {
+ usbh_kill_urb(&xbox_class->intout_urb);
}
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister XBOX Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_xbox_stop(xbox_class);
+
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_xbox_class_free(xbox_class);
return ret;
}
diff --git a/class/video/usbh_video.c b/class/video/usbh_video.c
index 4b601b85..4f7d9ba2 100644
--- a/class/video/usbh_video.c
+++ b/class/video/usbh_video.c
@@ -408,12 +408,12 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
video_class->data_intf = intf + 1;
video_class->num_of_intf_altsettings = hport->config.intf[intf + 1].altsetting_num;
- hport->config.intf[intf].priv = video_class;
+ usbh_set_intf_data(hport, intf, video_class);
ret = usbh_video_close(video_class);
if (ret < 0) {
USB_LOG_ERR("Fail to close video device\r\n");
- return ret;
+ goto errout;
}
p = hport->raw_config_desc;
@@ -431,7 +431,8 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
switch (p[DESC_bDescriptorSubType]) {
case VIDEO_VC_HEADER_DESCRIPTOR_SUBTYPE:
if (p[DESC_bLength] < 5) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
video_class->bcdVDC = ((uint16_t)p[4] << 8) | (uint16_t)p[3];
break;
@@ -450,19 +451,22 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
case VIDEO_VS_INPUT_HEADER_DESCRIPTOR_SUBTYPE:
if (p[DESC_bLength] < 4 || p[DESC_bNumFormats] == 0 ||
p[DESC_bNumFormats] > CONFIG_USBHOST_VIDEO_MAX_FORMATS) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
video_class->num_of_formats = p[DESC_bNumFormats];
break;
case VIDEO_VS_FORMAT_UNCOMPRESSED_DESCRIPTOR_SUBTYPE:
if (p[DESC_bLength] < 5) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
format_index = p[DESC_bFormatIndex];
num_of_frames = p[DESC_bNumFrameDescriptors];
if (format_index == 0 || format_index > CONFIG_USBHOST_VIDEO_MAX_FORMATS ||
num_of_frames == 0 || num_of_frames > CONFIG_USBHOST_VIDEO_MAX_FRAMES) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
video_class->format[format_index - 1].num_of_frames = num_of_frames;
@@ -470,13 +474,15 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
break;
case VIDEO_VS_FORMAT_MJPEG_DESCRIPTOR_SUBTYPE:
if (p[DESC_bLength] < 5) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
format_index = p[DESC_bFormatIndex];
num_of_frames = p[DESC_bNumFrameDescriptors];
if (format_index == 0 || format_index > CONFIG_USBHOST_VIDEO_MAX_FORMATS ||
num_of_frames == 0 || num_of_frames > CONFIG_USBHOST_VIDEO_MAX_FRAMES) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
video_class->format[format_index - 1].num_of_frames = num_of_frames;
@@ -484,14 +490,16 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
break;
case VIDEO_VS_FRAME_UNCOMPRESSED_DESCRIPTOR_SUBTYPE:
if (p[DESC_bLength] < sizeof(struct video_cs_if_vs_frame_uncompressed_descriptor)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
frame_index = p[DESC_bFrameIndex];
if (format_index == 0 || format_index > CONFIG_USBHOST_VIDEO_MAX_FORMATS ||
frame_index == 0 || frame_index > CONFIG_USBHOST_VIDEO_MAX_FRAMES ||
frame_index > video_class->format[format_index - 1].num_of_frames ||
((struct video_cs_if_vs_frame_uncompressed_descriptor *)p)->dwDefaultFrameInterval == 0) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
video_class->format[format_index - 1].frame[frame_index - 1].wWidth = ((struct video_cs_if_vs_frame_uncompressed_descriptor *)p)->wWidth;
@@ -500,14 +508,16 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
break;
case VIDEO_VS_FRAME_MJPEG_DESCRIPTOR_SUBTYPE:
if (p[DESC_bLength] < sizeof(struct video_cs_if_vs_frame_mjpeg_descriptor)) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
frame_index = p[DESC_bFrameIndex];
if (format_index == 0 || format_index > CONFIG_USBHOST_VIDEO_MAX_FORMATS ||
frame_index == 0 || frame_index > CONFIG_USBHOST_VIDEO_MAX_FRAMES ||
frame_index > video_class->format[format_index - 1].num_of_frames ||
((struct video_cs_if_vs_frame_mjpeg_descriptor *)p)->dwDefaultFrameInterval == 0) {
- return -USB_ERR_INVAL;
+ ret = -USB_ERR_INVAL;
+ goto errout;
}
video_class->format[format_index - 1].frame[frame_index - 1].wWidth = ((struct video_cs_if_vs_frame_mjpeg_descriptor *)p)->wWidth;
@@ -537,24 +547,24 @@ static int usbh_video_ctrl_connect(struct usbh_hubport *hport, uint8_t intf)
usbh_video_run(video_class);
return ret;
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_video_class_free(video_class);
+ return ret;
}
static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_video *video_class = (struct usbh_video *)hport->config.intf[intf].priv;
+ struct usbh_video *video_class = (struct usbh_video *)usbh_get_intf_data(hport, intf);
- if (video_class) {
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister Video Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_video_stop(video_class);
- }
-
- usbh_video_class_free(video_class);
- }
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister Video Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_video_stop(video_class);
+ usbh_set_intf_data(hport, intf, NULL);
+ usbh_video_class_free(video_class);
return ret;
}
@@ -567,8 +577,7 @@ static int usbh_video_streaming_connect(struct usbh_hubport *hport, uint8_t intf
static int usbh_video_streaming_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
- (void)hport;
- (void)intf;
+ usbh_set_intf_data(hport, intf, NULL);
return 0;
}
diff --git a/class/wireless/usbh_bluetooth.c b/class/wireless/usbh_bluetooth.c
index 3aa955ce..0d723c28 100644
--- a/class/wireless/usbh_bluetooth.c
+++ b/class/wireless/usbh_bluetooth.c
@@ -48,7 +48,7 @@ static int usbh_bluetooth_connect(struct usbh_hubport *hport, uint8_t intf)
#ifndef CONFIG_USBHOST_BLUETOOTH_HCI_H4
bluetooth_class->num_of_intf_altsettings = hport->config.intf[intf + 1].altsetting_num;
#endif
- hport->config.intf[intf].priv = bluetooth_class;
+ usbh_set_intf_data(hport, intf, bluetooth_class);
for (uint8_t i = 0; i < hport->config.intf[intf].altsetting[0].intf_desc.bNumEndpoints; i++) {
ep_desc = &hport->config.intf[intf].altsetting[0].ep[i].ep_desc;
@@ -57,7 +57,8 @@ static int usbh_bluetooth_connect(struct usbh_hubport *hport, uint8_t intf)
if (ep_desc->bEndpointAddress & 0x80) {
USBH_EP_INIT(bluetooth_class->intin, ep_desc);
} else {
- return -USB_ERR_NOTSUPP;
+ ret = -USB_ERR_NOTSUPP;
+ goto errout;
}
} else {
#endif
@@ -92,7 +93,7 @@ static int usbh_bluetooth_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_set_interface(hport, intf, 0);
if (ret < 0) {
- return ret;
+ goto errout;
}
USB_LOG_INFO("Bluetooth select altsetting 0\r\n");
#endif
@@ -100,44 +101,53 @@ static int usbh_bluetooth_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_INFO("Register Bluetooth Class:%s\r\n", hport->config.intf[intf].devname);
usbh_bluetooth_run(bluetooth_class);
return ret;
+#ifndef CONFIG_USBHOST_BLUETOOTH_HCI_H4
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(bluetooth_class, 0, sizeof(struct usbh_bluetooth));
+ return ret;
+#endif
}
static int usbh_bluetooth_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_bluetooth *bluetooth_class = (struct usbh_bluetooth *)hport->config.intf[intf].priv;
+#ifndef CONFIG_USBHOST_BLUETOOTH_HCI_H4
+ if (intf != 0) {
+ usbh_set_intf_data(hport, intf, NULL);
+ return 0;
+ }
+#endif
- if (bluetooth_class) {
- if (bluetooth_class->bulkin) {
- usbh_kill_urb(&bluetooth_class->bulkin_urb);
- }
+ struct usbh_bluetooth *bluetooth_class = (struct usbh_bluetooth *)usbh_get_intf_data(hport, intf);
- if (bluetooth_class->bulkout) {
- usbh_kill_urb(&bluetooth_class->bulkout_urb);
- }
+ if (bluetooth_class->bulkin) {
+ usbh_kill_urb(&bluetooth_class->bulkin_urb);
+ }
+
+ if (bluetooth_class->bulkout) {
+ usbh_kill_urb(&bluetooth_class->bulkout_urb);
+ }
#ifndef CONFIG_USBHOST_BLUETOOTH_HCI_H4
- if (bluetooth_class->intin) {
- usbh_kill_urb(&bluetooth_class->intin_urb);
- }
+ if (bluetooth_class->intin) {
+ usbh_kill_urb(&bluetooth_class->intin_urb);
+ }
- // if (bluetooth_class->isoin) {
- // usbh_kill_urb(&bluetooth_class->isoin_urb);
- // }
+ // if (bluetooth_class->isoin) {
+ // usbh_kill_urb(&bluetooth_class->isoin_urb);
+ // }
- // if (bluetooth_class->isoin) {
- // usbh_kill_urb(&bluetooth_class->isoinin_urb);
- // }
+ // if (bluetooth_class->isoin) {
+ // usbh_kill_urb(&bluetooth_class->isoinin_urb);
+ // }
#endif
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister Bluetooth Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_bluetooth_stop(bluetooth_class);
- }
-
- memset(bluetooth_class, 0, sizeof(struct usbh_bluetooth));
- }
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister Bluetooth Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_bluetooth_stop(bluetooth_class);
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(bluetooth_class, 0, sizeof(struct usbh_bluetooth));
return ret;
}
diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c
index 41c6dd83..90632fd5 100644
--- a/class/wireless/usbh_rndis.c
+++ b/class/wireless/usbh_rndis.c
@@ -351,8 +351,8 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
rndis_class->ctrl_intf = intf;
rndis_class->data_intf = intf + 1;
- hport->config.intf[intf].priv = rndis_class;
- hport->config.intf[intf + 1].priv = NULL;
+ usbh_set_intf_data(hport, intf, rndis_class);
+ usbh_set_intf_data(hport, intf + 1, NULL);
// ep_desc = &hport->config.intf[intf].altsetting[0].ep[0].ep_desc;
// USBH_EP_INIT(rndis_class->intin, ep_desc);
@@ -369,12 +369,12 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
ret = usbh_rndis_init_msg_transfer(rndis_class);
if (ret < 0) {
- return ret;
+ goto errout;
}
ret = usbh_rndis_query_msg_transfer(rndis_class, OID_GEN_SUPPORTED_LIST, 0, tmp_buffer, sizeof(tmp_buffer), &data_len);
if (ret < 0) {
- return ret;
+ goto errout;
}
oid_num = (data_len / 4);
USB_LOG_INFO("rndis query OID_GEN_SUPPORTED_LIST success,oid num: %u\r\n", (unsigned int)oid_num);
@@ -445,13 +445,13 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
uint32_t packet_filter = 0x0f;
ret = usbh_rndis_set_msg_transfer(rndis_class, OID_GEN_CURRENT_PACKET_FILTER, (uint8_t *)&packet_filter, 4);
if (ret < 0) {
- return ret;
+ goto errout;
}
uint8_t multicast_list[6] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x01 };
ret = usbh_rndis_set_msg_transfer(rndis_class, OID_802_3_MULTICAST_LIST, multicast_list, 6);
if (ret < 0) {
- return ret;
+ goto errout;
}
USB_LOG_INFO("rndis MAC address %02x:%02x:%02x:%02x:%02x:%02x\r\n",
@@ -469,6 +469,9 @@ static int usbh_rndis_connect(struct usbh_hubport *hport, uint8_t intf)
return ret;
query_errorout:
USB_LOG_ERR("rndis query iod:%08x error\r\n", (unsigned int)oid);
+errout:
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(rndis_class, 0, sizeof(struct usbh_rndis));
return ret;
}
@@ -476,30 +479,26 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
{
int ret = 0;
- struct usbh_rndis *rndis_class = (struct usbh_rndis *)hport->config.intf[intf].priv;
-
- if (rndis_class) {
- if (rndis_class->bulkin) {
- usbh_kill_urb(&rndis_class->bulkin_urb);
- }
+ struct usbh_rndis *rndis_class = (struct usbh_rndis *)usbh_get_intf_data(hport, intf);
- if (rndis_class->bulkout) {
- usbh_kill_urb(&rndis_class->bulkout_urb);
- }
+ if (rndis_class->bulkin) {
+ usbh_kill_urb(&rndis_class->bulkin_urb);
+ }
- // if (rndis_class->intin) {
- // usbh_kill_urb(&rndis_class->intin_urb);
- // }
+ if (rndis_class->bulkout) {
+ usbh_kill_urb(&rndis_class->bulkout_urb);
+ }
- if (hport->config.intf[intf].devname[0] != '\0') {
- usb_osal_thread_schedule_other();
- USB_LOG_INFO("Unregister RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
- usbh_rndis_stop(rndis_class);
- }
+ // if (rndis_class->intin) {
+ // usbh_kill_urb(&rndis_class->intin_urb);
+ // }
- memset(rndis_class, 0, sizeof(struct usbh_rndis));
- }
+ usb_osal_thread_schedule_other();
+ USB_LOG_INFO("Unregister RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
+ usbh_rndis_stop(rndis_class);
+ usbh_set_intf_data(hport, intf, NULL);
+ memset(rndis_class, 0, sizeof(struct usbh_rndis));
return ret;
}