mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH]: 2.4.0-testx: ac97_codec
@ 2000-11-27 17:38 Thomas Sailer
  0 siblings, 0 replies; only message in thread
From: Thomas Sailer @ 2000-11-27 17:38 UTC (permalink / raw)
  To: linux-kernel, torvalds

In the current ac97_codec, computation of attenuation values may overflow
the register width, thus resulting in maximum volume when minimum was requested.
This patch adds overflow checks and limitations.

Tom

--- ac97_codec.c.orig	Thu Nov 23 13:13:13 2000
+++ ac97_codec.c	Thu Nov 23 13:20:01 2000
@@ -284,6 +284,10 @@
 			if (oss_channel == SOUND_MIXER_IGAIN) {
 				right = (right * mh->scale) / 100;
 				left = (left * mh->scale) / 100;
+				if (right >= mh->scale)
+					right = mh->scale-1;
+				if (left >= mh->scale)
+					left = mh->scale-1;
 			} else {
 				/* these may have 5 or 6 bit resolution */
 				if (oss_channel == SOUND_MIXER_VOLUME ||
@@ -294,27 +298,49 @@
 
 				right = ((100 - right) * scale) / 100;
 				left = ((100 - left) * scale) / 100;
-			}			
+				if (right >= scale)
+					right = scale-1;
+				if (left >= scale)
+					left = scale-1;
+			}
 			val = (left << 8) | right;
 		}
 	} else if (oss_channel == SOUND_MIXER_BASS) {
 		val = codec->codec_read(codec , mh->offset) & ~0x0f00;
-		val |= ((((100 - left) * mh->scale) / 100) << 8) & 0x0e00;
+		left = ((100 - left) * mh->scale) / 100;
+		if (left >= mh->scale)
+			left = mh->scale-1;
+		val |= (left << 8) & 0x0e00;
 	} else if (oss_channel == SOUND_MIXER_TREBLE) {
 		val = codec->codec_read(codec , mh->offset) & ~0x000f;
-		val |= (((100 - left) * mh->scale) / 100) & 0x000e;
+		left = ((100 - left) * mh->scale) / 100;
+		if (left >= mh->scale)
+			left = mh->scale-1;
+		val |= left & 0x000e;
 	} else if(left == 0) {
 		val = AC97_MUTE;
 	} else if (oss_channel == SOUND_MIXER_SPEAKER) {
-		val = (((100 - left) * mh->scale) / 100) << 1;
+		left = ((100 - left) * mh->scale) / 100;
+		if (left >= mh->scale)
+			left = mh->scale-1;
+		val = left << 1;
 	} else if (oss_channel == SOUND_MIXER_PHONEIN) {
-		val = (((100 - left) * mh->scale) / 100);
+		left = ((100 - left) * mh->scale) / 100;
+		if (left >= mh->scale)
+			left = mh->scale-1;
+		val = left;
 	} else if (oss_channel == SOUND_MIXER_PHONEOUT) {
 		scale = (1 << codec->bit_resolution);
-		val = (((100 - left) * scale) / 100);
+		left = ((100 - left) * scale) / 100;
+		if (left >= mh->scale)
+			left = mh->scale-1;
+		val = left;
 	} else if (oss_channel == SOUND_MIXER_MIC) {
 		val = codec->codec_read(codec , mh->offset) & ~0x801f;
-		val |= (((100 - left) * mh->scale) / 100);
+		left = ((100 - left) * mh->scale) / 100;
+		if (left >= mh->scale)
+			left = mh->scale-1;
+		val |= left;
 		/*  the low bit is optional in the tone sliders and masking
 		    it lets us avoid the 0xf 'bypass'.. */
 	}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-11-27 18:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-27 17:38 [PATCH]: 2.4.0-testx: ac97_codec Thomas Sailer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®