Skip to content

Commit 95009db

Browse files
committed
Merge pull request #223 from P33M/rpi-3.6.y
dwc_otg: memory allocation/error handling bugfixes
2 parents 871eef1 + 8c3d773 commit 95009db

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

drivers/usb/host/dwc_otg/dwc_otg_hcd.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
462462
{
463463
dwc_irqflags_t flags;
464464
int retval = 0;
465+
uint8_t needs_scheduling = 0;
466+
dwc_otg_transaction_type_e tr_type;
465467
dwc_otg_qtd_t *qtd;
466468
gintmsk_data_t intr_mask = {.d32 = 0 };
467469

@@ -493,30 +495,29 @@ int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
493495
return -DWC_E_NO_MEMORY;
494496
}
495497
#endif
496-
retval =
497-
dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
498+
intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
499+
if(!intr_mask.b.sofintr) needs_scheduling = 1;
500+
if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
501+
/* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
502+
needs_scheduling = 0;
503+
504+
retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
498505
// creates a new queue in ep_handle if it doesn't exist already
499506
if (retval < 0) {
500507
DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
501508
"Error status %d\n", retval);
502509
dwc_otg_hcd_qtd_free(qtd);
510+
return retval;
503511
}
504-
intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
505-
if (!intr_mask.b.sofintr && retval == 0) {
506-
dwc_otg_transaction_type_e tr_type;
507-
if ((qtd->qh->ep_type == UE_BULK)
508-
&& !(qtd->urb->flags & URB_GIVEBACK_ASAP)) {
509-
/* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
510-
return 0;
511-
}
512+
513+
if(needs_scheduling) {
512514
DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
513515
tr_type = dwc_otg_hcd_select_transactions(hcd);
514516
if (tr_type != DWC_OTG_TRANSACTION_NONE) {
515517
dwc_otg_hcd_queue_transactions(hcd, tr_type);
516518
}
517519
DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
518520
}
519-
520521
return retval;
521522
}
522523

@@ -3135,17 +3136,13 @@ dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
31353136
else
31363137
dwc_otg_urb = DWC_ALLOC(size);
31373138

3138-
if (NULL != dwc_otg_urb)
3139-
dwc_otg_urb->packet_count = iso_desc_count;
3139+
if (dwc_otg_urb)
3140+
dwc_otg_urb->packet_count = iso_desc_count;
31403141
else {
3141-
dwc_otg_urb->packet_count = 0;
3142-
if (size != 0) {
3143-
DWC_ERROR("**** DWC OTG HCD URB alloc - "
3144-
"%salloc of %db failed\n",
3145-
atomic_alloc?"atomic ":"", size);
3146-
}
3147-
}
3148-
3142+
DWC_ERROR("**** DWC OTG HCD URB alloc - "
3143+
"%salloc of %db failed\n",
3144+
atomic_alloc?"atomic ":"", size);
3145+
}
31493146
return dwc_otg_urb;
31503147
}
31513148

drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
937937
if (*qh == NULL) {
938938
*qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
939939
if (*qh == NULL) {
940-
retval = -1;
940+
retval = -DWC_E_NO_MEMORY;
941941
goto done;
942942
}
943943
}

0 commit comments

Comments
 (0)