Skip to content

Commit

Permalink
USB: musb: fix inefficient copy of unaligned buffers
Browse files Browse the repository at this point in the history
Make sure only to copy any actual data rather than the whole buffer,
when releasing the temporary buffer used for unaligned non-isochronous
transfers.

Signed-off-by: Johan Hovold <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
jhovold authored and gregkh committed May 7, 2015
1 parent a842529 commit 8ca9a32
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/usb/musb/musb_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,7 @@ static void musb_free_temp_buffer(struct urb *urb)
{
enum dma_data_direction dir;
struct musb_temp_buffer *temp;
size_t length;

if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
return;
Expand All @@ -2522,8 +2523,12 @@ static void musb_free_temp_buffer(struct urb *urb)
data);

if (dir == DMA_FROM_DEVICE) {
memcpy(temp->old_xfer_buffer, temp->data,
urb->transfer_buffer_length);
if (usb_pipeisoc(urb->pipe))
length = urb->transfer_buffer_length;
else
length = urb->actual_length;

memcpy(temp->old_xfer_buffer, temp->data, length);
}
urb->transfer_buffer = temp->old_xfer_buffer;
kfree(temp->kmalloc_ptr);
Expand Down

0 comments on commit 8ca9a32

Please sign in to comment.