From: Giuliano Pochini Subject: [RFC] alsa-kernel, make control.c suspend aware Date: Thu, 2 Mar 2006 00:18:59 +0100 Message-ID: <20060302001859.58bd93af.pochini@shiny.it> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Alsa-devel List-Id: alsa-devel@alsa-project.org First attempt to add code that prevents someone to access the hardware via control interface when the card is suspended. I put the code in snd_ctl_elem_read_user() instead of snd_ctl_elem_read() because /pci/hda/hda_codec.c:snd_hda_resume_ctls() calls the latter from the resume callback. I had no time to check other things, consider it mostly untested. diff -dup alsa-kernel__orig/core/control.c alsa-kernel/core/control.c --- alsa-kernel__orig/core/control.c 2005-11-26 13:14:54.000000000 +0100 +++ alsa-kernel/core/control.c 2006-03-02 00:11:55.000000000 +0100 @@ -672,6 +672,7 @@ int snd_ctl_elem_read(struct snd_card *c unsigned int index_offset; int result, indirect; +snd_printk("snd_ctl_elem_read\n"); down_read(&card->controls_rwsem); kctl = snd_ctl_find_id(card, &control->id); if (kctl == NULL) { @@ -708,7 +709,13 @@ static int snd_ctl_elem_read_user(struct kfree(control); return -EFAULT; } - result = snd_ctl_elem_read(card, control); +snd_printk("snd_ctl_elem_read_user1\n"); + snd_power_lock(card); + result = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); + if (result >= 0) + result = snd_ctl_elem_read(card, control); + snd_power_unlock(card); +snd_printk("snd_ctl_elem_read_user2\n"); if (result >= 0) if (copy_to_user(_control, control, sizeof(*control))) result = -EFAULT; @@ -723,6 +730,7 @@ int snd_ctl_elem_write(struct snd_card * struct snd_kcontrol_volatile *vd; unsigned int index_offset; int result, indirect; +snd_printk("snd_ctl_elem_write\n"); down_read(&card->controls_rwsem); kctl = snd_ctl_find_id(card, &control->id); @@ -758,6 +766,7 @@ static int snd_ctl_elem_write_user(struc struct snd_ctl_elem_value __user *_control) { struct snd_ctl_elem_value *control; + struct snd_card *card; int result; control = kmalloc(sizeof(*control), GFP_KERNEL); @@ -767,7 +776,14 @@ static int snd_ctl_elem_write_user(struc kfree(control); return -EFAULT; } - result = snd_ctl_elem_write(file->card, file, control); + card = file->card; +snd_printk("snd_ctl_elem_write_user1\n"); + snd_power_lock(card); + result = snd_power_wait(card, SNDRV_CTL_POWER_D0, NULL); + if (result >= 0) + result = snd_ctl_elem_write(card, file, control); + snd_power_unlock(card); +snd_printk("snd_ctl_elem_write_user2\n"); if (result >= 0) if (copy_to_user(_control, control, sizeof(*control))) result = -EFAULT; -- Giuliano. ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642