Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev fix broken, audio_{g,s}et_port logic.



details:   https://anonhg.NetBSD.org/src/rev/c4851e5531ed
branches:  trunk
changeset: 819793:c4851e5531ed
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Dec 17 15:18:28 2016 +0000

description:
fix broken, audio_{g,s}et_port logic.

diffstat:

 sys/dev/audio.c |  82 ++++++++++++++++++++++++--------------------------------
 1 files changed, 35 insertions(+), 47 deletions(-)

diffs (115 lines):

diff -r e9607098d1e6 -r c4851e5531ed sys/dev/audio.c
--- a/sys/dev/audio.c   Sat Dec 17 14:49:26 2016 +0000
+++ b/sys/dev/audio.c   Sat Dec 17 15:18:28 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.282 2016/12/16 22:14:15 christos Exp $     */
+/*     $NetBSD: audio.c,v 1.283 2016/12/17 15:18:28 christos Exp $     */
 
 /*-
  * Copyright (c) 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -148,7 +148,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.282 2016/12/16 22:14:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.283 2016/12/17 15:18:28 christos Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -5623,63 +5623,51 @@
 static int
 audio_set_port(struct audio_softc *sc, mixer_ctrl_t *mc)
 {
-       int i, j, n;
-
        KASSERT(mutex_owned(sc->sc_lock));
 
-       if (mc->dev >= sc->sc_static_nmixer_states) {
-               n = (mc->dev - sc->sc_static_nmixer_states) / 2;
-               i = j = 0;
-               while (i <= n) {
+       int d = mc->dev - sc->sc_static_nmixer_states;
+
+       if (d < 0)
+               return sc->hw_if->set_port(sc->hw_hdl, mc);
+
+       size_t j, n = (size_t)d / 2;
+       
+       for (size_t i = j = 0; i <= n; i++)
+               if (sc->sc_audiopid[i].pid != -1)
                        j++;
-                       if (sc->sc_audiopid[j].pid != -1)
-                               i++;
-               }
-               n = j;
-
-               if ((mc->dev - sc->sc_static_nmixer_states) % 2 == 0) {
-                       sc->sc_vchan[n]->sc_swvol =
-                           mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
-               } else {
-                       sc->sc_vchan[n]->sc_recswvol =
-                           mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
-               }
-
-               return 0;
-       }
-
-       return sc->hw_if->set_port(sc->hw_hdl, mc);
+
+       uint8_t *level = &mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
+       uint8_t *vol = (d & 1) == 0 ?
+           &sc->sc_vchan[j]->sc_swvol : &sc->sc_vchan[j]->sc_recswvol;
+
+       *vol = *level;
+       return 0;
 }
 
 static int
 audio_get_port(struct audio_softc *sc, mixer_ctrl_t *mc)
 {
-       int i, j, n;
 
        KASSERT(mutex_owned(sc->sc_lock));
 
-       if (mc->dev >= sc->sc_static_nmixer_states) {
-               n = (mc->dev - sc->sc_static_nmixer_states) / 2;
-               i = j = 0;
-               while (i <= n) {
+       int d = mc->dev - sc->sc_static_nmixer_states;
+
+       if (d < 0)
+               return sc->hw_if->get_port(sc->hw_hdl, mc);
+
+       size_t j, n = (size_t)d / 2;
+       
+       for (size_t i = j = 0; i <= n; i++)
+               if (sc->sc_audiopid[i].pid != -1)
                        j++;
-                       if (sc->sc_audiopid[j].pid != -1)
-                               i++;
-               }
-               n = j;
-
-               if ((mc->dev - sc->sc_static_nmixer_states) % 2 == 0) {
-                       mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
-                           sc->sc_vchan[n]->sc_swvol;
-               } else {
-                       mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
-                           sc->sc_vchan[n]->sc_recswvol;
-               }
-
-               return 0;
-       }
-
-       return sc->hw_if->get_port(sc->hw_hdl, mc);
+
+       u_char *level = &mc->un.value.level[AUDIO_MIXER_LEVEL_MONO];
+       uint8_t *vol = (d & 1) == 0 ?
+           &sc->sc_vchan[j]->sc_swvol : &sc->sc_vchan[j]->sc_recswvol;
+
+       *level = *vol;
+       return 0;
+
 }
 
 static int



Home | Main Index | Thread Index | Old Index