Module Name:    src
Committed By:   nat
Date:           Wed Mar 29 06:24:22 UTC 2017

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

Log Message:
Fix channel assignment for multiple channels.

This fixes a problem if two or more channels are opened and the first
(any but last channel) is closed and new channels are opened.


To generate a diff of this commit:
cvs rdiff -u -r1.318 -r1.319 src/sys/dev/audio.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/audio.c
diff -u src/sys/dev/audio.c:1.318 src/sys/dev/audio.c:1.319
--- src/sys/dev/audio.c:1.318	Mon Mar 27 23:25:24 2017
+++ src/sys/dev/audio.c	Wed Mar 29 06:24:22 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.318 2017/03/27 23:25:24 nat Exp $	*/
+/*	$NetBSD: audio.c,v 1.319 2017/03/29 06:24:22 nat Exp $	*/
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.318 2017/03/27 23:25:24 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.319 2017/03/29 06:24:22 nat Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -2084,9 +2084,14 @@ audio_open(dev_t dev, struct audio_softc
 	hw = sc->hw_if;
 	if (hw == NULL)
 		return ENXIO;
-	n = 0;
-	SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries)
-		n++;
+	n = 1;
+	SIMPLEQ_FOREACH(chan, &sc->sc_audiochan, entries) {
+		if (chan == SIMPLEQ_FIRST(&sc->sc_audiochan))
+			continue;
+		n = chan->chan + 1;
+	}
+	if (n < 0)
+		return ENOMEM;
 
 	chan = kmem_zalloc(sizeof(struct audio_chan), KM_SLEEP);
 	vc = kmem_zalloc(sizeof(struct virtual_channel), KM_SLEEP);

Reply via email to