]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: firewire: fireface: Use guard() for spin locks
authorTakashi Iwai <tiwai@suse.de>
Thu, 28 Aug 2025 13:27:18 +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-15-tiwai@suse.de
sound/firewire/fireface/ff-hwdep.c
sound/firewire/fireface/ff-midi.c
sound/firewire/fireface/ff-stream.c
sound/firewire/fireface/ff-transaction.c

index ca5c5dee71f289a315786a414e44e3c967066e81..5976abf2e1ab090920bc6eb410994375e31fc8fc 100644 (file)
@@ -72,18 +72,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
                               poll_table *wait)
 {
        struct snd_ff *ff = hwdep->private_data;
-       __poll_t events;
 
        poll_wait(file, &ff->hwdep_wait, wait);
 
-       spin_lock_irq(&ff->lock);
+       guard(spinlock_irq)(&ff->lock);
        if (ff->dev_lock_changed || has_msg(ff))
-               events = EPOLLIN | EPOLLRDNORM;
+               return EPOLLIN | EPOLLRDNORM;
        else
-               events = 0;
-       spin_unlock_irq(&ff->lock);
-
-       return events;
+               return 0;
 }
 
 static int hwdep_get_info(struct snd_ff *ff, void __user *arg)
@@ -107,48 +103,35 @@ static int hwdep_get_info(struct snd_ff *ff, void __user *arg)
 
 static int hwdep_lock(struct snd_ff *ff)
 {
-       int err;
-
-       spin_lock_irq(&ff->lock);
+       guard(spinlock_irq)(&ff->lock);
 
        if (ff->dev_lock_count == 0) {
                ff->dev_lock_count = -1;
-               err = 0;
+               return 0;
        } else {
-               err = -EBUSY;
+               return -EBUSY;
        }
-
-       spin_unlock_irq(&ff->lock);
-
-       return err;
 }
 
 static int hwdep_unlock(struct snd_ff *ff)
 {
-       int err;
-
-       spin_lock_irq(&ff->lock);
+       guard(spinlock_irq)(&ff->lock);
 
        if (ff->dev_lock_count == -1) {
                ff->dev_lock_count = 0;
-               err = 0;
+               return 0;
        } else {
-               err = -EBADFD;
+               return -EBADFD;
        }
-
-       spin_unlock_irq(&ff->lock);
-
-       return err;
 }
 
 static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
 {
        struct snd_ff *ff = hwdep->private_data;
 
-       spin_lock_irq(&ff->lock);
+       guard(spinlock_irq)(&ff->lock);
        if (ff->dev_lock_count == -1)
                ff->dev_lock_count = 0;
-       spin_unlock_irq(&ff->lock);
 
        return 0;
 }
index da3054fdcc7d66050f51abc09cb2dd6ac309597e..9f6aa490e5bf256773ce468d50791cc643ac289c 100644 (file)
@@ -46,31 +46,25 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substream,
                                 int up)
 {
        struct snd_ff *ff = substream->rmidi->private_data;
-       unsigned long flags;
 
-       spin_lock_irqsave(&ff->lock, flags);
+       guard(spinlock_irqsave)(&ff->lock);
 
        if (up)
                WRITE_ONCE(ff->tx_midi_substreams[substream->number],
                           substream);
        else
                WRITE_ONCE(ff->tx_midi_substreams[substream->number], NULL);
-
-       spin_unlock_irqrestore(&ff->lock, flags);
 }
 
 static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
                                  int up)
 {
        struct snd_ff *ff = substream->rmidi->private_data;
-       unsigned long flags;
 
-       spin_lock_irqsave(&ff->lock, flags);
+       guard(spinlock_irqsave)(&ff->lock);
 
        if (up || !ff->rx_midi_error[substream->number])
                schedule_work(&ff->rx_midi_work[substream->number]);
-
-       spin_unlock_irqrestore(&ff->lock, flags);
 }
 
 static void set_midi_substream_names(struct snd_rawmidi_str *stream,
index 95bf405adb3d2bbcc902674440db27974a092fce..ba42490f2b0e263e73f83020ffea82ccefed2230 100644 (file)
@@ -253,33 +253,24 @@ void snd_ff_stream_lock_changed(struct snd_ff *ff)
 
 int snd_ff_stream_lock_try(struct snd_ff *ff)
 {
-       int err;
-
-       spin_lock_irq(&ff->lock);
+       guard(spinlock_irq)(&ff->lock);
 
        /* user land lock this */
-       if (ff->dev_lock_count < 0) {
-               err = -EBUSY;
-               goto end;
-       }
+       if (ff->dev_lock_count < 0)
+               return -EBUSY;
 
        /* this is the first time */
        if (ff->dev_lock_count++ == 0)
                snd_ff_stream_lock_changed(ff);
-       err = 0;
-end:
-       spin_unlock_irq(&ff->lock);
-       return err;
+       return 0;
 }
 
 void snd_ff_stream_lock_release(struct snd_ff *ff)
 {
-       spin_lock_irq(&ff->lock);
+       guard(spinlock_irq)(&ff->lock);
 
        if (WARN_ON(ff->dev_lock_count <= 0))
-               goto end;
+               return;
        if (--ff->dev_lock_count == 0)
                snd_ff_stream_lock_changed(ff);
-end:
-       spin_unlock_irq(&ff->lock);
 }
index 6b89e39f4a43fdbaf5659fc7a4f9af28ccd3231b..436da0a3bdcc7aa4c483c11e35ec0ddfb5877cee 100644 (file)
@@ -132,15 +132,13 @@ static void handle_msg(struct fw_card *card, struct fw_request *request, int tco
        struct snd_ff *ff = callback_data;
        __le32 *buf = data;
        u32 tstamp = fw_request_get_timestamp(request);
-       unsigned long flag;
 
        fw_send_response(card, request, RCODE_COMPLETE);
 
        offset -= ff->async_handler.offset;
 
-       spin_lock_irqsave(&ff->lock, flag);
+       guard(spinlock_irqsave)(&ff->lock);
        ff->spec->protocol->handle_msg(ff, (unsigned int)offset, buf, length, tstamp);
-       spin_unlock_irqrestore(&ff->lock, flag);
 }
 
 static int allocate_own_address(struct snd_ff *ff, int i)