Module Name: src
Committed By: drochner
Date: Wed Sep 9 11:47:24 UTC 2009
Modified Files:
src/sys/dev/pci/hdaudio: hdaudio_afg.c
Log Message:
catch the case where a mixer's "step" value is 0 (read from the hardware),
while such a mixer is likely not very useful it should not cause
a division by 0
(should fix the crash reported by Tobias Nygren)
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/pci/hdaudio/hdaudio_afg.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/pci/hdaudio/hdaudio_afg.c
diff -u src/sys/dev/pci/hdaudio/hdaudio_afg.c:1.9 src/sys/dev/pci/hdaudio/hdaudio_afg.c:1.10
--- src/sys/dev/pci/hdaudio/hdaudio_afg.c:1.9 Wed Sep 9 01:39:51 2009
+++ src/sys/dev/pci/hdaudio/hdaudio_afg.c Wed Sep 9 11:47:24 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio_afg.c,v 1.9 2009/09/09 01:39:51 jmcneill Exp $ */
+/* $NetBSD: hdaudio_afg.c,v 1.10 2009/09/09 11:47:24 drochner Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <[email protected]>
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdaudio_afg.c,v 1.9 2009/09/09 01:39:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio_afg.c,v 1.10 2009/09/09 11:47:24 drochner Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -3355,7 +3355,7 @@
struct hdaudio_afg_softc *sc = ad->ad_sc;
struct hdaudio_mixer *mx;
struct hdaudio_control *ctl;
- int i;
+ int i, divisor;
if (mc->dev < 0 || mc->dev >= sc->sc_nmixers)
return EINVAL;
@@ -3385,9 +3385,14 @@
return 0;
}
+ if (ctl->ctl_step == 0)
+ divisor = 128; /* ??? - just avoid div by 0 */
+ else
+ divisor = 255 / ctl->ctl_step;
+
hdaudio_afg_control_amp_set(ctl, HDAUDIO_AMP_MUTE_NONE,
- mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] / (255 / ctl->ctl_step),
- mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] / (255 / ctl->ctl_step));
+ mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] / divisor,
+ mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] / divisor);
return 0;
}
@@ -3400,7 +3405,7 @@
struct hdaudio_mixer *mx;
struct hdaudio_control *ctl;
u_int mask = 0;
- int i;
+ int i, factor;
if (mc->dev < 0 || mc->dev >= sc->sc_nmixers)
return EINVAL;
@@ -3430,10 +3435,13 @@
return 0;
}
- mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
- ctl->ctl_left * (255 / ctl->ctl_step);
- mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
- ctl->ctl_right * (255 / ctl->ctl_step);
+ if (ctl->ctl_step == 0)
+ factor = 128; /* ??? - just avoid div by 0 */
+ else
+ factor = 255 / ctl->ctl_step;
+
+ mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = ctl->ctl_left * factor;
+ mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = ctl->ctl_right * factor;
return 0;
}