From 96f231ac4b68fa34a2c0a6354f5089374ccc15c3 Mon Sep 17 00:00:00 2001 From: Caveh Jalali Date: Thu, 28 May 2020 18:19:36 -0700 Subject: usb/xhci: Fix timeout logic This fixes a logic bug in how timeouts are reported back. In the timeout case, the original code would return -1 instead of 0. All call sites expect a return value of 0 as the timeout indicator. Signed-off-by: Caveh Jalali Change-Id: I81a888aa0a1544e55e6a680be8f3b7f6e0d87812 Reviewed-on: https://review.coreboot.org/c/coreboot/+/41854 Tested-by: build bot (Jenkins) Reviewed-by: Tim Wawrzynczak --- payloads/libpayload/drivers/usb/xhci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'payloads') diff --git a/payloads/libpayload/drivers/usb/xhci.c b/payloads/libpayload/drivers/usb/xhci.c index 07d5b16486..749ff0a066 100644 --- a/payloads/libpayload/drivers/usb/xhci.c +++ b/payloads/libpayload/drivers/usb/xhci.c @@ -129,7 +129,12 @@ xhci_switchback_ppt_ports(pcidev_t addr) static long xhci_handshake(volatile u32 *const reg, u32 mask, u32 wait_for, long timeout_us) { - while ((*reg & mask) != wait_for && timeout_us--) udelay(1); + if (timeout_us <= 0) + return 0; + while ((*reg & mask) != wait_for && timeout_us != 0) { + --timeout_us; + udelay(1); + } return timeout_us; } -- cgit v1.2.3