aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc2/hcd_queue.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/dwc2/hcd_queue.c')
-rw-r--r--drivers/usb/dwc2/hcd_queue.c49
1 files changed, 12 insertions, 37 deletions
diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
index 9b5c36256627..3ad63d392e13 100644
--- a/drivers/usb/dwc2/hcd_queue.c
+++ b/drivers/usb/dwc2/hcd_queue.c
@@ -191,7 +191,7 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
191 * 191 *
192 * Return: Pointer to the newly allocated QH, or NULL on error 192 * Return: Pointer to the newly allocated QH, or NULL on error
193 */ 193 */
194static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg, 194struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg,
195 struct dwc2_hcd_urb *urb, 195 struct dwc2_hcd_urb *urb,
196 gfp_t mem_flags) 196 gfp_t mem_flags)
197{ 197{
@@ -767,57 +767,32 @@ void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct dwc2_hcd_urb *urb)
767 * 767 *
768 * @hsotg: The DWC HCD structure 768 * @hsotg: The DWC HCD structure
769 * @qtd: The QTD to add 769 * @qtd: The QTD to add
770 * @qh: Out parameter to return queue head 770 * @qh: Queue head to add qtd to
771 * @atomic_alloc: Flag to do atomic alloc if needed
772 * 771 *
773 * Return: 0 if successful, negative error code otherwise 772 * Return: 0 if successful, negative error code otherwise
774 * 773 *
775 * Finds the correct QH to place the QTD into. If it does not find a QH, it 774 * If the QH to which the QTD is added is not currently scheduled, it is placed
776 * will create a new QH. If the QH to which the QTD is added is not currently 775 * into the proper schedule based on its EP type.
777 * scheduled, it is placed into the proper schedule based on its EP type.
778 */ 776 */
779int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, 777int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
780 struct dwc2_qh **qh, gfp_t mem_flags) 778 struct dwc2_qh *qh)
781{ 779{
782 struct dwc2_hcd_urb *urb = qtd->urb;
783 int allocated = 0;
784 int retval; 780 int retval;
785 781
786 /* 782 if (unlikely(!qh)) {
787 * Get the QH which holds the QTD-list to insert to. Create QH if it 783 dev_err(hsotg->dev, "%s: Invalid QH\n", __func__);
788 * doesn't exist. 784 retval = -EINVAL;
789 */ 785 goto fail;
790 if (*qh == NULL) {
791 *qh = dwc2_hcd_qh_create(hsotg, urb, mem_flags);
792 if (*qh == NULL)
793 return -ENOMEM;
794 allocated = 1;
795 } 786 }
796 787
797 retval = dwc2_hcd_qh_add(hsotg, *qh); 788 retval = dwc2_hcd_qh_add(hsotg, qh);
798 if (retval) 789 if (retval)
799 goto fail; 790 goto fail;
800 791
801 qtd->qh = *qh; 792 qtd->qh = qh;
802 list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list); 793 list_add_tail(&qtd->qtd_list_entry, &qh->qtd_list);
803 794
804 return 0; 795 return 0;
805
806fail: 796fail:
807 if (allocated) {
808 struct dwc2_qtd *qtd2, *qtd2_tmp;
809 struct dwc2_qh *qh_tmp = *qh;
810
811 *qh = NULL;
812 dwc2_hcd_qh_unlink(hsotg, qh_tmp);
813
814 /* Free each QTD in the QH's QTD list */
815 list_for_each_entry_safe(qtd2, qtd2_tmp, &qh_tmp->qtd_list,
816 qtd_list_entry)
817 dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh_tmp);
818
819 dwc2_hcd_qh_free(hsotg, qh_tmp);
820 }
821
822 return retval; 797 return retval;
823} 798}