]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ALSA: core: Simplify snd_power_ref_and_wait() with the standard macro
authorTakashi Iwai <tiwai@suse.de>
Wed, 19 Jan 2022 09:10:50 +0000 (10:10 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 19 Jan 2022 16:26:04 +0000 (17:26 +0100)
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: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20220119091050.30125-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/init.c

index ac335f5906c6b442bc7944b10ee1685ea652ecdf..31ba7024e3addfd5e7ffdac9f792a2bab27e1828 100644 (file)
@@ -1111,29 +1111,14 @@ EXPORT_SYMBOL(snd_card_file_remove);
  */
 int snd_power_ref_and_wait(struct snd_card *card)
 {
-       wait_queue_entry_t wait;
-       int result = 0;
-
        snd_power_ref(card);
-       /* fastpath */
        if (snd_power_get_state(card) == SNDRV_CTL_POWER_D0)
                return 0;
-       init_waitqueue_entry(&wait, current);
-       add_wait_queue(&card->power_sleep, &wait);
-       while (1) {
-               if (card->shutdown) {
-                       result = -ENODEV;
-                       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;
+       wait_event_cmd(card->power_sleep,
+                      card->shutdown ||
+                      snd_power_get_state(card) == SNDRV_CTL_POWER_D0,
+                      snd_power_unref(card), snd_power_ref(card));
+       return card->shutdown ? -ENODEV : 0;
 }
 EXPORT_SYMBOL_GPL(snd_power_ref_and_wait);