we _know_ that for_each_sg() will only iterate over number of mapped sgs, so there's no need to count full_len and break out when it reaches zero. Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx> --- drivers/usb/host/xhci-ring.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index d7f9c0cfa047..c6b77282924d 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -2967,17 +2967,13 @@ static inline unsigned int count_trbs_needed(struct urb *urb) static unsigned int count_sg_trbs_needed(struct urb *urb) { struct scatterlist *sg; - unsigned int i, len, full_len, num_trbs = 0; - - full_len = urb->transfer_buffer_length; + unsigned int i, num_trbs = 0; for_each_sg(urb->sg, sg, urb->num_mapped_sgs, i) { - len = sg_dma_len(sg); - num_trbs += count_trbs(sg_dma_address(sg), len); - len = min_t(unsigned int, len, full_len); - full_len -= len; - if (full_len == 0) - break; + unsigned int len = sg_dma_len(sg); + dma_addr_t dma = sg_dma_address(sg); + + num_trbs += count_trbs(dma, len); } return num_trbs; -- 2.8.0.rc2 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html