This is a note to let you know that I've just added the patch titled xhci: handle failed buffer copy to URB sg list and fix a W=1 copiler warning to the 5.13-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: xhci-handle-failed-buffer-copy-to-urb-sg-list-and-fi.patch and it can be found in the queue-5.13 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit cd58753dc2100e11b12846ffc52413f3484374ff Author: Mathias Nyman <mathias.nyman@xxxxxxxxxxxxxxx> Date: Thu Jun 17 18:03:53 2021 +0300 xhci: handle failed buffer copy to URB sg list and fix a W=1 copiler warning [ Upstream commit 271a21d8b280b186f8cc9ca6f7151902efde9512 ] Set the urb->actual_length to bytes successfully copied in case all bytes weren't copied from a temporary buffer to the URB sg list. Also print a debug message Signed-off-by: Mathias Nyman <mathias.nyman@xxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/20210617150354.1512157-4-mathias.nyman@xxxxxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 27283654ca08..9248ce8d09a4 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1361,12 +1361,17 @@ static void xhci_unmap_temp_buf(struct usb_hcd *hcd, struct urb *urb) urb->transfer_buffer_length, dir); - if (usb_urb_dir_in(urb)) + if (usb_urb_dir_in(urb)) { len = sg_pcopy_from_buffer(urb->sg, urb->num_sgs, urb->transfer_buffer, buf_len, 0); - + if (len != buf_len) { + xhci_dbg(hcd_to_xhci(hcd), + "Copy from tmp buf to urb sg list failed\n"); + urb->actual_length = len; + } + } urb->transfer_flags &= ~URB_DMA_MAP_SINGLE; kfree(urb->transfer_buffer); urb->transfer_buffer = NULL;