Commit b2d6cb55 authored by Paul Zimmerman's avatar Paul Zimmerman Committed by Greg Kroah-Hartman

staging: dwc2: fix dwc2_hcd_qtd_add()

The logic in dwc2_hcd_qtd_add() was a bit messy, and one of the
error exit paths was broken. Fix it up.
Signed-off-by: default avatarPaul Zimmerman <paulz@synopsys.com>
Tested-by: default avatarStephen Warren <swarren@wwwdotorg.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 399fdf9e
...@@ -197,6 +197,9 @@ static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg, ...@@ -197,6 +197,9 @@ static struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg,
{ {
struct dwc2_qh *qh; struct dwc2_qh *qh;
if (!urb->priv)
return NULL;
/* Allocate memory */ /* Allocate memory */
qh = kzalloc(sizeof(*qh), mem_flags); qh = kzalloc(sizeof(*qh), mem_flags);
if (!qh) if (!qh)
...@@ -638,7 +641,7 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, ...@@ -638,7 +641,7 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
struct dwc2_hcd_urb *urb = qtd->urb; struct dwc2_hcd_urb *urb = qtd->urb;
unsigned long flags; unsigned long flags;
int allocated = 0; int allocated = 0;
int retval = 0; int retval;
/* /*
* Get the QH which holds the QTD-list to insert to. Create QH if it * Get the QH which holds the QTD-list to insert to. Create QH if it
...@@ -652,8 +655,19 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, ...@@ -652,8 +655,19 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
} }
spin_lock_irqsave(&hsotg->lock, flags); spin_lock_irqsave(&hsotg->lock, flags);
retval = dwc2_hcd_qh_add(hsotg, *qh); retval = dwc2_hcd_qh_add(hsotg, *qh);
if (retval && allocated) { if (retval)
goto fail;
qtd->qh = *qh;
list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list);
spin_unlock_irqrestore(&hsotg->lock, flags);
return 0;
fail:
if (allocated) {
struct dwc2_qtd *qtd2, *qtd2_tmp; struct dwc2_qtd *qtd2, *qtd2_tmp;
struct dwc2_qh *qh_tmp = *qh; struct dwc2_qh *qh_tmp = *qh;
...@@ -668,8 +682,6 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd, ...@@ -668,8 +682,6 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,
spin_unlock_irqrestore(&hsotg->lock, flags); spin_unlock_irqrestore(&hsotg->lock, flags);
dwc2_hcd_qh_free(hsotg, qh_tmp); dwc2_hcd_qh_free(hsotg, qh_tmp);
} else { } else {
qtd->qh = *qh;
list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list);
spin_unlock_irqrestore(&hsotg->lock, flags); spin_unlock_irqrestore(&hsotg->lock, flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment