]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/host/dwc2.c
usb: dwc2: fix aligned buffer usage
[karo-tx-uboot.git] / drivers / usb / host / dwc2.c
index e8a7e713c87f46c09ce1e0cea9ae465d3ec5ba18..05d21b7948f564f2a262b83d5000997b377c1c89 100644 (file)
@@ -724,11 +724,9 @@ int wait_for_chhltd(uint32_t *sub, int *toggle)
        hctsiz = readl(&hc_regs->hctsiz);
        *sub = (hctsiz & DWC2_HCTSIZ_XFERSIZE_MASK) >>
                DWC2_HCTSIZ_XFERSIZE_OFFSET;
-       if (toggle)
-               *toggle = (hctsiz & DWC2_HCTSIZ_PID_MASK) >>
-                       DWC2_HCTSIZ_PID_OFFSET;
+       *toggle = (hctsiz & DWC2_HCTSIZ_PID_MASK) >> DWC2_HCTSIZ_PID_OFFSET;
 
-       debug("%s: sub=%u toggle=%d\n", __func__, *sub, toggle ? *toggle : -1);
+       debug("%s: sub=%u toggle=%d\n", __func__, *sub, *toggle);
 
        return 0;
 }
@@ -797,7 +795,9 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
                       (*pid << DWC2_HCTSIZ_PID_OFFSET),
                       &hc_regs->hctsiz);
 
-               memcpy(aligned_buffer, (char *)buffer + done, len - done);
+               if (!in)
+                       memcpy(aligned_buffer, (char *)buffer + done, len);
+
                writel((uint32_t)aligned_buffer, &hc_regs->hcdma);
 
                /* Set host channel enable after all other setup is complete. */
@@ -812,16 +812,16 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
                        break;
                }
 
-               done += xfer_len;
                if (in) {
-                       done -= sub;
+                       xfer_len -= sub;
+                       memcpy(buffer + done, aligned_buffer, xfer_len);
                        if (sub)
                                stop_transfer = 1;
                }
-       } while ((done < len) && !stop_transfer);
 
-       if (done && in)
-               memcpy(buffer, aligned_buffer, done);
+               done += xfer_len;
+
+       } while ((done < len) && !stop_transfer);
 
        writel(0, &hc_regs->hcintmsk);
        writel(0xFFFFFFFF, &hc_regs->hcint);