diff options
author | Takashi Iwai <tiwai@suse.de> | 2007-11-15 09:58:13 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-01-31 11:29:24 -0500 |
commit | 4e98d6a7ce934b19bffb309f2522b22384355fef (patch) | |
tree | 8613aee414a855314663de2575f2bee284c8430c /sound/pci/pcxhr | |
parent | ab2dac2bdcf562dd616bd1fadddf5078ae7c3d83 (diff) |
[ALSA] pci - check value range in ctl callbacks
Check the value ranges in ctl put callbacks properly in the rest of
PCI drivers.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/pci/pcxhr')
-rw-r--r-- | sound/pci/pcxhr/pcxhr_mixer.c | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/sound/pci/pcxhr/pcxhr_mixer.c b/sound/pci/pcxhr/pcxhr_mixer.c index 5f8d42633b04..4d8654575e18 100644 --- a/sound/pci/pcxhr/pcxhr_mixer.c +++ b/sound/pci/pcxhr/pcxhr_mixer.c | |||
@@ -120,8 +120,18 @@ static int pcxhr_analog_vol_put(struct snd_kcontrol *kcontrol, | |||
120 | is_capture = (kcontrol->private_value != 0); | 120 | is_capture = (kcontrol->private_value != 0); |
121 | for (i = 0; i < 2; i++) { | 121 | for (i = 0; i < 2; i++) { |
122 | int new_volume = ucontrol->value.integer.value[i]; | 122 | int new_volume = ucontrol->value.integer.value[i]; |
123 | int* stored_volume = is_capture ? &chip->analog_capture_volume[i] : | 123 | int *stored_volume = is_capture ? |
124 | &chip->analog_capture_volume[i] : | ||
124 | &chip->analog_playback_volume[i]; | 125 | &chip->analog_playback_volume[i]; |
126 | if (is_capture) { | ||
127 | if (new_volume < PCXHR_ANALOG_CAPTURE_LEVEL_MIN || | ||
128 | new_volume > PCXHR_ANALOG_CAPTURE_LEVEL_MAX) | ||
129 | continue; | ||
130 | } else { | ||
131 | if (new_volume < PCXHR_ANALOG_PLAYBACK_LEVEL_MIN || | ||
132 | new_volume > PCXHR_ANALOG_PLAYBACK_LEVEL_MAX) | ||
133 | continue; | ||
134 | } | ||
125 | if (*stored_volume != new_volume) { | 135 | if (*stored_volume != new_volume) { |
126 | *stored_volume = new_volume; | 136 | *stored_volume = new_volume; |
127 | changed = 1; | 137 | changed = 1; |
@@ -165,10 +175,13 @@ static int pcxhr_audio_sw_put(struct snd_kcontrol *kcontrol, | |||
165 | int i, changed = 0; | 175 | int i, changed = 0; |
166 | mutex_lock(&chip->mgr->mixer_mutex); | 176 | mutex_lock(&chip->mgr->mixer_mutex); |
167 | for(i = 0; i < 2; i++) { | 177 | for(i = 0; i < 2; i++) { |
168 | if (chip->analog_playback_active[i] != ucontrol->value.integer.value[i]) { | 178 | if (chip->analog_playback_active[i] != |
169 | chip->analog_playback_active[i] = ucontrol->value.integer.value[i]; | 179 | ucontrol->value.integer.value[i]) { |
180 | chip->analog_playback_active[i] = | ||
181 | !!ucontrol->value.integer.value[i]; | ||
170 | changed = 1; | 182 | changed = 1; |
171 | pcxhr_update_analog_audio_level(chip, 0, i); /* update playback levels */ | 183 | /* update playback levels */ |
184 | pcxhr_update_analog_audio_level(chip, 0, i); | ||
172 | } | 185 | } |
173 | } | 186 | } |
174 | mutex_unlock(&chip->mgr->mixer_mutex); | 187 | mutex_unlock(&chip->mgr->mixer_mutex); |
@@ -323,20 +336,24 @@ static int pcxhr_pcm_vol_put(struct snd_kcontrol *kcontrol, | |||
323 | int i; | 336 | int i; |
324 | 337 | ||
325 | mutex_lock(&chip->mgr->mixer_mutex); | 338 | mutex_lock(&chip->mgr->mixer_mutex); |
326 | if (is_capture) | 339 | if (is_capture) /* digital capture */ |
327 | stored_volume = chip->digital_capture_volume; /* digital capture */ | 340 | stored_volume = chip->digital_capture_volume; |
328 | else | 341 | else /* digital playback */ |
329 | stored_volume = chip->digital_playback_volume[idx]; /* digital playback */ | 342 | stored_volume = chip->digital_playback_volume[idx]; |
330 | for (i = 0; i < 2; i++) { | 343 | for (i = 0; i < 2; i++) { |
331 | if (stored_volume[i] != ucontrol->value.integer.value[i]) { | 344 | int vol = ucontrol->value.integer.value[i]; |
332 | stored_volume[i] = ucontrol->value.integer.value[i]; | 345 | if (vol < PCXHR_DIGITAL_LEVEL_MIN || |
346 | vol > PCXHR_DIGITAL_LEVEL_MAX) | ||
347 | continue; | ||
348 | if (stored_volume[i] != vol) { | ||
349 | stored_volume[i] = vol; | ||
333 | changed = 1; | 350 | changed = 1; |
334 | if (is_capture) /* update capture volume */ | 351 | if (is_capture) /* update capture volume */ |
335 | pcxhr_update_audio_pipe_level(chip, 1, i); | 352 | pcxhr_update_audio_pipe_level(chip, 1, i); |
336 | } | 353 | } |
337 | } | 354 | } |
338 | if (! is_capture && changed) | 355 | if (!is_capture && changed) /* update playback volume */ |
339 | pcxhr_update_playback_stream_level(chip, idx); /* update playback volume */ | 356 | pcxhr_update_playback_stream_level(chip, idx); |
340 | mutex_unlock(&chip->mgr->mixer_mutex); | 357 | mutex_unlock(&chip->mgr->mixer_mutex); |
341 | return changed; | 358 | return changed; |
342 | } | 359 | } |
@@ -378,8 +395,10 @@ static int pcxhr_pcm_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v | |||
378 | mutex_lock(&chip->mgr->mixer_mutex); | 395 | mutex_lock(&chip->mgr->mixer_mutex); |
379 | j = idx; | 396 | j = idx; |
380 | for (i = 0; i < 2; i++) { | 397 | for (i = 0; i < 2; i++) { |
381 | if (chip->digital_playback_active[j][i] != ucontrol->value.integer.value[i]) { | 398 | if (chip->digital_playback_active[j][i] != |
382 | chip->digital_playback_active[j][i] = ucontrol->value.integer.value[i]; | 399 | ucontrol->value.integer.value[i]) { |
400 | chip->digital_playback_active[j][i] = | ||
401 | !!ucontrol->value.integer.value[i]; | ||
383 | changed = 1; | 402 | changed = 1; |
384 | } | 403 | } |
385 | } | 404 | } |
@@ -423,10 +442,13 @@ static int pcxhr_monitor_vol_put(struct snd_kcontrol *kcontrol, | |||
423 | 442 | ||
424 | mutex_lock(&chip->mgr->mixer_mutex); | 443 | mutex_lock(&chip->mgr->mixer_mutex); |
425 | for (i = 0; i < 2; i++) { | 444 | for (i = 0; i < 2; i++) { |
426 | if (chip->monitoring_volume[i] != ucontrol->value.integer.value[i]) { | 445 | if (chip->monitoring_volume[i] != |
427 | chip->monitoring_volume[i] = ucontrol->value.integer.value[i]; | 446 | ucontrol->value.integer.value[i]) { |
428 | if(chip->monitoring_active[i]) /* do only when monitoring is unmuted */ | 447 | chip->monitoring_volume[i] = |
448 | !!ucontrol->value.integer.value[i]; | ||
449 | if(chip->monitoring_active[i]) | ||
429 | /* update monitoring volume and mute */ | 450 | /* update monitoring volume and mute */ |
451 | /* do only when monitoring is unmuted */ | ||
430 | pcxhr_update_audio_pipe_level(chip, 0, i); | 452 | pcxhr_update_audio_pipe_level(chip, 0, i); |
431 | changed = 1; | 453 | changed = 1; |
432 | } | 454 | } |
@@ -470,15 +492,17 @@ static int pcxhr_monitor_sw_put(struct snd_kcontrol *kcontrol, | |||
470 | 492 | ||
471 | mutex_lock(&chip->mgr->mixer_mutex); | 493 | mutex_lock(&chip->mgr->mixer_mutex); |
472 | for (i = 0; i < 2; i++) { | 494 | for (i = 0; i < 2; i++) { |
473 | if (chip->monitoring_active[i] != ucontrol->value.integer.value[i]) { | 495 | if (chip->monitoring_active[i] != |
474 | chip->monitoring_active[i] = ucontrol->value.integer.value[i]; | 496 | ucontrol->value.integer.value[i]) { |
497 | chip->monitoring_active[i] = | ||
498 | !!ucontrol->value.integer.value[i]; | ||
475 | changed |= (1<<i); /* mask 0x01 and 0x02 */ | 499 | changed |= (1<<i); /* mask 0x01 and 0x02 */ |
476 | } | 500 | } |
477 | } | 501 | } |
478 | if(changed & 0x01) | 502 | if (changed & 0x01) |
479 | /* update left monitoring volume and mute */ | 503 | /* update left monitoring volume and mute */ |
480 | pcxhr_update_audio_pipe_level(chip, 0, 0); | 504 | pcxhr_update_audio_pipe_level(chip, 0, 0); |
481 | if(changed & 0x02) | 505 | if (changed & 0x02) |
482 | /* update right monitoring volume and mute */ | 506 | /* update right monitoring volume and mute */ |
483 | pcxhr_update_audio_pipe_level(chip, 0, 1); | 507 | pcxhr_update_audio_pipe_level(chip, 0, 1); |
484 | 508 | ||
@@ -579,6 +603,8 @@ static int pcxhr_audio_src_put(struct snd_kcontrol *kcontrol, | |||
579 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); | 603 | struct snd_pcxhr *chip = snd_kcontrol_chip(kcontrol); |
580 | int ret = 0; | 604 | int ret = 0; |
581 | 605 | ||
606 | if (ucontrol->value.enumerated.item[0] >= 3) | ||
607 | return -EINVAL; | ||
582 | mutex_lock(&chip->mgr->mixer_mutex); | 608 | mutex_lock(&chip->mgr->mixer_mutex); |
583 | if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) { | 609 | if (chip->audio_capture_source != ucontrol->value.enumerated.item[0]) { |
584 | chip->audio_capture_source = ucontrol->value.enumerated.item[0]; | 610 | chip->audio_capture_source = ucontrol->value.enumerated.item[0]; |
@@ -642,8 +668,11 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol, | |||
642 | struct snd_ctl_elem_value *ucontrol) | 668 | struct snd_ctl_elem_value *ucontrol) |
643 | { | 669 | { |
644 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); | 670 | struct pcxhr_mgr *mgr = snd_kcontrol_chip(kcontrol); |
671 | unsigned int clock_items = 3 + mgr->capture_chips; | ||
645 | int rate, ret = 0; | 672 | int rate, ret = 0; |
646 | 673 | ||
674 | if (ucontrol->value.enumerated.item[0] >= clock_items) | ||
675 | return -EINVAL; | ||
647 | mutex_lock(&mgr->mixer_mutex); | 676 | mutex_lock(&mgr->mixer_mutex); |
648 | if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) { | 677 | if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) { |
649 | mutex_lock(&mgr->setup_mutex); | 678 | mutex_lock(&mgr->setup_mutex); |