diff options
author | Giuliano Pochini <pochini@shiny.it> | 2006-03-13 08:11:11 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@suse.cz> | 2006-03-22 04:37:23 -0500 |
commit | 646494007b48e8897888cd407c2b7d1d69cb2e58 (patch) | |
tree | 02d72d5f844ecb0ce3c25b1b8401ca3b172fa866 /sound | |
parent | 9230d2148a0c53188c216b446cf17ea213ebca8a (diff) |
[ALSA] make control.c suspend aware
Modules: Control Midlevel
This patch prevents user-space apps from accessing the hardware via
control interface while the soundcard is suspended.
Signed-off-by: Giuliano Pochini <pochini@shiny.it>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/core/control.c | 20 | ||||
-rw-r--r-- | sound/core/control_compat.c | 33 |
2 files changed, 42 insertions, 11 deletions
diff --git a/sound/core/control.c b/sound/core/control.c index 0c29679a8576..9742bdba0de1 100644 --- a/sound/core/control.c +++ b/sound/core/control.c | |||
@@ -658,7 +658,11 @@ static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl, | |||
658 | 658 | ||
659 | if (copy_from_user(&info, _info, sizeof(info))) | 659 | if (copy_from_user(&info, _info, sizeof(info))) |
660 | return -EFAULT; | 660 | return -EFAULT; |
661 | result = snd_ctl_elem_info(ctl, &info); | 661 | snd_power_lock(ctl->card); |
662 | result = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0, NULL); | ||
663 | if (result >= 0) | ||
664 | result = snd_ctl_elem_info(ctl, &info); | ||
665 | snd_power_unlock(ctl->card); | ||
662 | if (result >= 0) | 666 | if (result >= 0) |
663 | if (copy_to_user(_info, &info, sizeof(info))) | 667 | if (copy_to_user(_info, &info, sizeof(info))) |
664 | return -EFAULT; | 668 | return -EFAULT; |
@@ -708,7 +712,11 @@ static int snd_ctl_elem_read_user(struct snd_card *card, | |||
708 | kfree(control); | 712 | kfree(control); |
709 | return -EFAULT; | 713 | return -EFAULT; |
710 | } | 714 | } |
711 | result = snd_ctl_elem_read(card, control); | 715 | snd_power_lock(card); |
716 | result = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); | ||
717 | if (result >= 0) | ||
718 | result = snd_ctl_elem_read(card, control); | ||
719 | snd_power_unlock(card); | ||
712 | if (result >= 0) | 720 | if (result >= 0) |
713 | if (copy_to_user(_control, control, sizeof(*control))) | 721 | if (copy_to_user(_control, control, sizeof(*control))) |
714 | result = -EFAULT; | 722 | result = -EFAULT; |
@@ -758,6 +766,7 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file, | |||
758 | struct snd_ctl_elem_value __user *_control) | 766 | struct snd_ctl_elem_value __user *_control) |
759 | { | 767 | { |
760 | struct snd_ctl_elem_value *control; | 768 | struct snd_ctl_elem_value *control; |
769 | struct snd_card *card; | ||
761 | int result; | 770 | int result; |
762 | 771 | ||
763 | control = kmalloc(sizeof(*control), GFP_KERNEL); | 772 | control = kmalloc(sizeof(*control), GFP_KERNEL); |
@@ -767,7 +776,12 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file, | |||
767 | kfree(control); | 776 | kfree(control); |
768 | return -EFAULT; | 777 | return -EFAULT; |
769 | } | 778 | } |
770 | result = snd_ctl_elem_write(file->card, file, control); | 779 | card = file->card; |
780 | snd_power_lock(card); | ||
781 | result = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); | ||
782 | if (result >= 0) | ||
783 | result = snd_ctl_elem_write(card, file, control); | ||
784 | snd_power_unlock(card); | ||
771 | if (result >= 0) | 785 | if (result >= 0) |
772 | if (copy_to_user(_control, control, sizeof(*control))) | 786 | if (copy_to_user(_control, control, sizeof(*control))) |
773 | result = -EFAULT; | 787 | result = -EFAULT; |
diff --git a/sound/core/control_compat.c b/sound/core/control_compat.c index a529b62972b4..84fef5084e17 100644 --- a/sound/core/control_compat.c +++ b/sound/core/control_compat.c | |||
@@ -107,7 +107,13 @@ static int snd_ctl_elem_info_compat(struct snd_ctl_file *ctl, | |||
107 | */ | 107 | */ |
108 | if (get_user(data->value.enumerated.item, &data32->value.enumerated.item)) | 108 | if (get_user(data->value.enumerated.item, &data32->value.enumerated.item)) |
109 | goto error; | 109 | goto error; |
110 | err = snd_ctl_elem_info(ctl, data); | 110 | |
111 | snd_power_lock(ctl->card); | ||
112 | err = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0, NULL); | ||
113 | if (err >= 0) | ||
114 | err = snd_ctl_elem_info(ctl, data); | ||
115 | snd_power_unlock(ctl->card); | ||
116 | |||
111 | if (err < 0) | 117 | if (err < 0) |
112 | goto error; | 118 | goto error; |
113 | /* restore info to 32bit */ | 119 | /* restore info to 32bit */ |
@@ -286,9 +292,14 @@ static int snd_ctl_elem_read_user_compat(struct snd_card *card, | |||
286 | 292 | ||
287 | if ((err = copy_ctl_value_from_user(card, data, data32, &type, &count)) < 0) | 293 | if ((err = copy_ctl_value_from_user(card, data, data32, &type, &count)) < 0) |
288 | goto error; | 294 | goto error; |
289 | if ((err = snd_ctl_elem_read(card, data)) < 0) | 295 | |
290 | goto error; | 296 | snd_power_lock(card); |
291 | err = copy_ctl_value_to_user(data32, data, type, count); | 297 | err = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); |
298 | if (err >= 0) | ||
299 | err = snd_ctl_elem_read(card, data); | ||
300 | snd_power_unlock(card); | ||
301 | if (err >= 0) | ||
302 | err = copy_ctl_value_to_user(data32, data, type, count); | ||
292 | error: | 303 | error: |
293 | kfree(data); | 304 | kfree(data); |
294 | return err; | 305 | return err; |
@@ -298,17 +309,23 @@ static int snd_ctl_elem_write_user_compat(struct snd_ctl_file *file, | |||
298 | struct snd_ctl_elem_value32 __user *data32) | 309 | struct snd_ctl_elem_value32 __user *data32) |
299 | { | 310 | { |
300 | struct snd_ctl_elem_value *data; | 311 | struct snd_ctl_elem_value *data; |
312 | struct snd_card *card = file->card; | ||
301 | int err, type, count; | 313 | int err, type, count; |
302 | 314 | ||
303 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 315 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
304 | if (data == NULL) | 316 | if (data == NULL) |
305 | return -ENOMEM; | 317 | return -ENOMEM; |
306 | 318 | ||
307 | if ((err = copy_ctl_value_from_user(file->card, data, data32, &type, &count)) < 0) | 319 | if ((err = copy_ctl_value_from_user(card, data, data32, &type, &count)) < 0) |
308 | goto error; | ||
309 | if ((err = snd_ctl_elem_write(file->card, file, data)) < 0) | ||
310 | goto error; | 320 | goto error; |
311 | err = copy_ctl_value_to_user(data32, data, type, count); | 321 | |
322 | snd_power_lock(card); | ||
323 | err = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); | ||
324 | if (err >= 0) | ||
325 | err = snd_ctl_elem_write(card, file, data); | ||
326 | snd_power_unlock(card); | ||
327 | if (err >= 0) | ||
328 | err = copy_ctl_value_to_user(data32, data, type, count); | ||
312 | error: | 329 | error: |
313 | kfree(data); | 330 | kfree(data); |
314 | return err; | 331 | return err; |