171-usb-dwc2-Fix-inefficient-copy-of-unaligned-buffers.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. From 81da1738eee68f1961e03bdeb2d60cf0eb4dd713 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Antti=20Sepp=C3=A4l=C3=A4?= <a.seppala@gmail.com>
  3. Date: Thu, 5 Jul 2018 12:06:18 +0300
  4. Subject: [PATCH 2/2] usb: dwc2: Fix inefficient copy of unaligned buffers
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Make sure only to copy any actual data rather than the whole buffer,
  9. when releasing the temporary buffer used for unaligned non-isochronous
  10. transfers.
  11. Taken directly from commit 0efd937e27d5e ("USB: ehci-tegra: fix inefficient
  12. copy of unaligned buffers")
  13. Tested with Lantiq xRX200 (MIPS) and RPi Model B Rev 2 (ARM)
  14. Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
  15. ---
  16. drivers/usb/dwc2/hcd.c | 12 +++++++++---
  17. 1 file changed, 9 insertions(+), 3 deletions(-)
  18. --- a/drivers/usb/dwc2/hcd.c
  19. +++ b/drivers/usb/dwc2/hcd.c
  20. @@ -2669,6 +2669,7 @@ static int dwc2_alloc_split_dma_aligned_
  21. static void dwc2_free_dma_aligned_buffer(struct urb *urb)
  22. {
  23. void *stored_xfer_buffer;
  24. + size_t length;
  25. if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
  26. return;
  27. @@ -2677,9 +2678,14 @@ static void dwc2_free_dma_aligned_buffer
  28. memcpy(&stored_xfer_buffer, urb->transfer_buffer +
  29. urb->transfer_buffer_length, sizeof(urb->transfer_buffer));
  30. - if (usb_urb_dir_in(urb))
  31. - memcpy(stored_xfer_buffer, urb->transfer_buffer,
  32. - urb->transfer_buffer_length);
  33. + if (usb_urb_dir_in(urb)) {
  34. + if (usb_pipeisoc(urb->pipe))
  35. + length = urb->transfer_buffer_length;
  36. + else
  37. + length = urb->actual_length;
  38. +
  39. + memcpy(stored_xfer_buffer, urb->transfer_buffer, length);
  40. + }
  41. kfree(urb->transfer_buffer);
  42. urb->transfer_buffer = stored_xfer_buffer;