Module Name:    src
Committed By:   riastradh
Date:           Sun Oct 23 23:02:50 UTC 2022

Modified Files:
        src/sys/dev: midi.c

Log Message:
midi(4): Wake waiters _before_ waiting for them.

Otherwise we may deadlock waiting for them to give up while they're
waiting for I/O, not knowing they need to give up.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/midi.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/midi.c
diff -u src/sys/dev/midi.c:1.98 src/sys/dev/midi.c:1.99
--- src/sys/dev/midi.c:1.98	Sat Jun  4 03:31:10 2022
+++ src/sys/dev/midi.c	Sun Oct 23 23:02:50 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: midi.c,v 1.98 2022/06/04 03:31:10 pgoyette Exp $	*/
+/*	$NetBSD: midi.c,v 1.99 2022/10/23 23:02:50 riastradh Exp $	*/
 
 /*
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.98 2022/06/04 03:31:10 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.99 2022/10/23 23:02:50 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "midi.h"
@@ -206,13 +206,12 @@ mididetach(device_t self, int flags)
 
 	mutex_enter(sc->lock);
 	sc->dying = 1;
+	cv_broadcast(&sc->wchan);
+	cv_broadcast(&sc->rchan);
 
 	if (--sc->refcnt >= 0) {
-		/* Wake anything? */
 		(void)cv_timedwait(&sc->detach_cv, sc->lock, hz * 60);
 	}
-	cv_broadcast(&sc->wchan);
-	cv_broadcast(&sc->rchan);
 	mutex_exit(sc->lock);
 
 	/* locate the major number */

Reply via email to