diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-03-20 00:40:52 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-03-20 00:40:52 +0000 |
| commit | db001d1ace892ccca35309eb4ea1935e99de26f6 (patch) | |
| tree | 98fe2854c154d22ffac9d13356494c807fbc57aa /sys/dev/usb | |
| parent | 30afedb017fa787130b2f2cacc2920d02fcd1e9c (diff) | |
usbdi(9): Make sure aborting a pipe waits for all callbacks.
There may be a callback in flight from an xfer that has already been
taken off the queue by the time usbd_ar_pipe gets to it. We must
guarantee that even that callback has completed before returning
control to the caller.
Diffstat (limited to 'sys/dev/usb')
| -rw-r--r-- | sys/dev/usb/usbdi.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sys/dev/usb/usbdi.c b/sys/dev/usb/usbdi.c index 6f564f2ccc8..fab8108fc6d 100644 --- a/sys/dev/usb/usbdi.c +++ b/sys/dev/usb/usbdi.c @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi.c,v 1.239 2022/03/19 10:05:52 riastradh Exp $ */ +/* $NetBSD: usbdi.c,v 1.240 2022/03/20 00:40:52 riastradh Exp $ */ /* * Copyright (c) 1998, 2012, 2015 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.239 2022/03/19 10:05:52 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.240 2022/03/20 00:40:52 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_usb.h" @@ -1071,6 +1071,19 @@ usbd_ar_pipe(struct usbd_pipe *pipe) } } + /* + * There may be an xfer callback already in progress which was + * taken off the queue before we got to it. We must wait for + * the callback to finish before returning control to the + * caller. + */ + while (pipe->up_callingxfer) { + USBHIST_LOG(usbdebug, "wait for callback" + "pipe = %#jx xfer = %#jx", + (uintptr_t)pipe, (uintptr_t)pipe->up_callingxfer, 0, 0); + cv_wait(&pipe->up_callingcv, pipe->up_dev->ud_bus->ub_lock); + } + KASSERT(mutex_owned(pipe->up_dev->ud_bus->ub_lock)); KASSERTMSG(pipe->up_abortlwp == curlwp, "pipe->up_abortlwp=%p", pipe->up_abortlwp); |
