Module Name:    src
Committed By:   riastradh
Date:           Sun Mar 20 00:40:52 UTC 2022

Modified Files:
        src/sys/dev/usb: usbdi.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.239 -r1.240 src/sys/dev/usb/usbdi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/usbdi.c
diff -u src/sys/dev/usb/usbdi.c:1.239 src/sys/dev/usb/usbdi.c:1.240
--- src/sys/dev/usb/usbdi.c:1.239	Sat Mar 19 10:05:52 2022
+++ src/sys/dev/usb/usbdi.c	Sun Mar 20 00:40:52 2022
@@ -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);

Reply via email to