linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Sailer <sailer@ife.ee.ethz.ch>
To: linux-kernel@vger.kernel.org, torvalds@transmeta.com
Subject: [PATCH]: 2.4.0-testx: ac97_codec
Date: Mon, 27 Nov 2000 18:38:52 +0100 (MET)	[thread overview]
Message-ID: <200011271738.eARHcqM05977@eldrich.ee.ethz.ch> (raw)

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/

                 reply	other threads:[~2000-11-27 18:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200011271738.eARHcqM05977@eldrich.ee.ethz.ch \
    --to=sailer@ife.ee.ethz.ch \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).