diff options
author | Takashi Iwai <tiwai@suse.de> | 2007-11-15 10:13:32 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-01-31 11:29:25 -0500 |
commit | d05ab185b770de96399766be6bcb5769ab99bc09 (patch) | |
tree | 4dbcebd67139f890aa5568ba06efbecf4fd40454 /sound/drivers/vx | |
parent | 9c45ba100501c206658f356ea1db3263947b9a30 (diff) |
[ALSA] vxpocket - Check value range in ctl callbacks
Check the value ranges in ctl put callbacks in vxpocket driver.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/drivers/vx')
-rw-r--r-- | sound/drivers/vx/vx_mixer.c | 67 |
1 files changed, 48 insertions, 19 deletions
diff --git a/sound/drivers/vx/vx_mixer.c b/sound/drivers/vx/vx_mixer.c index b8fcd79a7e11..a37f0a8f17af 100644 --- a/sound/drivers/vx/vx_mixer.c +++ b/sound/drivers/vx/vx_mixer.c | |||
@@ -439,14 +439,19 @@ static int vx_output_level_put(struct snd_kcontrol *kcontrol, struct snd_ctl_ele | |||
439 | { | 439 | { |
440 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); | 440 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
441 | int codec = kcontrol->id.index; | 441 | int codec = kcontrol->id.index; |
442 | unsigned int val[2], vmax; | ||
443 | |||
444 | vmax = chip->hw->output_level_max; | ||
445 | val[0] = ucontrol->value.integer.value[0]; | ||
446 | val[1] = ucontrol->value.integer.value[1]; | ||
447 | if (val[0] > vmax || val[1] > vmax) | ||
448 | return -EINVAL; | ||
442 | mutex_lock(&chip->mixer_mutex); | 449 | mutex_lock(&chip->mixer_mutex); |
443 | if (ucontrol->value.integer.value[0] != chip->output_level[codec][0] || | 450 | if (val[0] != chip->output_level[codec][0] || |
444 | ucontrol->value.integer.value[1] != chip->output_level[codec][1]) { | 451 | val[1] != chip->output_level[codec][1]) { |
445 | vx_set_analog_output_level(chip, codec, | 452 | vx_set_analog_output_level(chip, codec, val[0], val[1]); |
446 | ucontrol->value.integer.value[0], | 453 | chip->output_level[codec][0] = val[0]; |
447 | ucontrol->value.integer.value[1]); | 454 | chip->output_level[codec][1] = val[1]; |
448 | chip->output_level[codec][0] = ucontrol->value.integer.value[0]; | ||
449 | chip->output_level[codec][1] = ucontrol->value.integer.value[1]; | ||
450 | mutex_unlock(&chip->mixer_mutex); | 455 | mutex_unlock(&chip->mixer_mutex); |
451 | return 1; | 456 | return 1; |
452 | } | 457 | } |
@@ -506,6 +511,14 @@ static int vx_audio_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v | |||
506 | static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 511 | static int vx_audio_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
507 | { | 512 | { |
508 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); | 513 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
514 | |||
515 | if (chip->type >= VX_TYPE_VXPOCKET) { | ||
516 | if (ucontrol->value.enumerated.item[0] > 2) | ||
517 | return -EINVAL; | ||
518 | } else { | ||
519 | if (ucontrol->value.enumerated.item[0] > 1) | ||
520 | return -EINVAL; | ||
521 | } | ||
509 | mutex_lock(&chip->mixer_mutex); | 522 | mutex_lock(&chip->mixer_mutex); |
510 | if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { | 523 | if (chip->audio_source_target != ucontrol->value.enumerated.item[0]) { |
511 | chip->audio_source_target = ucontrol->value.enumerated.item[0]; | 524 | chip->audio_source_target = ucontrol->value.enumerated.item[0]; |
@@ -554,6 +567,9 @@ static int vx_clock_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ | |||
554 | static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 567 | static int vx_clock_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
555 | { | 568 | { |
556 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); | 569 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
570 | |||
571 | if (ucontrol->value.enumerated.item[0] > 2) | ||
572 | return -EINVAL; | ||
557 | mutex_lock(&chip->mixer_mutex); | 573 | mutex_lock(&chip->mixer_mutex); |
558 | if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { | 574 | if (chip->clock_mode != ucontrol->value.enumerated.item[0]) { |
559 | chip->clock_mode = ucontrol->value.enumerated.item[0]; | 575 | chip->clock_mode = ucontrol->value.enumerated.item[0]; |
@@ -603,12 +619,17 @@ static int vx_audio_gain_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ | |||
603 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); | 619 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
604 | int audio = kcontrol->private_value & 0xff; | 620 | int audio = kcontrol->private_value & 0xff; |
605 | int capture = (kcontrol->private_value >> 8) & 1; | 621 | int capture = (kcontrol->private_value >> 8) & 1; |
622 | unsigned int val[2]; | ||
606 | 623 | ||
624 | val[0] = ucontrol->value.integer.value[0]; | ||
625 | val[1] = ucontrol->value.integer.value[1]; | ||
626 | if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) | ||
627 | return -EINVAL; | ||
607 | mutex_lock(&chip->mixer_mutex); | 628 | mutex_lock(&chip->mixer_mutex); |
608 | if (ucontrol->value.integer.value[0] != chip->audio_gain[capture][audio] || | 629 | if (val[0] != chip->audio_gain[capture][audio] || |
609 | ucontrol->value.integer.value[1] != chip->audio_gain[capture][audio+1]) { | 630 | val[1] != chip->audio_gain[capture][audio+1]) { |
610 | vx_set_audio_gain(chip, audio, capture, ucontrol->value.integer.value[0]); | 631 | vx_set_audio_gain(chip, audio, capture, val[0]); |
611 | vx_set_audio_gain(chip, audio+1, capture, ucontrol->value.integer.value[1]); | 632 | vx_set_audio_gain(chip, audio+1, capture, val[1]); |
612 | mutex_unlock(&chip->mixer_mutex); | 633 | mutex_unlock(&chip->mixer_mutex); |
613 | return 1; | 634 | return 1; |
614 | } | 635 | } |
@@ -632,13 +653,19 @@ static int vx_audio_monitor_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el | |||
632 | { | 653 | { |
633 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); | 654 | struct vx_core *chip = snd_kcontrol_chip(kcontrol); |
634 | int audio = kcontrol->private_value & 0xff; | 655 | int audio = kcontrol->private_value & 0xff; |
656 | unsigned int val[2]; | ||
657 | |||
658 | val[0] = ucontrol->value.integer.value[0]; | ||
659 | val[1] = ucontrol->value.integer.value[1]; | ||
660 | if (val[0] > CVAL_MAX || val[1] > CVAL_MAX) | ||
661 | return -EINVAL; | ||
635 | 662 | ||
636 | mutex_lock(&chip->mixer_mutex); | 663 | mutex_lock(&chip->mixer_mutex); |
637 | if (ucontrol->value.integer.value[0] != chip->audio_monitor[audio] || | 664 | if (val[0] != chip->audio_monitor[audio] || |
638 | ucontrol->value.integer.value[1] != chip->audio_monitor[audio+1]) { | 665 | val[1] != chip->audio_monitor[audio+1]) { |
639 | vx_set_monitor_level(chip, audio, ucontrol->value.integer.value[0], | 666 | vx_set_monitor_level(chip, audio, val[0], |
640 | chip->audio_monitor_active[audio]); | 667 | chip->audio_monitor_active[audio]); |
641 | vx_set_monitor_level(chip, audio+1, ucontrol->value.integer.value[1], | 668 | vx_set_monitor_level(chip, audio+1, val[1], |
642 | chip->audio_monitor_active[audio+1]); | 669 | chip->audio_monitor_active[audio+1]); |
643 | mutex_unlock(&chip->mixer_mutex); | 670 | mutex_unlock(&chip->mixer_mutex); |
644 | return 1; | 671 | return 1; |
@@ -669,8 +696,10 @@ static int vx_audio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_va | |||
669 | mutex_lock(&chip->mixer_mutex); | 696 | mutex_lock(&chip->mixer_mutex); |
670 | if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || | 697 | if (ucontrol->value.integer.value[0] != chip->audio_active[audio] || |
671 | ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { | 698 | ucontrol->value.integer.value[1] != chip->audio_active[audio+1]) { |
672 | vx_set_audio_switch(chip, audio, ucontrol->value.integer.value[0]); | 699 | vx_set_audio_switch(chip, audio, |
673 | vx_set_audio_switch(chip, audio+1, ucontrol->value.integer.value[1]); | 700 | !!ucontrol->value.integer.value[0]); |
701 | vx_set_audio_switch(chip, audio+1, | ||
702 | !!ucontrol->value.integer.value[1]); | ||
674 | mutex_unlock(&chip->mixer_mutex); | 703 | mutex_unlock(&chip->mixer_mutex); |
675 | return 1; | 704 | return 1; |
676 | } | 705 | } |
@@ -699,9 +728,9 @@ static int vx_monitor_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_ | |||
699 | if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || | 728 | if (ucontrol->value.integer.value[0] != chip->audio_monitor_active[audio] || |
700 | ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { | 729 | ucontrol->value.integer.value[1] != chip->audio_monitor_active[audio+1]) { |
701 | vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], | 730 | vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], |
702 | ucontrol->value.integer.value[0]); | 731 | !!ucontrol->value.integer.value[0]); |
703 | vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], | 732 | vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], |
704 | ucontrol->value.integer.value[1]); | 733 | !!ucontrol->value.integer.value[1]); |
705 | mutex_unlock(&chip->mixer_mutex); | 734 | mutex_unlock(&chip->mixer_mutex); |
706 | return 1; | 735 | return 1; |
707 | } | 736 | } |