]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: firewire: dice: Use guard() for spin locks
authorTakashi Iwai <tiwai@suse.de>
Thu, 28 Aug 2025 13:27:16 +0000 (15:27 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sat, 30 Aug 2025 08:02:21 +0000 (10:02 +0200)
Clean up the code using guard() for spin locks.

Merely code refactoring, and no behavior change.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250828132802.9032-13-tiwai@suse.de
sound/firewire/dice/dice-hwdep.c
sound/firewire/dice/dice-midi.c
sound/firewire/dice/dice-stream.c
sound/firewire/dice/dice-transaction.c

index d165dd427bd3b9ef9a951a373c104c48b913e223..747ff09524837dd7ed180109d0f2701175cfdd26 100644 (file)
@@ -55,18 +55,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
                               poll_table *wait)
 {
        struct snd_dice *dice = hwdep->private_data;
-       __poll_t events;
 
        poll_wait(file, &dice->hwdep_wait, wait);
 
-       spin_lock_irq(&dice->lock);
+       guard(spinlock_irq)(&dice->lock);
        if (dice->dev_lock_changed || dice->notification_bits != 0)
-               events = EPOLLIN | EPOLLRDNORM;
+               return EPOLLIN | EPOLLRDNORM;
        else
-               events = 0;
-       spin_unlock_irq(&dice->lock);
-
-       return events;
+               return 0;
 }
 
 static int hwdep_get_info(struct snd_dice *dice, void __user *arg)
@@ -90,48 +86,35 @@ static int hwdep_get_info(struct snd_dice *dice, void __user *arg)
 
 static int hwdep_lock(struct snd_dice *dice)
 {
-       int err;
-
-       spin_lock_irq(&dice->lock);
+       guard(spinlock_irq)(&dice->lock);
 
        if (dice->dev_lock_count == 0) {
                dice->dev_lock_count = -1;
-               err = 0;
+               return 0;
        } else {
-               err = -EBUSY;
+               return -EBUSY;
        }
-
-       spin_unlock_irq(&dice->lock);
-
-       return err;
 }
 
 static int hwdep_unlock(struct snd_dice *dice)
 {
-       int err;
-
-       spin_lock_irq(&dice->lock);
+       guard(spinlock_irq)(&dice->lock);
 
        if (dice->dev_lock_count == -1) {
                dice->dev_lock_count = 0;
-               err = 0;
+               return 0;
        } else {
-               err = -EBADFD;
+               return -EBADFD;
        }
-
-       spin_unlock_irq(&dice->lock);
-
-       return err;
 }
 
 static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
 {
        struct snd_dice *dice = hwdep->private_data;
 
-       spin_lock_irq(&dice->lock);
+       guard(spinlock_irq)(&dice->lock);
        if (dice->dev_lock_count == -1)
                dice->dev_lock_count = 0;
-       spin_unlock_irq(&dice->lock);
 
        return 0;
 }
index 9ca975c556ca713e377e2bbf3001cfcb2dbb8285..722bce3793453be9840a1105bacc7f9b5132b017 100644 (file)
@@ -47,9 +47,8 @@ static int midi_close(struct snd_rawmidi_substream *substream)
 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
 {
        struct snd_dice *dice = substrm->rmidi->private_data;
-       unsigned long flags;
 
-       spin_lock_irqsave(&dice->lock, flags);
+       guard(spinlock_irqsave)(&dice->lock);
 
        if (up)
                amdtp_am824_midi_trigger(&dice->tx_stream[0],
@@ -57,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
        else
                amdtp_am824_midi_trigger(&dice->tx_stream[0],
                                          substrm->number, NULL);
-
-       spin_unlock_irqrestore(&dice->lock, flags);
 }
 
 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
 {
        struct snd_dice *dice = substrm->rmidi->private_data;
-       unsigned long flags;
 
-       spin_lock_irqsave(&dice->lock, flags);
+       guard(spinlock_irqsave)(&dice->lock);
 
        if (up)
                amdtp_am824_midi_trigger(&dice->rx_stream[0],
@@ -74,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
        else
                amdtp_am824_midi_trigger(&dice->rx_stream[0],
                                         substrm->number, NULL);
-
-       spin_unlock_irqrestore(&dice->lock, flags);
 }
 
 static void set_midi_substream_names(struct snd_dice *dice,
index 4c677c8546c71a8bebc867abb423239d49906108..d5ffe7c8299329e3e835beb4c3edafc5f64aa06e 100644 (file)
@@ -677,32 +677,23 @@ static void dice_lock_changed(struct snd_dice *dice)
 
 int snd_dice_stream_lock_try(struct snd_dice *dice)
 {
-       int err;
-
-       spin_lock_irq(&dice->lock);
+       guard(spinlock_irq)(&dice->lock);
 
-       if (dice->dev_lock_count < 0) {
-               err = -EBUSY;
-               goto out;
-       }
+       if (dice->dev_lock_count < 0)
+               return -EBUSY;
 
        if (dice->dev_lock_count++ == 0)
                dice_lock_changed(dice);
-       err = 0;
-out:
-       spin_unlock_irq(&dice->lock);
-       return err;
+       return 0;
 }
 
 void snd_dice_stream_lock_release(struct snd_dice *dice)
 {
-       spin_lock_irq(&dice->lock);
+       guard(spinlock_irq)(&dice->lock);
 
        if (WARN_ON(dice->dev_lock_count <= 0))
-               goto out;
+               return;
 
        if (--dice->dev_lock_count == 0)
                dice_lock_changed(dice);
-out:
-       spin_unlock_irq(&dice->lock);
 }
index 92941ef83cd5c5b2b717c19c05cde7ffad30f7bf..a3f7dfa990a4e5fb5e28b61ee275a4378dd57899 100644 (file)
@@ -136,7 +136,6 @@ static void dice_notification(struct fw_card *card, struct fw_request *request,
 {
        struct snd_dice *dice = callback_data;
        u32 bits;
-       unsigned long flags;
 
        if (tcode != TCODE_WRITE_QUADLET_REQUEST) {
                fw_send_response(card, request, RCODE_TYPE_ERROR);
@@ -149,9 +148,9 @@ static void dice_notification(struct fw_card *card, struct fw_request *request,
 
        bits = be32_to_cpup(data);
 
-       spin_lock_irqsave(&dice->lock, flags);
-       dice->notification_bits |= bits;
-       spin_unlock_irqrestore(&dice->lock, flags);
+       scoped_guard(spinlock_irqsave, &dice->lock) {
+               dice->notification_bits |= bits;
+       }
 
        fw_send_response(card, request, RCODE_COMPLETE);