alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, Clemens Ladisch <clemens@ladisch.de>
Subject: Re: [PATCH] alsa-lib/tlv: fix handling of raw value	ranges
Date: Tue, 22 May 2012 18:06:34 +0200 (CEST)	[thread overview]
Message-ID: <1666726176.1119743.1337702794239.JavaMail.root@advansee.com> (raw)
In-Reply-To: <s5hbolg8uyp.wl%tiwai@suse.de>

[-- Attachment #1: Type: text/plain, Size: 268 bytes --]

Hi Takashi,

Takashi Iwai wrote:
> It's OK to put an attachment, but I failed to apply it.
> Please check the patch you sent can be really applied cleanly to
> alsa-lib git tree.

My copy/paste damaged tabs. Hopefully, this should now work.

Regards,
Benoît

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: improve-tlv-raw-val-robustness.patch --]
[-- Type: text/x-patch; name=improve-tlv-raw-val-robustness.patch, Size: 1971 bytes --]

alsa-lib/tlv: improve robustness of raw value ranges

snd_tlv_convert_from_dB() relies on rangemin/max blindly. Since this function is
exported, it is better for robustness and consistency to parse the range
properly, which this patch does.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>

--- alsa-lib/src/control/tlv.c
+++ alsa-lib/src/control/tlv.c
@@ -291,41 +291,37 @@ int snd_tlv_convert_from_dB(unsigned int
 {
 	switch (tlv[0]) {
 	case SND_CTL_TLVT_DB_RANGE: {
-		long dbmin, dbmax, prev_rangemax;
+		long dbmin, dbmax, prev_submax;
 		unsigned int pos, len;
 		len = int_index(tlv[1]);
-		if (len > MAX_TLV_RANGE_SIZE)
+		if (len < 6 || len > MAX_TLV_RANGE_SIZE)
 			return -EINVAL;
-		if (snd_tlv_get_dB_range(tlv, rangemin, rangemax,
-					 &dbmin, &dbmax))
-			return -EINVAL;
-		if (db_gain <= dbmin) {
-			*value = rangemin;
-			return 0;
-		} else if (db_gain >= dbmax) {
-			*value = rangemax;
-			return 0;
-		}
 		pos = 2;
-		prev_rangemax = 0;
+		prev_submax = 0;
 		while (pos + 4 <= len) {
-			rangemin = (int)tlv[pos];
-			rangemax = (int)tlv[pos + 1];
+			long submin, submax;
+			submin = (int)tlv[pos];
+			submax = (int)tlv[pos + 1];
+			if (rangemax < submax)
+				submax = rangemax;
 			if (!snd_tlv_get_dB_range(tlv + pos + 2,
-						  rangemin, rangemax,
+						  submin, submax,
 						  &dbmin, &dbmax) &&
 			    db_gain >= dbmin && db_gain <= dbmax)
 				return snd_tlv_convert_from_dB(tlv + pos + 2,
-							       rangemin, rangemax,
+							       submin, submax,
 							       db_gain, value, xdir);
 			else if (db_gain < dbmin) {
-				*value = xdir ? rangemin : prev_rangemax;
+				*value = xdir || pos == 2 ? submin : prev_submax;
 				return 0;
 			}
-			prev_rangemax = rangemax;
+			prev_submax = submax;
+			if (rangemax == submax)
+				break;
 			pos += int_index(tlv[pos + 3]) + 4;
 		}
-		return -EINVAL;
+		*value = prev_submax;
+		return 0;
 	}
 	case SND_CTL_TLVT_DB_SCALE: {
 		int min, step, max;

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2012-05-22 16:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <a995c693-9d0b-4572-af9c-85e3deebf37c@zose-store-12>
2012-03-29 23:05 ` [PATCH] alsa-lib/tlv: fix handling of raw value ranges Benoît Thébaudeau
2012-03-30  8:37   ` Clemens Ladisch
2012-03-30 10:41     ` Benoît Thébaudeau
2012-03-30 11:44       ` Takashi Iwai
2012-03-30 11:51         ` Takashi Iwai
2012-03-30 13:07           ` Benoît Thébaudeau
2012-03-30 13:23             ` Takashi Iwai
2012-03-30 12:38       ` Clemens Ladisch
2012-03-30 13:07         ` Benoît Thébaudeau
2012-03-30 13:10           ` Benoît Thébaudeau
2012-03-30 13:51           ` Clemens Ladisch
2012-03-30 13:58             ` Benoît Thébaudeau
2012-03-30 15:20               ` Benoît Thébaudeau
2012-03-30 15:45                 ` Takashi Iwai
2012-03-30 15:59                   ` Benoît Thébaudeau
2012-03-30 15:44               ` Takashi Iwai
2012-03-30 16:15                 ` Benoît Thébaudeau
2012-05-21 19:38                 ` Benoît Thébaudeau
2012-05-22  0:57                   ` Takashi Iwai
2012-05-22  2:19                     ` Benoît Thébaudeau
2012-05-22  8:45                       ` Takashi Iwai
2012-05-22 16:06                         ` Benoît Thébaudeau [this message]
2012-05-22 23:54                           ` Takashi Iwai
2012-06-02  8:09       ` James Courtier-Dutton
2012-06-02 12:26         ` Benoît Thébaudeau

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=1666726176.1119743.1337702794239.JavaMail.root@advansee.com \
    --to=benoit.thebaudeau@advansee.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /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).