aboutsummaryrefslogtreecommitdiffstats
path: root/sound/ppc/tumbler.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2007-11-15 10:14:12 -0500
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:29:25 -0500
commitd4079ac49a08e36d6839a9ceb26aec8c24c9ed82 (patch)
tree91ebc493375fd4e7fa84c3a6ab67a885121b1c81 /sound/ppc/tumbler.c
parentd05ab185b770de96399766be6bcb5769ab99bc09 (diff)
[ALSA] powermac - Check value range in ctl callbacks
Check the value ranges in ctl put callbacks properly in snd-powermac driver. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/ppc/tumbler.c')
-rw-r--r--sound/ppc/tumbler.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index 5821cdd0bec9..bacff3d1c189 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -275,14 +275,20 @@ static int tumbler_put_master_volume(struct snd_kcontrol *kcontrol,
275{ 275{
276 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 276 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
277 struct pmac_tumbler *mix = chip->mixer_data; 277 struct pmac_tumbler *mix = chip->mixer_data;
278 unsigned int vol[2];
278 int change; 279 int change;
279 280
280 snd_assert(mix, return -ENODEV); 281 snd_assert(mix, return -ENODEV);
281 change = mix->master_vol[0] != ucontrol->value.integer.value[0] || 282 vol[0] = ucontrol->value.integer.value[0];
282 mix->master_vol[1] != ucontrol->value.integer.value[1]; 283 vol[1] = ucontrol->value.integer.value[1];
284 if (vol[0] >= ARRAY_SIZE(master_volume_table) ||
285 vol[1] >= ARRAY_SIZE(master_volume_table))
286 return -EINVAL;
287 change = mix->master_vol[0] != vol[0] ||
288 mix->master_vol[1] != vol[1];
283 if (change) { 289 if (change) {
284 mix->master_vol[0] = ucontrol->value.integer.value[0]; 290 mix->master_vol[0] = vol[0];
285 mix->master_vol[1] = ucontrol->value.integer.value[1]; 291 mix->master_vol[1] = vol[1];
286 tumbler_set_master_volume(mix); 292 tumbler_set_master_volume(mix);
287 } 293 }
288 return change; 294 return change;
@@ -417,13 +423,22 @@ static int tumbler_put_drc_value(struct snd_kcontrol *kcontrol,
417{ 423{
418 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 424 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
419 struct pmac_tumbler *mix; 425 struct pmac_tumbler *mix;
426 unsigned int val;
420 int change; 427 int change;
421 428
422 if (! (mix = chip->mixer_data)) 429 if (! (mix = chip->mixer_data))
423 return -ENODEV; 430 return -ENODEV;
424 change = mix->drc_range != ucontrol->value.integer.value[0]; 431 val = ucontrol->value.integer.value[0];
432 if (chip->model == PMAC_TUMBLER) {
433 if (val > TAS3001_DRC_MAX)
434 return -EINVAL;
435 } else {
436 if (val > TAS3004_DRC_MAX)
437 return -EINVAL;
438 }
439 change = mix->drc_range != val;
425 if (change) { 440 if (change) {
426 mix->drc_range = ucontrol->value.integer.value[0]; 441 mix->drc_range = val;
427 if (chip->model == PMAC_TUMBLER) 442 if (chip->model == PMAC_TUMBLER)
428 tumbler_set_drc(mix); 443 tumbler_set_drc(mix);
429 else 444 else
@@ -530,13 +545,17 @@ static int tumbler_put_mono(struct snd_kcontrol *kcontrol,
530 struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value; 545 struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
531 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 546 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
532 struct pmac_tumbler *mix; 547 struct pmac_tumbler *mix;
548 unsigned int vol;
533 int change; 549 int change;
534 550
535 if (! (mix = chip->mixer_data)) 551 if (! (mix = chip->mixer_data))
536 return -ENODEV; 552 return -ENODEV;
537 change = mix->mono_vol[info->index] != ucontrol->value.integer.value[0]; 553 vol = ucontrol->value.integer.value[0];
554 if (vol >= info->max)
555 return -EINVAL;
556 change = mix->mono_vol[info->index] != vol;
538 if (change) { 557 if (change) {
539 mix->mono_vol[info->index] = ucontrol->value.integer.value[0]; 558 mix->mono_vol[info->index] = vol;
540 tumbler_set_mono_volume(mix, info); 559 tumbler_set_mono_volume(mix, info);
541 } 560 }
542 return change; 561 return change;
@@ -672,15 +691,21 @@ static int snapper_put_mix(struct snd_kcontrol *kcontrol,
672 int idx = (int)kcontrol->private_value; 691 int idx = (int)kcontrol->private_value;
673 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 692 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
674 struct pmac_tumbler *mix; 693 struct pmac_tumbler *mix;
694 unsigned int vol[2];
675 int change; 695 int change;
676 696
677 if (! (mix = chip->mixer_data)) 697 if (! (mix = chip->mixer_data))
678 return -ENODEV; 698 return -ENODEV;
679 change = mix->mix_vol[idx][0] != ucontrol->value.integer.value[0] || 699 vol[0] = ucontrol->value.integer.value[0];
680 mix->mix_vol[idx][1] != ucontrol->value.integer.value[1]; 700 vol[1] = ucontrol->value.integer.value[1];
701 if (vol[0] >= ARRAY_SIZE(mixer_volume_table) ||
702 vol[1] >= ARRAY_SIZE(mixer_volume_table))
703 return -EINVAL;
704 change = mix->mix_vol[idx][0] != vol[0] ||
705 mix->mix_vol[idx][1] != vol[1];
681 if (change) { 706 if (change) {
682 mix->mix_vol[idx][0] = ucontrol->value.integer.value[0]; 707 mix->mix_vol[idx][0] = vol[0];
683 mix->mix_vol[idx][1] = ucontrol->value.integer.value[1]; 708 mix->mix_vol[idx][1] = vol[1];
684 snapper_set_mix_vol(mix, idx); 709 snapper_set_mix_vol(mix, idx);
685 } 710 }
686 return change; 711 return change;
@@ -784,7 +809,7 @@ static int snapper_get_capture_source(struct snd_kcontrol *kcontrol,
784 struct pmac_tumbler *mix = chip->mixer_data; 809 struct pmac_tumbler *mix = chip->mixer_data;
785 810
786 snd_assert(mix, return -ENODEV); 811 snd_assert(mix, return -ENODEV);
787 ucontrol->value.integer.value[0] = mix->capture_source; 812 ucontrol->value.enumerated.value[0] = mix->capture_source;
788 return 0; 813 return 0;
789} 814}
790 815
@@ -796,9 +821,9 @@ static int snapper_put_capture_source(struct snd_kcontrol *kcontrol,
796 int change; 821 int change;
797 822
798 snd_assert(mix, return -ENODEV); 823 snd_assert(mix, return -ENODEV);
799 change = ucontrol->value.integer.value[0] != mix->capture_source; 824 change = ucontrol->value.enuemerated.item[0] != mix->capture_source;
800 if (change) { 825 if (change) {
801 mix->capture_source = !!ucontrol->value.integer.value[0]; 826 mix->capture_source = !!ucontrol->value.enumerated.item[0];
802 snapper_set_capture_source(mix); 827 snapper_set_capture_source(mix);
803 } 828 }
804 return change; 829 return change;