Skip to content

Commit 5adc1cc

Browse files
Epicuriusgregkh
authored andcommitted
usb: xhci: address off-by-one in xhci_num_trbs_free()
Reduce the number of do-while loops by 1. The number of loops should be number of segment + 1, the +1 is in case deq and enq are on the same segment. But due to the use of a do-while loop, the expression is evaluated after executing the loop, thus the loop is executed 1 extra time. Changing the do-while loop expression from "<=" to "<", reduces the loop amount by 1. The expression "<=" would also work if it was a while loop instead of a do-while loop. Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://lore.kernel.org/r/20240429140245.3955523-6-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 577c867 commit 5adc1cc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/usb/host/xhci-ring.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static unsigned int xhci_num_trbs_free(struct xhci_hcd *xhci, struct xhci_ring *
308308
free += last_on_seg - enq;
309309
enq_seg = enq_seg->next;
310310
enq = enq_seg->trbs;
311-
} while (i++ <= ring->num_segs);
311+
} while (i++ < ring->num_segs);
312312

313313
return free;
314314
}

0 commit comments

Comments
 (0)