diff options
| author | sakumisu <[email protected]> | 2026-04-21 21:41:27 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2026-04-21 21:41:27 +0800 |
| commit | 9ce1b1cee3ad712bbc3d2019f0f49d69987ce2d7 (patch) | |
| tree | 6af44013c746de83ecc1c306537c16217187743f | |
| parent | febe71b30c6786041dcf8b38d68874d76adb8749 (diff) | |
fix(security): remove hport mutex safely
Signed-off-by: sakumisu <[email protected]>
| -rw-r--r-- | class/hub/usbh_hub.c | 1 | ||||
| -rw-r--r-- | core/usbh_core.c | 9 |
2 files changed, 7 insertions, 3 deletions
diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index bce8fd82..f3cdbbb7 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -642,6 +642,7 @@ static void usbh_hub_events(struct usbh_hub *hub) child->speed = speed; child->bus = hub->bus; child->mutex = usb_osal_mutex_create(); + USB_ASSERT(child->mutex != NULL); USB_LOG_INFO("New %s device on Bus %u, Hub %u, Port %u connected\r\n", speed_table[speed], hub->bus->busid, hub->index, port + 1); diff --git a/core/usbh_core.c b/core/usbh_core.c index 34f2ab05..cce9a46e 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -603,9 +603,8 @@ void usbh_hubport_release(struct usbh_hubport *hport) hport->bus->event_handler(hport->bus->busid, hport->parent->index, hport->port, i, USBH_EVENT_INTERFACE_STOP); } hport->config.config_desc.bNumInterfaces = 0; - if (hport->mutex) { - usb_osal_mutex_delete(hport->mutex); - } + usb_osal_mutex_take(hport->mutex); + usb_osal_mutex_delete(hport->mutex); USB_LOG_INFO("Device on Bus %u, Hub %u, Port %u disconnected\r\n", hport->bus->busid, hport->parent->index, hport->port); hport->bus->event_handler(hport->bus->busid, hport->parent->index, hport->port, USB_INTERFACE_ANY, USBH_EVENT_DEVICE_DISCONNECTED); } @@ -683,6 +682,10 @@ int usbh_control_transfer(struct usbh_hubport *hport, struct usb_setup_packet *s return -USB_ERR_INVAL; } + if (!hport->connected) { + return -USB_ERR_NODEV; + } + urb = &hport->ep0_urb; usb_osal_mutex_take(hport->mutex); |
