[ALSA] aoa - Check value range in ctl callbacks

Check the value ranges in ctl put callbacks properly in aoa drivers.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Takashi Iwai 2007-11-15 16:16:32 +01:00 committed by Jaroslav Kysela
parent 02ff132493
commit 498ade1a13
3 changed files with 33 additions and 2 deletions

View File

@ -138,6 +138,13 @@ static int onyx_snd_vol_put(struct snd_kcontrol *kcontrol,
struct onyx *onyx = snd_kcontrol_chip(kcontrol); struct onyx *onyx = snd_kcontrol_chip(kcontrol);
s8 l, r; s8 l, r;
if (ucontrol->value.integer.value[0] < -128 + VOLUME_RANGE_SHIFT ||
ucontrol->value.integer.value[0] > -1 + VOLUME_RANGE_SHIFT)
return -EINVAL;
if (ucontrol->value.integer.value[1] < -128 + VOLUME_RANGE_SHIFT ||
ucontrol->value.integer.value[1] > -1 + VOLUME_RANGE_SHIFT)
return -EINVAL;
mutex_lock(&onyx->mutex); mutex_lock(&onyx->mutex);
onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, &l); onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_LEFT, &l);
onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, &r); onyx_read_register(onyx, ONYX_REG_DAC_ATTEN_RIGHT, &r);
@ -206,6 +213,9 @@ static int onyx_snd_inputgain_put(struct snd_kcontrol *kcontrol,
struct onyx *onyx = snd_kcontrol_chip(kcontrol); struct onyx *onyx = snd_kcontrol_chip(kcontrol);
u8 v, n; u8 v, n;
if (ucontrol->value.integer.value[0] < 3 + INPUTGAIN_RANGE_SHIFT ||
ucontrol->value.integer.value[0] > 28 + INPUTGAIN_RANGE_SHIFT)
return -EINVAL;
mutex_lock(&onyx->mutex); mutex_lock(&onyx->mutex);
onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &v); onyx_read_register(onyx, ONYX_REG_ADC_CONTROL, &v);
n = v; n = v;
@ -272,6 +282,8 @@ static void onyx_set_capture_source(struct onyx *onyx, int mic)
static int onyx_snd_capture_source_put(struct snd_kcontrol *kcontrol, static int onyx_snd_capture_source_put(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
if (ucontrol->value.enumerated.item[0] > 1)
return -EINVAL;
onyx_set_capture_source(snd_kcontrol_chip(kcontrol), onyx_set_capture_source(snd_kcontrol_chip(kcontrol),
ucontrol->value.enumerated.item[0]); ucontrol->value.enumerated.item[0]);
return 1; return 1;

View File

@ -248,6 +248,13 @@ static int tas_snd_vol_put(struct snd_kcontrol *kcontrol,
{ {
struct tas *tas = snd_kcontrol_chip(kcontrol); struct tas *tas = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.integer.value[0] < 0 ||
ucontrol->value.integer.value[0] > 177)
return -EINVAL;
if (ucontrol->value.integer.value[1] < 0 ||
ucontrol->value.integer.value[1] > 177)
return -EINVAL;
mutex_lock(&tas->mtx); mutex_lock(&tas->mtx);
if (tas->cached_volume_l == ucontrol->value.integer.value[0] if (tas->cached_volume_l == ucontrol->value.integer.value[0]
&& tas->cached_volume_r == ucontrol->value.integer.value[1]) { && tas->cached_volume_r == ucontrol->value.integer.value[1]) {
@ -401,6 +408,10 @@ static int tas_snd_drc_range_put(struct snd_kcontrol *kcontrol,
{ {
struct tas *tas = snd_kcontrol_chip(kcontrol); struct tas *tas = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.integer.value[0] < 0 ||
ucontrol->value.integer.value[0] > TAS3004_DRC_MAX)
return -EINVAL;
mutex_lock(&tas->mtx); mutex_lock(&tas->mtx);
if (tas->drc_range == ucontrol->value.integer.value[0]) { if (tas->drc_range == ucontrol->value.integer.value[0]) {
mutex_unlock(&tas->mtx); mutex_unlock(&tas->mtx);
@ -447,7 +458,7 @@ static int tas_snd_drc_switch_put(struct snd_kcontrol *kcontrol,
return 0; return 0;
} }
tas->drc_enabled = ucontrol->value.integer.value[0]; tas->drc_enabled = !!ucontrol->value.integer.value[0];
if (tas->hw_enabled) if (tas->hw_enabled)
tas3004_set_drc(tas); tas3004_set_drc(tas);
mutex_unlock(&tas->mtx); mutex_unlock(&tas->mtx);
@ -494,6 +505,8 @@ static int tas_snd_capture_source_put(struct snd_kcontrol *kcontrol,
struct tas *tas = snd_kcontrol_chip(kcontrol); struct tas *tas = snd_kcontrol_chip(kcontrol);
int oldacr; int oldacr;
if (ucontrol->value.enumerated.item[0] > 1)
return -EINVAL;
mutex_lock(&tas->mtx); mutex_lock(&tas->mtx);
oldacr = tas->acr; oldacr = tas->acr;
@ -562,6 +575,9 @@ static int tas_snd_treble_put(struct snd_kcontrol *kcontrol,
{ {
struct tas *tas = snd_kcontrol_chip(kcontrol); struct tas *tas = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.integer.value[0] < TAS3004_TREBLE_MIN ||
ucontrol->value.integer.value[0] > TAS3004_TREBLE_MAX)
return -EINVAL;
mutex_lock(&tas->mtx); mutex_lock(&tas->mtx);
if (tas->treble == ucontrol->value.integer.value[0]) { if (tas->treble == ucontrol->value.integer.value[0]) {
mutex_unlock(&tas->mtx); mutex_unlock(&tas->mtx);
@ -610,6 +626,9 @@ static int tas_snd_bass_put(struct snd_kcontrol *kcontrol,
{ {
struct tas *tas = snd_kcontrol_chip(kcontrol); struct tas *tas = snd_kcontrol_chip(kcontrol);
if (ucontrol->value.integer.value[0] < TAS3004_BASS_MIN ||
ucontrol->value.integer.value[0] > TAS3004_BASS_MAX)
return -EINVAL;
mutex_lock(&tas->mtx); mutex_lock(&tas->mtx);
if (tas->bass == ucontrol->value.integer.value[0]) { if (tas->bass == ucontrol->value.integer.value[0]) {
mutex_unlock(&tas->mtx); mutex_unlock(&tas->mtx);

View File

@ -600,7 +600,7 @@ static int n##_control_put(struct snd_kcontrol *kcontrol, \
struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \ struct gpio_runtime *gpio = snd_kcontrol_chip(kcontrol); \
if (gpio->methods && gpio->methods->get_##n) \ if (gpio->methods && gpio->methods->get_##n) \
gpio->methods->set_##n(gpio, \ gpio->methods->set_##n(gpio, \
ucontrol->value.integer.value[0]); \ !!ucontrol->value.integer.value[0]); \
return 1; \ return 1; \
} \ } \
static struct snd_kcontrol_new n##_ctl = { \ static struct snd_kcontrol_new n##_ctl = { \