Skip to content

Commit

Permalink
ehci(4): Fix cv_timedwait loop in ehci_sync_hc.
Browse files Browse the repository at this point in the history
Stop when

	now - starttime >= delta,

i.e., when at least delta ticks have elapsed since the start, not
when

	endtime - now > delta,

i.e., more than delta ticks _remain_ to sleep, which is never going
to happen (except on arithmetic overflow).

As is, what will happen in the case that should time out is that we
wake up after delta ticks, and find now = getticks() is exactly
endtime, so we retry cv_timedwait with timo=(endtime - now)=0 which
means sleep indefinitely with no timeout as if with cv_wait.

PR port-i386/57662

XXX pullup-10
  • Loading branch information
riastradh authored and riastradh committed Oct 28, 2023
1 parent 794ef7d commit b436790
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sys/dev/usb/ehci.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: ehci.c,v 1.317 2023/07/30 12:17:02 skrll Exp $ */
/* $NetBSD: ehci.c,v 1.318 2023/10/28 21:18:15 riastradh Exp $ */

/*
* Copyright (c) 2004-2012,2016,2020 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -54,7 +54,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.317 2023/07/30 12:17:02 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.318 2023/10/28 21:18:15 riastradh Exp $");

#include "ohci.h"
#include "uhci.h"
Expand Down Expand Up @@ -2277,7 +2277,7 @@ ehci_sync_hc(ehci_softc_t *sc)
*/
while (sc->sc_doorbelllwp == curlwp) {
now = getticks();
if (endtime - now > delta) {
if (now - starttime >= delta) {
sc->sc_doorbelllwp = NULL;
cv_signal(&sc->sc_doorbell);
DPRINTF("doorbell timeout", 0, 0, 0, 0);
Expand Down

0 comments on commit b436790

Please sign in to comment.