kernel: Copy patches from kernel 4.14 to 4.19
[openwrt/staging/wigyori.git] / target / linux / generic / pending-4.19 / 171-usb-dwc2-Fix-inefficient-copy-of-unaligned-buffers.patch
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
9 Make sure only to copy any actual data rather than the whole buffer,
10 when releasing the temporary buffer used for unaligned non-isochronous
11 transfers.
12
13 Taken directly from commit 0efd937e27d5e ("USB: ehci-tegra: fix inefficient
14 copy of unaligned buffers")
15
16 Tested with Lantiq xRX200 (MIPS) and RPi Model B Rev 2 (ARM)
17
18 Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
19 ---
20 drivers/usb/dwc2/hcd.c | 12 +++++++++---
21 1 file changed, 9 insertions(+), 3 deletions(-)
22
23 --- a/drivers/usb/dwc2/hcd.c
24 +++ b/drivers/usb/dwc2/hcd.c
25 @@ -2669,6 +2669,7 @@ static int dwc2_alloc_split_dma_aligned_
26 static void dwc2_free_dma_aligned_buffer(struct urb *urb)
27 {
28 void *stored_xfer_buffer;
29 + size_t length;
30
31 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
32 return;
33 @@ -2677,9 +2678,14 @@ static void dwc2_free_dma_aligned_buffer
34 memcpy(&stored_xfer_buffer, urb->transfer_buffer +
35 urb->transfer_buffer_length, sizeof(urb->transfer_buffer));
36
37 - if (usb_urb_dir_in(urb))
38 - memcpy(stored_xfer_buffer, urb->transfer_buffer,
39 - urb->transfer_buffer_length);
40 + if (usb_urb_dir_in(urb)) {
41 + if (usb_pipeisoc(urb->pipe))
42 + length = urb->transfer_buffer_length;
43 + else
44 + length = urb->actual_length;
45 +
46 + memcpy(stored_xfer_buffer, urb->transfer_buffer, length);
47 + }
48 kfree(urb->transfer_buffer);
49 urb->transfer_buffer = stored_xfer_buffer;
50