summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2016-10-06 05:29:20 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2016-10-06 05:29:20 +0000
commit88e935907f31f7de4be8d4d3615bafc1e3580c04 (patch)
treedcd79c37a14ee386eb5999816df590c4be674160 /sys
parent5a4a0fc4f6ed6911157af114be90ddc28495a08d (diff)
Fix the condition used to decide whether to automatically start the
device, and factor it into a single function. Without this fix, if the device is open in full-duplex mode, it could start with empty play buffer.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/audio.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sys/dev/audio.c b/sys/dev/audio.c
index cd8d0834b0b..e230e584106 100644
--- a/sys/dev/audio.c
+++ b/sys/dev/audio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: audio.c,v 1.154 2016/10/04 23:02:03 deraadt Exp $ */
+/* $OpenBSD: audio.c,v 1.155 2016/10/06 05:29:19 ratchov Exp $ */
/*
* Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
*
@@ -593,6 +593,18 @@ audio_stop(struct audio_softc *sc)
}
int
+audio_canstart(struct audio_softc *sc)
+{
+ if (sc->active || sc->pause)
+ return 0;
+ if ((sc->mode & AUMODE_RECORD) && sc->rec.used != 0)
+ return 0;
+ if ((sc->mode & AUMODE_PLAY) && sc->play.used != sc->play.len)
+ return 0;
+ return 1;
+}
+
+int
audio_setpar(struct audio_softc *sc)
{
struct audio_params p, r;
@@ -1377,7 +1389,7 @@ audio_read(struct audio_softc *sc, struct uio *uio, int ioflag)
/* start automatically if audio_ioc_start() was never called */
mtx_enter(&audio_lock);
- if (!sc->active && !sc->pause && sc->rec.used == 0) {
+ if (audio_canstart(sc)) {
mtx_leave(&audio_lock);
error = audio_start(sc);
if (error)
@@ -1500,8 +1512,7 @@ audio_write(struct audio_softc *sc, struct uio *uio, int ioflag)
audio_buf_wcommit(&sc->play, count);
/* start automatically if audio_ioc_start() was never called */
- if (!sc->active && !sc->pause &&
- sc->play.used == sc->play.len) {
+ if (audio_canstart(sc)) {
mtx_leave(&audio_lock);
error = audio_start(sc);
if (error)