summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorratchov <ratchov@openbsd.org>2015-05-12 18:05:43 +0000
committerratchov <ratchov@openbsd.org>2015-05-12 18:05:43 +0000
commit4ac461ca809b04c4b1f9d4a1bebcb76cf480058f (patch)
tree0eb3e935ea59f83b9d6ddff8a582a9e032ad0a6c
parentRemove references to (deleted) auconv.h and mulaw.h files. Fixes (diff)
downloadwireguard-openbsd-4ac461ca809b04c4b1f9d4a1bebcb76cf480058f.tar.xz
wireguard-openbsd-4ac461ca809b04c4b1f9d4a1bebcb76cf480058f.zip
Don't hold the audio mutex when calling uiomove(), as uiomove()
may sleep in case of a page fault
-rw-r--r--sys/dev/midi.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/sys/dev/midi.c b/sys/dev/midi.c
index d2f00461b66..277682a932e 100644
--- a/sys/dev/midi.c
+++ b/sys/dev/midi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: midi.c,v 1.34 2015/03/14 03:38:46 jsg Exp $ */
+/* $OpenBSD: midi.c,v 1.35 2015/05/12 18:05:43 ratchov Exp $ */
/*
* Copyright (c) 2003, 2004 Alexandre Ratchov
@@ -141,11 +141,11 @@ midiread(dev_t dev, struct uio *uio, int ioflag)
count = mb->used;
if (count > uio->uio_resid)
count = uio->uio_resid;
+ mtx_leave(&audio_lock);
error = uiomovei(mb->data + mb->start, count, uio);
- if (error) {
- mtx_leave(&audio_lock);
+ if (error)
return error;
- }
+ mtx_enter(&audio_lock);
MIDIBUF_REMOVE(mb, count);
}
mtx_leave(&audio_lock);
@@ -246,12 +246,13 @@ midiwrite(dev_t dev, struct uio *uio, int ioflag)
* in the buffer to store at least one byte. If not then dont
* start the write process.
*/
-
- if ((ioflag & IO_NDELAY) && MIDIBUF_ISFULL(mb) && (uio->uio_resid > 0))
+ mtx_enter(&audio_lock);
+ if ((ioflag & IO_NDELAY) && MIDIBUF_ISFULL(mb) && (uio->uio_resid > 0)) {
+ mtx_leave(&audio_lock);
return EWOULDBLOCK;
+ }
while (uio->uio_resid > 0) {
- mtx_enter(&audio_lock);
while (MIDIBUF_ISFULL(mb)) {
if (ioflag & IO_NDELAY) {
/*
@@ -279,15 +280,15 @@ midiwrite(dev_t dev, struct uio *uio, int ioflag)
count = MIDIBUF_AVAIL(mb);
if (count > uio->uio_resid)
count = uio->uio_resid;
+ mtx_leave(&audio_lock);
error = uiomovei(mb->data + MIDIBUF_END(mb), count, uio);
- if (error) {
- mtx_leave(&audio_lock);
+ if (error)
return error;
- }
+ mtx_enter(&audio_lock);
mb->used += count;
midi_out_start(sc);
- mtx_leave(&audio_lock);
}
+ mtx_leave(&audio_lock);
return 0;
}