summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2023-11-22 21:41:14 +0800
committersakumisu <[email protected]>2023-11-22 21:42:56 +0800
commit5b32482c3efb2cb612a738220e3a3ec63bbc637a (patch)
tree8e4337535bf9338ed72b57559492076193c1ed52
parent18eed18413631a856388fbc3feee70a90e6b7fbc (diff)
free pipe after sem giving
-rw-r--r--port/dwc2/usb_hc_dwc2.c9
-rw-r--r--port/ehci/usb_hc_ehci.c19
-rw-r--r--port/musb/usb_hc_musb.c11
3 files changed, 25 insertions, 14 deletions
diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c
index d276fd19..8848deed 100644
--- a/port/dwc2/usb_hc_dwc2.c
+++ b/port/dwc2/usb_hc_dwc2.c
@@ -749,9 +749,12 @@ int usbh_submit_urb(struct usbh_urb *urb)
}
urb->timeout = 0;
ret = urb->errorcode;
+ /* we can free chan when waitsem is done */
+ dwc2_chan_free(chan);
}
return ret;
errout_timeout:
+ urb->timeout = 0;
usbh_kill_urb(urb);
return ret;
}
@@ -781,6 +784,8 @@ int usbh_kill_urb(struct usbh_urb *urb)
urb->timeout = 0;
urb->errorcode = -ESHUTDOWN;
usb_osal_sem_give(chan->waitsem);
+ } else {
+ dwc2_chan_free(chan);
}
usb_osal_leave_critical_section(flags);
@@ -796,11 +801,11 @@ static inline void dwc2_urb_waitup(struct usbh_urb *urb)
chan->urb = NULL;
urb->hcpriv = NULL;
- dwc2_chan_free(chan);
-
if (urb->timeout) {
urb->timeout = 0;
usb_osal_sem_give(chan->waitsem);
+ } else {
+ dwc2_chan_free(chan);
}
if (urb->complete) {
diff --git a/port/ehci/usb_hc_ehci.c b/port/ehci/usb_hc_ehci.c
index 8f3e2687..4d9b588b 100644
--- a/port/ehci/usb_hc_ehci.c
+++ b/port/ehci/usb_hc_ehci.c
@@ -632,11 +632,12 @@ static void ehci_urb_waitup(struct usbh_urb *urb)
urb->hcpriv = NULL;
qh->remove_in_iaad = 0;
- ehci_qh_free(qh);
if (urb->timeout) {
urb->timeout = 0;
usb_osal_sem_give(qh->waitsem);
+ } else {
+ ehci_qh_free(qh);
}
if (urb->complete) {
@@ -732,8 +733,6 @@ static void ehci_kill_qh(struct ehci_qh_hw *qhead, struct ehci_qh_hw *qh)
qh->first_qtd = qtd->hw.next_qtd;
qtd = EHCI_ADDR2QTD(qh->first_qtd);
}
-
- ehci_qh_free(qh);
}
static int usbh_reset_port(const uint8_t port)
@@ -964,7 +963,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_RESUME;
usb_osal_msleep(20);
EHCI_HCOR->portsc[port - 1] &= ~EHCI_PORTSC_RESUME;
- while(EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_RESUME){}
+ while (EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_RESUME) {}
temp = EHCI_HCOR->usbcmd;
temp |= EHCI_USBCMD_ASEN;
@@ -972,7 +971,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
temp |= EHCI_USBCMD_RUN;
EHCI_HCOR->usbcmd = temp;
- while((EHCI_HCOR->usbcmd & EHCI_USBCMD_RUN) == 0){}
+ while ((EHCI_HCOR->usbcmd & EHCI_USBCMD_RUN) == 0) {}
case HUB_PORT_FEATURE_C_SUSPEND:
break;
@@ -1009,10 +1008,10 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
temp &= ~EHCI_USBCMD_RUN;
EHCI_HCOR->usbcmd = temp;
- while(EHCI_HCOR->usbcmd & EHCI_USBCMD_RUN){}
+ while (EHCI_HCOR->usbcmd & EHCI_USBCMD_RUN) {}
EHCI_HCOR->portsc[port - 1] |= EHCI_PORTSC_SUSPEND;
- while((EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_SUSPEND) == 0){}
+ while ((EHCI_HCOR->portsc[port - 1] & EHCI_PORTSC_SUSPEND) == 0) {}
break;
case HUB_PORT_FEATURE_POWER:
#ifdef CONFIG_USB_EHCI_PORT_POWER
@@ -1142,10 +1141,12 @@ int usbh_submit_urb(struct usbh_urb *urb)
}
urb->timeout = 0;
ret = urb->errorcode;
+ /* we should free qh when waitsem is done */
+ ehci_qh_free(qh);
}
return ret;
errout_timeout:
- /* Timeout will run here */
+ urb->timeout = 0;
usbh_kill_urb(urb);
return ret;
}
@@ -1199,6 +1200,8 @@ int usbh_kill_urb(struct usbh_urb *urb)
urb->timeout = 0;
urb->errorcode = -ESHUTDOWN;
usb_osal_sem_give(qh->waitsem);
+ } else {
+ ehci_qh_free(qh);
}
usb_osal_leave_critical_section(flags);
diff --git a/port/musb/usb_hc_musb.c b/port/musb/usb_hc_musb.c
index f19f3264..c959f651 100644
--- a/port/musb/usb_hc_musb.c
+++ b/port/musb/usb_hc_musb.c
@@ -650,9 +650,12 @@ int usbh_submit_urb(struct usbh_urb *urb)
}
urb->timeout = 0;
ret = urb->errorcode;
+ /* we can free pipe when waitsem is done */
+ musb_pipe_free(pipe);
}
return ret;
errout_timeout:
+ urb->timeout = 0;
usbh_kill_urb(urb);
return ret;
}
@@ -672,12 +675,12 @@ int usbh_kill_urb(struct usbh_urb *urb)
urb->hcpriv = NULL;
pipe->urb = NULL;
- musb_pipe_free(pipe);
-
if (urb->timeout) {
urb->timeout = 0;
urb->errorcode = -ESHUTDOWN;
usb_osal_sem_give(pipe->waitsem);
+ } else {
+ musb_pipe_free(pipe);
}
usb_osal_leave_critical_section(flags);
@@ -692,11 +695,11 @@ static void musb_urb_waitup(struct usbh_urb *urb)
pipe->urb = NULL;
urb->hcpriv = NULL;
- musb_pipe_free(pipe);
-
if (urb->timeout) {
urb->timeout = 0;
usb_osal_sem_give(pipe->waitsem);
+ } else {
+ musb_pipe_free(pipe);
}
if (urb->complete) {