* [2/2] usb: dwc2: Fix inefficient copy of unaligned buffers
@ 2018-07-05 14:31 Antti Seppälä
0 siblings, 0 replies; 2+ messages in thread
From: Antti Seppälä @ 2018-07-05 14:31 UTC (permalink / raw)
To: Minas Harutyunyan, John Youn, Felipe Balbi
Cc: Grigor Tovmasyan, Vardan Mikayelyan, Douglas Anderson, William Wu,
Greg Kroah-Hartman, linux-usb, Antti Seppälä
Make sure only to copy any actual data rather than the whole buffer,
when releasing the temporary buffer used for unaligned non-isochronous
transfers.
Taken directly from commit 0efd937e27d5e ("USB: ehci-tegra: fix inefficient
copy of unaligned buffers")
Tested with Lantiq xRX200 (MIPS) and RPi Model B Rev 2 (ARM)
Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
---
drivers/usb/dwc2/hcd.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 2ed0ac18e053..6e2cdd7b93d4 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2668,6 +2668,7 @@ static int dwc2_alloc_split_dma_aligned_buf(struct dwc2_hsotg *hsotg,
static void dwc2_free_dma_aligned_buffer(struct urb *urb)
{
void *stored_xfer_buffer;
+ size_t length;
if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
return;
@@ -2676,9 +2677,14 @@ static void dwc2_free_dma_aligned_buffer(struct urb *urb)
memcpy(&stored_xfer_buffer, urb->transfer_buffer +
urb->transfer_buffer_length, sizeof(urb->transfer_buffer));
- if (usb_urb_dir_in(urb))
- memcpy(stored_xfer_buffer, urb->transfer_buffer,
- urb->transfer_buffer_length);
+ if (usb_urb_dir_in(urb)) {
+ if (usb_pipeisoc(urb->pipe))
+ length = urb->transfer_buffer_length;
+ else
+ length = urb->actual_length;
+
+ memcpy(stored_xfer_buffer, urb->transfer_buffer, length);
+ }
kfree(urb->transfer_buffer);
urb->transfer_buffer = stored_xfer_buffer;
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [2/2] usb: dwc2: Fix inefficient copy of unaligned buffers
@ 2018-07-06 15:58 Doug Anderson
0 siblings, 0 replies; 2+ messages in thread
From: Doug Anderson @ 2018-07-06 15:58 UTC (permalink / raw)
To: Antti Seppälä
Cc: Minas Harutyunyan, John Youn, Felipe Balbi, Grigor Tovmasyan,
Vardan Mikayelyan, William Wu, Greg Kroah-Hartman, linux-usb
Hi,
On Thu, Jul 5, 2018 at 7:31 AM, Antti Seppälä <a.seppala@gmail.com> wrote:
> Make sure only to copy any actual data rather than the whole buffer,
> when releasing the temporary buffer used for unaligned non-isochronous
> transfers.
>
> Taken directly from commit 0efd937e27d5e ("USB: ehci-tegra: fix inefficient
> copy of unaligned buffers")
>
> Tested with Lantiq xRX200 (MIPS) and RPi Model B Rev 2 (ARM)
>
> Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
> ---
> drivers/usb/dwc2/hcd.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
I haven't personally gone down and tracked down the validity of
"actual_length", but I agree that this matches what tegra has done and
seems sane.
Reviewed-by: Douglas Anderson <dianders@chromium.org>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-06 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-05 14:31 [2/2] usb: dwc2: Fix inefficient copy of unaligned buffers Antti Seppälä
-- strict thread matches above, loose matches on Subject: below --
2018-07-06 15:58 Doug Anderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).