On Sat, 12 Feb 2011, Paul Zimmerman wrote: > Calculations like > > running_total = TRB_MAX_BUFF_SIZE - > (sg_dma_address(sg) & (TRB_MAX_BUFF_SIZE - 1)); > if (running_total != 0) > num_trbs++; > > are incorrect, because running_total can never be zero, so the if() > expression will never be true. I think the intention was that > running_total be in the range of 0 to TRB_MAX_BUFF_SIZE-1, not 1 > to TRB_MAX_BUFF_SIZE. So adding a > > running_total &= TRB_MAX_BUFF_SIZE - 1; > > fixes the problem. > > Signed-off-by: Paul Zimmerman <paulz@xxxxxxxxxxxx> > --- > drivers/usb/host/xhci-ring.c | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c > index fe6dd81..8939086 100644 > --- a/drivers/usb/host/xhci-ring.c > +++ b/drivers/usb/host/xhci-ring.c > @@ -2375,6 +2375,7 @@ static unsigned int count_sg_trbs_needed(struct xhci_hcd *xhci, struct urb *urb) > /* Scatter gather list entries may cross 64KB boundaries */ > running_total = TRB_MAX_BUFF_SIZE - > (sg_dma_address(sg) & (TRB_MAX_BUFF_SIZE - 1)); > + running_total &= TRB_MAX_BUFF_SIZE - 1; It be a lot simpler to replace these two expressions with: running_total = (- sg_dma_address(sg)) & (TRB_MAX_BUFF_SIZE - 1); However this might not be very comprehensible. As a compromise, you could use: running_total = (TRB_MAX_BUFF_SIZE - sg_dma_address(sg)) & (TRB_MAX_BUFF_SIZE - 1); Alan Stern -- 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