]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ALSA: usb-audio: Use the new helper for shutdown refcount
authorTakashi Iwai <tiwai@suse.de>
Wed, 10 Jun 2026 15:45:35 +0000 (17:45 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 11 Jun 2026 07:34:09 +0000 (09:34 +0200)
Replace the open-code for managing the shutdown refcount with the new
helpers.
Only a code cleanup, no functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20260610154538.51076-6-tiwai@suse.de
sound/usb/card.c
sound/usb/usbaudio.h

index f42d72cd03781f4913eb0f86273a56e31b9d4e4c..6a3b576fb06792ce22a3b7bc06ddc7a20693900d 100644 (file)
@@ -769,7 +769,6 @@ static int snd_usb_audio_create(struct usb_interface *intf,
 
        chip = card->private_data;
        mutex_init(&chip->mutex);
-       init_waitqueue_head(&chip->shutdown_wait);
        chip->index = idx;
        chip->dev = dev;
        chip->card = card;
@@ -778,7 +777,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
        chip->autoclock = autoclock;
        chip->lowlatency = lowlatency;
        atomic_set(&chip->active, 1); /* avoid autopm during probing */
-       atomic_set(&chip->usage_count, 0);
+       snd_refcount_init(&chip->usage_count);
        atomic_set(&chip->shutdown, 0);
 
        chip->usb_id = usb_id;
@@ -1107,8 +1106,7 @@ static bool __usb_audio_disconnect(struct usb_interface *intf,
                /* wait until all pending tasks done;
                 * they are protected by snd_usb_lock_shutdown()
                 */
-               wait_event(chip->shutdown_wait,
-                          !atomic_read(&chip->usage_count));
+               snd_refcount_sync(&chip->usage_count);
                snd_card_disconnect(card);
                /* release the pcm resources */
                list_for_each_entry(as, &chip->pcm_list, list) {
@@ -1166,7 +1164,7 @@ int snd_usb_lock_shutdown(struct snd_usb_audio *chip)
 {
        int err;
 
-       atomic_inc(&chip->usage_count);
+       snd_refcount_get(&chip->usage_count);
        if (atomic_read(&chip->shutdown)) {
                err = -EIO;
                goto error;
@@ -1177,8 +1175,7 @@ int snd_usb_lock_shutdown(struct snd_usb_audio *chip)
        return 0;
 
  error:
-       if (atomic_dec_and_test(&chip->usage_count))
-               wake_up(&chip->shutdown_wait);
+       snd_refcount_put(&chip->usage_count);
        return err;
 }
 EXPORT_SYMBOL_GPL(snd_usb_lock_shutdown);
@@ -1187,8 +1184,7 @@ EXPORT_SYMBOL_GPL(snd_usb_lock_shutdown);
 void snd_usb_unlock_shutdown(struct snd_usb_audio *chip)
 {
        snd_usb_autosuspend(chip);
-       if (atomic_dec_and_test(&chip->usage_count))
-               wake_up(&chip->shutdown_wait);
+       snd_refcount_put(&chip->usage_count);
 }
 EXPORT_SYMBOL_GPL(snd_usb_unlock_shutdown);
 
index e472aef6eb879edfb05f758ec0cac2993bc128fa..e26f9092417ed06d4c28a7b5f314d742d5895fe8 100644 (file)
@@ -7,6 +7,8 @@
  *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
  */
 
+#include <sound/core.h>
+
 /* handling of USB vendor/product ID pairs as 32-bit numbers */
 #define USB_ID(vendor, product) (((unsigned int)(vendor) << 16) | (product))
 #define USB_ID_VENDOR(id) ((id) >> 16)
@@ -41,8 +43,7 @@ struct snd_usb_audio {
        unsigned int system_suspend;
        atomic_t active;
        atomic_t shutdown;
-       atomic_t usage_count;
-       wait_queue_head_t shutdown_wait;
+       struct snd_refcount usage_count;
        unsigned int quirk_flags;
        unsigned int need_delayed_register:1; /* warn for delayed registration */
        int num_interfaces;