alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: "Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] alsa-lib/tlv: fix handling of raw value ranges
Date: Fri, 30 Mar 2012 10:37:37 +0200	[thread overview]
Message-ID: <4F7570D1.2060809@ladisch.de> (raw)
In-Reply-To: <bf360596-9a77-4441-bf58-09ed92891e19@zose-store-12>

Benoît Thébaudeau wrote:
> In case of a TLV dB range with all items having raw value ranges strictly within
> the main raw value range reported by the driver, snd_tlv_convert_from_dB()
> returned one of the main raw range boundaries, which was outside all dB range
> items.

But the main raw range boundaries _are_ valid values.

I guess the problem you actually have is that convert_to_dB does not
work with these raw values?

> static const unsigned int bd3753x_vol_fader_gain_att_tlv[] = {
> 	TLV_DB_RANGE_HEAD(2),
> 	0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
> 	48, 142, TLV_DB_SCALE_ITEM(-7900, 100, 0),
> };
> 	SOC_SINGLE_TLV("Main Volume",
> 		       BD3753X_VOL_GAIN,
> 		       0, 255, 1, bd3753x_vol_fader_gain_att_tlv),
>
> snd_tlv_convert_from_dB(tlv, 0, 255, 1500, &value, 1) returned 255 instead of
> the expected 142.

But there is no guarantee that this mixer control will have only one of
those values in the TLV's range.  Furthermore, convert_to_dB will still
fail for any raw value 1..47.

This TLV is just incomplete.  Please report this bug to the driver's
author.

As for the patch, while I'm not sure whether it is needed at all, I also
don't quite understand the reason for all the changes.

> --- 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_submax;
>  		unsigned int pos, len;
>  		len = int_index(tlv[1]);
> +		if (len < 6 || len > MAX_TLV_RANGE_SIZE)
>  			return -EINVAL;
>  		pos = 2;
> +		prev_submax = 0;
> +		do {

Why is this not a while loop?

> +			long submin, submax;
> +			submin = (int)tlv[pos];
> +			submax = (int)tlv[pos + 1];
> +			if (rangemax < submax)
> +				submax = rangemax;

Why is this check needed?  Any why not return -EINVAL?

>  			if (!snd_tlv_get_dB_range(tlv + pos + 2,
> +						  submin, submax,
>  						  &dbmin, &dbmax) &&
>  			    db_gain >= dbmin && db_gain <= dbmax)
>  				return snd_tlv_convert_from_dB(tlv + pos + 2,
> +							       submin, submax,
>  							       db_gain, value, xdir);
>  			else if (db_gain < dbmin) {
> +				*value = xdir || pos == 2 ? submin : prev_submax;
>  				return 0;
>  			}
> +			prev_submax = submax;
> +			if (rangemax == submax)
> +				break;

Why this check?

>  			pos += int_index(tlv[pos + 3]) + 4;
> +		} while (pos + 4 <= len);
> +		*value = prev_submax;
> +		return 0;
>  	}


Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

  reply	other threads:[~2012-03-30  8:34 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 [this message]
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
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=4F7570D1.2060809@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=benoit.thebaudeau@advansee.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).