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

index b150607c0a0d13801b935a4610da5e808c4cac5f..435d18417cf038bab244ad711cde299efd981a15 100644 (file)
@@ -63,18 +63,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file,
                               poll_table *wait)
 {
        struct snd_dg00x *dg00x = hwdep->private_data;
-       __poll_t events;
 
        poll_wait(file, &dg00x->hwdep_wait, wait);
 
-       spin_lock_irq(&dg00x->lock);
+       guard(spinlock_irq)(&dg00x->lock);
        if (dg00x->dev_lock_changed || dg00x->msg)
-               events = EPOLLIN | EPOLLRDNORM;
+               return EPOLLIN | EPOLLRDNORM;
        else
-               events = 0;
-       spin_unlock_irq(&dg00x->lock);
-
-       return events;
+               return 0;
 }
 
 static int hwdep_get_info(struct snd_dg00x *dg00x, void __user *arg)
@@ -98,48 +94,35 @@ static int hwdep_get_info(struct snd_dg00x *dg00x, void __user *arg)
 
 static int hwdep_lock(struct snd_dg00x *dg00x)
 {
-       int err;
-
-       spin_lock_irq(&dg00x->lock);
+       guard(spinlock_irq)(&dg00x->lock);
 
        if (dg00x->dev_lock_count == 0) {
                dg00x->dev_lock_count = -1;
-               err = 0;
+               return 0;
        } else {
-               err = -EBUSY;
+               return -EBUSY;
        }
-
-       spin_unlock_irq(&dg00x->lock);
-
-       return err;
 }
 
 static int hwdep_unlock(struct snd_dg00x *dg00x)
 {
-       int err;
-
-       spin_lock_irq(&dg00x->lock);
+       guard(spinlock_irq)(&dg00x->lock);
 
        if (dg00x->dev_lock_count == -1) {
                dg00x->dev_lock_count = 0;
-               err = 0;
+               return 0;
        } else {
-               err = -EBADFD;
+               return -EBADFD;
        }
-
-       spin_unlock_irq(&dg00x->lock);
-
-       return err;
 }
 
 static int hwdep_release(struct snd_hwdep *hwdep, struct file *file)
 {
        struct snd_dg00x *dg00x = hwdep->private_data;
 
-       spin_lock_irq(&dg00x->lock);
+       guard(spinlock_irq)(&dg00x->lock);
        if (dg00x->dev_lock_count == -1)
                dg00x->dev_lock_count = 0;
-       spin_unlock_irq(&dg00x->lock);
 
        return 0;
 }
index 0f6ca58cc4a0d592dca6987ec9e7b9c9a0006063..bcdaf003514b811aca7f86e0cb3a0e008e223f48 100644 (file)
@@ -49,21 +49,18 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substream,
 {
        struct snd_dg00x *dg00x = substream->rmidi->private_data;
        unsigned int port;
-       unsigned long flags;
 
        if (substream->rmidi->device == 0)
                port = substream->number;
        else
                port = 2;
 
-       spin_lock_irqsave(&dg00x->lock, flags);
+       guard(spinlock_irqsave)(&dg00x->lock);
 
        if (up)
                amdtp_dot_midi_trigger(&dg00x->tx_stream, port, substream);
        else
                amdtp_dot_midi_trigger(&dg00x->tx_stream, port, NULL);
-
-       spin_unlock_irqrestore(&dg00x->lock, flags);
 }
 
 static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
@@ -71,21 +68,18 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substream,
 {
        struct snd_dg00x *dg00x = substream->rmidi->private_data;
        unsigned int port;
-       unsigned long flags;
 
        if (substream->rmidi->device == 0)
                port = substream->number;
        else
                port = 2;
 
-       spin_lock_irqsave(&dg00x->lock, flags);
+       guard(spinlock_irqsave)(&dg00x->lock);
 
        if (up)
                amdtp_dot_midi_trigger(&dg00x->rx_stream, port, substream);
        else
                amdtp_dot_midi_trigger(&dg00x->rx_stream, port, NULL);
-
-       spin_unlock_irqrestore(&dg00x->lock, flags);
 }
 
 static void set_substream_names(struct snd_dg00x *dg00x,
index 295163bb8abb623c03a92a10b30f1b5dc630fa4a..250ffdb26ebdd282752be8243801de5d51ab8a83 100644 (file)
@@ -427,33 +427,24 @@ void snd_dg00x_stream_lock_changed(struct snd_dg00x *dg00x)
 
 int snd_dg00x_stream_lock_try(struct snd_dg00x *dg00x)
 {
-       int err;
-
-       spin_lock_irq(&dg00x->lock);
+       guard(spinlock_irq)(&dg00x->lock);
 
        /* user land lock this */
-       if (dg00x->dev_lock_count < 0) {
-               err = -EBUSY;
-               goto end;
-       }
+       if (dg00x->dev_lock_count < 0)
+               return -EBUSY;
 
        /* this is the first time */
        if (dg00x->dev_lock_count++ == 0)
                snd_dg00x_stream_lock_changed(dg00x);
-       err = 0;
-end:
-       spin_unlock_irq(&dg00x->lock);
-       return err;
+       return 0;
 }
 
 void snd_dg00x_stream_lock_release(struct snd_dg00x *dg00x)
 {
-       spin_lock_irq(&dg00x->lock);
+       guard(spinlock_irq)(&dg00x->lock);
 
        if (WARN_ON(dg00x->dev_lock_count <= 0))
-               goto end;
+               return;
        if (--dg00x->dev_lock_count == 0)
                snd_dg00x_stream_lock_changed(dg00x);
-end:
-       spin_unlock_irq(&dg00x->lock);
 }
index cf0bcf1c595631e910cba3bf2d6d1f0e2c9927da..8a1667159930daba5d2005f865c4789e44b44a1b 100644 (file)
 static void handle_unknown_message(struct snd_dg00x *dg00x,
                                   unsigned long long offset, __be32 *buf)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave(&dg00x->lock, flags);
-       dg00x->msg = be32_to_cpu(*buf);
-       spin_unlock_irqrestore(&dg00x->lock, flags);
+       scoped_guard(spinlock_irqsave, &dg00x->lock) {
+               dg00x->msg = be32_to_cpu(*buf);
+       }
 
        wake_up(&dg00x->hwdep_wait);
 }