Commit 8c0ae778 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: core: Simplify snd_power_ref_and_wait() with the standard macro

Use wait_event_cmd() macro and simplify snd_power_ref_wait()
implementation.  This may also cover possible races in the current
open code, too.
Reviewed-by: default avatarJaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20220119091050.30125-1-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 85c25662
...@@ -1111,29 +1111,14 @@ EXPORT_SYMBOL(snd_card_file_remove); ...@@ -1111,29 +1111,14 @@ EXPORT_SYMBOL(snd_card_file_remove);
*/ */
int snd_power_ref_and_wait(struct snd_card *card) int snd_power_ref_and_wait(struct snd_card *card)
{ {
wait_queue_entry_t wait;
int result = 0;
snd_power_ref(card); snd_power_ref(card);
/* fastpath */
if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0) if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0)
return 0; return 0;
init_waitqueue_entry(&wait, current); wait_event_cmd(card->power_sleep,
add_wait_queue(&card->power_sleep, &wait); card->shutdown ||
while (1) { snd_power_get_state(card) == SNDRV_CTL_POWER_D0,
if (card->shutdown) { snd_power_unref(card), snd_power_ref(card));
result = -ENODEV; return card->shutdown ? -ENODEV : 0;
break;
}
if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0)
break;
snd_power_unref(card);
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_timeout(30 * HZ);
snd_power_ref(card);
}
remove_wait_queue(&card->power_sleep, &wait);
return result;
} }
EXPORT_SYMBOL_GPL(snd_power_ref_and_wait); EXPORT_SYMBOL_GPL(snd_power_ref_and_wait);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment