[alsa-devel] [PATCH - alsa-lib 1/3] tlv: Check out of range dB with SND_CTL_TLVT_DB_RANGE
Takashi Iwai
tiwai at suse.de
Mon Jul 19 17:48:06 CEST 2010
At Mon, 19 Jul 2010 10:14:04 +0300,
Peter Ujfalusi wrote:
>
> When converting from dB value to raw value, the control's
> full range was not checked in case of SND_CTL_TLVT_DB_RANGE.
>
> Check out of range dB values, and return apropriate raw
> value for the caller.
>
> Signed-off-by: Peter Ujfalusi <peter.ujfalusi at nokia.com>
> ---
> src/control/tlv.c | 9 ++++++++-
> 1 files changed, 8 insertions(+), 1 deletions(-)
>
> diff --git a/src/control/tlv.c b/src/control/tlv.c
> index 0ff052e..d09766a 100644
> --- a/src/control/tlv.c
> +++ b/src/control/tlv.c
> @@ -285,13 +285,20 @@ int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
> {
> switch (tlv[0]) {
> case SND_CTL_TLVT_DB_RANGE: {
> + long dbmin, dbmax;
> unsigned int pos, len;
> len = int_index(tlv[1]);
> if (len > MAX_TLV_RANGE_SIZE)
> return -EINVAL;
> + if (snd_tlv_get_dB_range(tlv, rangemin, rangemax,
> + &dbmin, &dbmax))
> + return -EINVAL;
> + if (db_gain <= dbmin || db_gain >= dbmax) {
> + *value = db_gain <= dbmin ? rangemin : rangemax;
> + return 0;
> + }
The check looks good, but IMO, just plain two if's are more intuitive:
if (db_gain <= dbmin) {
*value = rangemin;
return 0;
} else if (db_gain >= dbmax) {
*value = rangemax;
return 0;
}
thanks,
Takashi
More information about the Alsa-devel
mailing list