diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2016-12-20 16:03:40 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2016-12-20 16:03:40 +0000 |
commit | e5175244e0715bec617be80d08e27d4d5daa2978 (patch) | |
tree | e12a08c4b2a42b7b90aa7ec268d6c7b35db437a6 /sys/dev | |
parent | f73663a9ecd9643c152f84cb3aa6e457242828e9 (diff) |
In midiread() and midiwrite(), add a second goto label to
factor calls to mtx_leave() before returning. From Michael
W. Bombardieri <mb at ii.net>. Thanks!
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/midi.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/sys/dev/midi.c b/sys/dev/midi.c index 709368f0c95..fdc43f17ac0 100644 --- a/sys/dev/midi.c +++ b/sys/dev/midi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: midi.c,v 1.40 2015/05/22 12:52:00 jsg Exp $ */ +/* $OpenBSD: midi.c,v 1.41 2016/12/20 16:03:39 ratchov Exp $ */ /* * Copyright (c) 2003, 2004 Alexandre Ratchov @@ -125,18 +125,15 @@ midiread(dev_t dev, struct uio *uio, int ioflag) mtx_enter(&audio_lock); while (MIDIBUF_ISEMPTY(mb)) { if (ioflag & IO_NDELAY) { - mtx_leave(&audio_lock); error = EWOULDBLOCK; - goto done; + goto done_mtx; } sc->rchan = 1; error = msleep(&sc->rchan, &audio_lock, PWAIT | PCATCH, "mid_rd", 0); if (!(sc->dev.dv_flags & DVF_ACTIVE)) error = EIO; - if (error) { - mtx_leave(&audio_lock); - goto done; - } + if (error) + goto done_mtx; } /* at this stage, there is at least 1 byte */ @@ -154,6 +151,8 @@ midiread(dev_t dev, struct uio *uio, int ioflag) mtx_enter(&audio_lock); MIDIBUF_REMOVE(mb, count); } + +done_mtx: mtx_leave(&audio_lock); done: device_unref(&sc->dev); @@ -262,9 +261,8 @@ midiwrite(dev_t dev, struct uio *uio, int ioflag) error = 0; mtx_enter(&audio_lock); if ((ioflag & IO_NDELAY) && MIDIBUF_ISFULL(mb) && (uio->uio_resid > 0)) { - mtx_leave(&audio_lock); error = EWOULDBLOCK; - goto done; + goto done_mtx; } while (uio->uio_resid > 0) { @@ -274,18 +272,15 @@ midiwrite(dev_t dev, struct uio *uio, int ioflag) * At this stage at least one byte is already * moved so we do not return EWOULDBLOCK */ - mtx_leave(&audio_lock); - goto done; + goto done_mtx; } sc->wchan = 1; error = msleep(&sc->wchan, &audio_lock, PWAIT | PCATCH, "mid_wr", 0); if (!(sc->dev.dv_flags & DVF_ACTIVE)) error = EIO; - if (error) { - mtx_leave(&audio_lock); - goto done; - } + if (error) + goto done_mtx; } count = MIDIBUF_SIZE - MIDIBUF_END(mb); @@ -301,6 +296,8 @@ midiwrite(dev_t dev, struct uio *uio, int ioflag) mb->used += count; midi_out_start(sc); } + +done_mtx: mtx_leave(&audio_lock); done: device_unref(&sc->dev); |