summaryrefslogtreecommitdiff
path: root/core
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 /core
parent738dedc6ec1968190ef17805fc4e37edbaec4ff3 (diff)
update(class): free class immediately in xxx_connect when return error
Signed-off-by: sakumisu <[email protected]>
Diffstat (limited to 'core')
-rw-r--r--core/usbh_core.c16
-rw-r--r--core/usbh_core.h3
2 files changed, 12 insertions, 7 deletions
diff --git a/core/usbh_core.c b/core/usbh_core.c
index 6c29ca52..7fc74ce0 100644
--- a/core/usbh_core.c
+++ b/core/usbh_core.c
@@ -621,6 +621,8 @@ int usbh_enumerate(struct usbh_hubport *hport)
ret = CLASS_CONNECT(hport, i);
if (ret >= 0) {
hport->bus->event_handler(hport->bus->busid, hport->parent->index, hport->port, i, USBH_EVENT_INTERFACE_START);
+ } else {
+ hport->config.intf[i].class_driver = NULL;
}
}
@@ -639,10 +641,10 @@ void usbh_hubport_release(struct usbh_hubport *hport)
usbh_kill_urb(&hport->ep0_urb);
usbh_free_devaddr(hport);
for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) {
- if (hport->config.intf[i].class_driver && hport->config.intf[i].class_driver->disconnect) {
+ if (usbh_get_intf_data(hport, i) && hport->config.intf[i].class_driver && hport->config.intf[i].class_driver->disconnect) {
CLASS_DISCONNECT(hport, i);
+ hport->bus->event_handler(hport->bus->busid, hport->parent->index, hport->port, i, USBH_EVENT_INTERFACE_STOP);
}
- hport->bus->event_handler(hport->bus->busid, hport->parent->index, hport->port, i, USBH_EVENT_INTERFACE_STOP);
}
hport->config.config_desc.bNumInterfaces = 0;
usb_osal_mutex_take(hport->mutex);
@@ -828,11 +830,11 @@ static void *usbh_list_all_interface_name(struct usbh_hub *hub, const char *devn
if (hport->connected) {
for (uint8_t itf = 0; itf < hport->config.config_desc.bNumInterfaces; itf++) {
if (hport->config.intf[itf].class_driver && hport->config.intf[itf].class_driver->driver_name) {
- if ((strncmp(hport->config.intf[itf].devname, devname, CONFIG_USBHOST_DEV_NAMELEN) == 0) && hport->config.intf[itf].priv)
- return hport->config.intf[itf].priv;
+ if ((strncmp(hport->config.intf[itf].devname, devname, CONFIG_USBHOST_DEV_NAMELEN) == 0) && usbh_get_intf_data(hport, itf))
+ return usbh_get_intf_data(hport, itf);
if (strcmp(hport->config.intf[itf].class_driver->driver_name, "hub") == 0) {
- hub_next = hport->config.intf[itf].priv;
+ hub_next = usbh_get_intf_data(hport, itf);
if (hub_next && hub_next->connected) {
priv = usbh_list_all_interface_name(hub_next, devname);
@@ -869,7 +871,7 @@ static struct usbh_hubport *usbh_list_all_hubport(struct usbh_hub *hub, uint8_t
for (uint8_t itf = 0; itf < hport->config.config_desc.bNumInterfaces; itf++) {
if (hport->config.intf[itf].class_driver && hport->config.intf[itf].class_driver->driver_name) {
if (strcmp(hport->config.intf[itf].class_driver->driver_name, "hub") == 0) {
- hub_next = hport->config.intf[itf].priv;
+ hub_next = usbh_get_intf_data(hport, itf);
if (hub_next && hub_next->connected) {
struct usbh_hubport *hport_next = usbh_list_all_hubport(hub_next, hub_index, hub_port);
@@ -1108,7 +1110,7 @@ static void usbh_list_device(struct usbh_hub *hub, bool astree, bool verbose, in
}
if (!strcmp(hport->config.intf[intf].class_driver->driver_name, "hub")) {
- hub_next = hport->config.intf[intf].priv;
+ hub_next = usbh_get_intf_data(hport, intf);
if (hub_next && hub_next->connected) {
usbh_list_device(hub_next, astree, verbose, dev_addr, vid, pid);
diff --git a/core/usbh_core.h b/core/usbh_core.h
index c6c891f6..5b22390c 100644
--- a/core/usbh_core.h
+++ b/core/usbh_core.h
@@ -67,6 +67,9 @@ enum usbh_event_type {
#define USB_CLASS_MATCH_INTF_NUM 0x0020
#define USB_CLASS_MATCH_VID_PID (USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT)
+#define usbh_set_intf_data(hport, intf_index, data) ((hport)->config.intf[(intf_index)].priv = (data))
+#define usbh_get_intf_data(hport, intf_index) ((hport)->config.intf[(intf_index)].priv)
+
#define CLASS_CONNECT(hport, i) ((hport)->config.intf[i].class_driver->connect(hport, i))
#define CLASS_DISCONNECT(hport, i) ((hport)->config.intf[i].class_driver->disconnect(hport, i))