Skip to content

Commit 7d8e829

Browse files
committed
ALSA: Get rid of card power_lock
Currently we're taking power_lock at each card component for assuring the power-up sequence, but it doesn't help anything in the implementation at the moment: it just serializes unnecessarily the callers, but it doesn't protect about the power state change itself. It used to have some usefulness in the early days where we managed the PM manually. But now the suspend/resume core procedure is beyond our hands, and power_lock lost its meaning. This patch drops the power_lock from allover the places. There shouldn't be any issues by this change, as it's no helper regarding the power state change. Rather we'll get better performance by removing the serialization; which is the only slight concern of any behavior change, but it can't be a showstopper, after all. Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 3454a47 commit 7d8e829

6 files changed

Lines changed: 53 additions & 89 deletions

File tree

‎include/sound/core.h‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ struct snd_card {
136136

137137
#ifdef CONFIG_PM
138138
unsigned int power_state; /* power state */
139-
struct mutex power_lock; /* power lock */
140139
wait_queue_head_t power_sleep;
141140
#endif
142141

@@ -149,16 +148,6 @@ struct snd_card {
149148
#define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev)
150149

151150
#ifdef CONFIG_PM
152-
static inline void snd_power_lock(struct snd_card *card)
153-
{
154-
mutex_lock(&card->power_lock);
155-
}
156-
157-
static inline void snd_power_unlock(struct snd_card *card)
158-
{
159-
mutex_unlock(&card->power_lock);
160-
}
161-
162151
static inline unsigned int snd_power_get_state(struct snd_card *card)
163152
{
164153
return card->power_state;
@@ -175,8 +164,6 @@ int snd_power_wait(struct snd_card *card, unsigned int power_state);
175164

176165
#else /* ! CONFIG_PM */
177166

178-
#define snd_power_lock(card) do { (void)(card); } while (0)
179-
#define snd_power_unlock(card) do { (void)(card); } while (0)
180167
static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
181168
#define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; })
182169
#define snd_power_change_state(card, state) do { (void)(card); } while (0)

‎sound/core/control.c‎

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -864,14 +864,14 @@ static int snd_ctl_elem_info_user(struct snd_ctl_file *ctl,
864864

865865
if (copy_from_user(&info, _info, sizeof(info)))
866866
return -EFAULT;
867-
snd_power_lock(ctl->card);
868867
result = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0);
869-
if (result >= 0)
870-
result = snd_ctl_elem_info(ctl, &info);
871-
snd_power_unlock(ctl->card);
872-
if (result >= 0)
873-
if (copy_to_user(_info, &info, sizeof(info)))
874-
return -EFAULT;
868+
if (result < 0)
869+
return result;
870+
result = snd_ctl_elem_info(ctl, &info);
871+
if (result < 0)
872+
return result;
873+
if (copy_to_user(_info, &info, sizeof(info)))
874+
return -EFAULT;
875875
return result;
876876
}
877877

@@ -905,17 +905,19 @@ static int snd_ctl_elem_read_user(struct snd_card *card,
905905
if (IS_ERR(control))
906906
return PTR_ERR(control);
907907

908-
snd_power_lock(card);
909908
result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
910-
if (result >= 0) {
911-
down_read(&card->controls_rwsem);
912-
result = snd_ctl_elem_read(card, control);
913-
up_read(&card->controls_rwsem);
914-
}
915-
snd_power_unlock(card);
916-
if (result >= 0)
917-
if (copy_to_user(_control, control, sizeof(*control)))
918-
result = -EFAULT;
909+
if (result < 0)
910+
goto error;
911+
912+
down_read(&card->controls_rwsem);
913+
result = snd_ctl_elem_read(card, control);
914+
up_read(&card->controls_rwsem);
915+
if (result < 0)
916+
goto error;
917+
918+
if (copy_to_user(_control, control, sizeof(*control)))
919+
result = -EFAULT;
920+
error:
919921
kfree(control);
920922
return result;
921923
}
@@ -964,17 +966,19 @@ static int snd_ctl_elem_write_user(struct snd_ctl_file *file,
964966
return PTR_ERR(control);
965967

966968
card = file->card;
967-
snd_power_lock(card);
968969
result = snd_power_wait(card, SNDRV_CTL_POWER_D0);
969-
if (result >= 0) {
970-
down_write(&card->controls_rwsem);
971-
result = snd_ctl_elem_write(card, file, control);
972-
up_write(&card->controls_rwsem);
973-
}
974-
snd_power_unlock(card);
975-
if (result >= 0)
976-
if (copy_to_user(_control, control, sizeof(*control)))
977-
result = -EFAULT;
970+
if (result < 0)
971+
goto error;
972+
973+
down_write(&card->controls_rwsem);
974+
result = snd_ctl_elem_write(card, file, control);
975+
up_write(&card->controls_rwsem);
976+
if (result < 0)
977+
goto error;
978+
979+
if (copy_to_user(_control, control, sizeof(*control)))
980+
result = -EFAULT;
981+
error:
978982
kfree(control);
979983
return result;
980984
}

‎sound/core/control_compat.c‎

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ static int snd_ctl_elem_info_compat(struct snd_ctl_file *ctl,
111111
if (get_user(data->value.enumerated.item, &data32->value.enumerated.item))
112112
goto error;
113113

114-
snd_power_lock(ctl->card);
115114
err = snd_power_wait(ctl->card, SNDRV_CTL_POWER_D0);
116-
if (err >= 0)
117-
err = snd_ctl_elem_info(ctl, data);
118-
snd_power_unlock(ctl->card);
119-
115+
if (err < 0)
116+
goto error;
117+
err = snd_ctl_elem_info(ctl, data);
120118
if (err < 0)
121119
goto error;
122120
/* restore info to 32bit */
@@ -315,14 +313,13 @@ static int ctl_elem_read_user(struct snd_card *card,
315313
if (err < 0)
316314
goto error;
317315

318-
snd_power_lock(card);
319316
err = snd_power_wait(card, SNDRV_CTL_POWER_D0);
320-
if (err >= 0)
321-
err = snd_ctl_elem_read(card, data);
322-
snd_power_unlock(card);
323-
if (err >= 0)
324-
err = copy_ctl_value_to_user(userdata, valuep, data,
325-
type, count);
317+
if (err < 0)
318+
goto error;
319+
err = snd_ctl_elem_read(card, data);
320+
if (err < 0)
321+
goto error;
322+
err = copy_ctl_value_to_user(userdata, valuep, data, type, count);
326323
error:
327324
kfree(data);
328325
return err;
@@ -344,14 +341,13 @@ static int ctl_elem_write_user(struct snd_ctl_file *file,
344341
if (err < 0)
345342
goto error;
346343

347-
snd_power_lock(card);
348344
err = snd_power_wait(card, SNDRV_CTL_POWER_D0);
349-
if (err >= 0)
350-
err = snd_ctl_elem_write(card, file, data);
351-
snd_power_unlock(card);
352-
if (err >= 0)
353-
err = copy_ctl_value_to_user(userdata, valuep, data,
354-
type, count);
345+
if (err < 0)
346+
goto error;
347+
err = snd_ctl_elem_write(card, file, data);
348+
if (err < 0)
349+
goto error;
350+
err = copy_ctl_value_to_user(userdata, valuep, data, type, count);
355351
error:
356352
kfree(data);
357353
return err;

‎sound/core/init.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ int snd_card_new(struct device *parent, int idx, const char *xid,
253253
spin_lock_init(&card->files_lock);
254254
INIT_LIST_HEAD(&card->files_list);
255255
#ifdef CONFIG_PM
256-
mutex_init(&card->power_lock);
257256
init_waitqueue_head(&card->power_sleep);
258257
#endif
259258

@@ -978,8 +977,6 @@ EXPORT_SYMBOL(snd_card_file_remove);
978977
* Waits until the power-state is changed.
979978
*
980979
* Return: Zero if successful, or a negative error code.
981-
*
982-
* Note: the power lock must be active before call.
983980
*/
984981
int snd_power_wait(struct snd_card *card, unsigned int power_state)
985982
{
@@ -999,9 +996,7 @@ int snd_power_wait(struct snd_card *card, unsigned int power_state)
999996
if (snd_power_get_state(card) == power_state)
1000997
break;
1001998
set_current_state(TASK_UNINTERRUPTIBLE);
1002-
snd_power_unlock(card);
1003999
schedule_timeout(30 * HZ);
1004-
snd_power_lock(card);
10051000
}
10061001
remove_wait_queue(&card->power_sleep, &wait);
10071002
return result;

‎sound/core/pcm_native.c‎

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,6 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
18301830
add_wait_queue(&to_check->sleep, &wait);
18311831
snd_pcm_stream_unlock_irq(substream);
18321832
up_read(&snd_pcm_link_rwsem);
1833-
snd_power_unlock(card);
18341833
if (runtime->no_period_wakeup)
18351834
tout = MAX_SCHEDULE_TIMEOUT;
18361835
else {
@@ -1842,7 +1841,6 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
18421841
tout = msecs_to_jiffies(tout * 1000);
18431842
}
18441843
tout = schedule_timeout_interruptible(tout);
1845-
snd_power_lock(card);
18461844
down_read(&snd_pcm_link_rwsem);
18471845
snd_pcm_stream_lock_irq(substream);
18481846
remove_wait_queue(&to_check->sleep, &wait);
@@ -2764,11 +2762,16 @@ static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg)
27642762
return 0;
27652763
}
27662764

2767-
static int snd_pcm_common_ioctl(struct file *file,
2765+
static int snd_pcm_common_ioctl1(struct file *file,
27682766
struct snd_pcm_substream *substream,
27692767
unsigned int cmd, void __user *arg)
27702768
{
27712769
struct snd_pcm_file *pcm_file = file->private_data;
2770+
int res;
2771+
2772+
res = snd_power_wait(substream->pcm->card, SNDRV_CTL_POWER_D0);
2773+
if (res < 0)
2774+
return res;
27722775

27732776
switch (cmd) {
27742777
case SNDRV_PCM_IOCTL_PVERSION:
@@ -2846,21 +2849,6 @@ static int snd_pcm_common_ioctl(struct file *file,
28462849
return -ENOTTY;
28472850
}
28482851

2849-
static int snd_pcm_common_ioctl1(struct file *file,
2850-
struct snd_pcm_substream *substream,
2851-
unsigned int cmd, void __user *arg)
2852-
{
2853-
struct snd_card *card = substream->pcm->card;
2854-
int res;
2855-
2856-
snd_power_lock(card);
2857-
res = snd_power_wait(card, SNDRV_CTL_POWER_D0);
2858-
if (res >= 0)
2859-
res = snd_pcm_common_ioctl(file, substream, cmd, arg);
2860-
snd_power_unlock(card);
2861-
return res;
2862-
}
2863-
28642852
static int snd_pcm_playback_ioctl1(struct file *file,
28652853
struct snd_pcm_substream *substream,
28662854
unsigned int cmd, void __user *arg)
@@ -3064,7 +3052,6 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
30643052
{
30653053
snd_pcm_uframes_t *frames = arg;
30663054
snd_pcm_sframes_t result;
3067-
int err;
30683055

30693056
switch (cmd) {
30703057
case SNDRV_PCM_IOCTL_FORWARD:
@@ -3084,10 +3071,7 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
30843071
case SNDRV_PCM_IOCTL_START:
30853072
return snd_pcm_start_lock_irq(substream);
30863073
case SNDRV_PCM_IOCTL_DRAIN:
3087-
snd_power_lock(substream->pcm->card);
3088-
err = snd_pcm_drain(substream, NULL);
3089-
snd_power_unlock(substream->pcm->card);
3090-
return err;
3074+
return snd_pcm_drain(substream, NULL);
30913075
case SNDRV_PCM_IOCTL_DROP:
30923076
return snd_pcm_drop(substream);
30933077
case SNDRV_PCM_IOCTL_DELAY:

‎sound/soc/soc-core.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,7 @@ int snd_soc_suspend(struct device *dev)
653653
/* Due to the resume being scheduled into a workqueue we could
654654
* suspend before that's finished - wait for it to complete.
655655
*/
656-
snd_power_lock(card->snd_card);
657656
snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
658-
snd_power_unlock(card->snd_card);
659657

660658
/* we're going to block userspace touching us until resume completes */
661659
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);

0 commit comments

Comments
 (0)