]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: mpu401: Use guard() for spin locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 15:00:20 +0000 (17:00 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:53:34 +0000 (13:53 +0200)
Clean up the code using guard() for spin locks.

Merely code refactoring, and no behavior change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250829150026.6379-10-tiwai@suse.de
sound/drivers/mpu401/mpu401_uart.c

index 670f8ba92c0843d3904a7a71241a4fef2ca1b7b4..4af89822bf32b819f0c3d7055595120800d92f24 100644 (file)
@@ -81,27 +81,21 @@ static void snd_mpu401_uart_clear_rx(struct snd_mpu401 *mpu)
 
 static void uart_interrupt_tx(struct snd_mpu401 *mpu)
 {
-       unsigned long flags;
-
        if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) &&
            test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) {
-               spin_lock_irqsave(&mpu->output_lock, flags);
+               guard(spinlock_irqsave)(&mpu->output_lock);
                snd_mpu401_uart_output_write(mpu);
-               spin_unlock_irqrestore(&mpu->output_lock, flags);
        }
 }
 
 static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu)
 {
-       unsigned long flags;
-
        if (mpu->info_flags & MPU401_INFO_INPUT) {
-               spin_lock_irqsave(&mpu->input_lock, flags);
+               guard(spinlock_irqsave)(&mpu->input_lock);
                if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode))
                        snd_mpu401_uart_input_read(mpu);
                else
                        snd_mpu401_uart_clear_rx(mpu);
-               spin_unlock_irqrestore(&mpu->input_lock, flags);
        }
        if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
                /* ok. for better Tx performance try do some output
@@ -158,12 +152,11 @@ EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx);
 static void snd_mpu401_uart_timer(struct timer_list *t)
 {
        struct snd_mpu401 *mpu = timer_container_of(mpu, t, timer);
-       unsigned long flags;
 
-       spin_lock_irqsave(&mpu->timer_lock, flags);
-       /*mpu->mode |= MPU401_MODE_TIMER;*/
-       mod_timer(&mpu->timer,  1 + jiffies);
-       spin_unlock_irqrestore(&mpu->timer_lock, flags);
+       scoped_guard(spinlock_irqsave, &mpu->timer_lock) {
+               /*mpu->mode |= MPU401_MODE_TIMER;*/
+               mod_timer(&mpu->timer,  1 + jiffies);
+       }
        if (mpu->rmidi)
                _snd_mpu401_uart_interrupt(mpu);
 }
@@ -173,16 +166,13 @@ static void snd_mpu401_uart_timer(struct timer_list *t)
  */
 static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave (&mpu->timer_lock, flags);
+       guard(spinlock_irqsave)(&mpu->timer_lock);
        if (mpu->timer_invoked == 0) {
                timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0);
                mod_timer(&mpu->timer, 1 + jiffies);
        } 
        mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER :
                MPU401_MODE_OUTPUT_TIMER;
-       spin_unlock_irqrestore (&mpu->timer_lock, flags);
 }
 
 /*
@@ -190,16 +180,13 @@ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input)
  */
 static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave (&mpu->timer_lock, flags);
+       guard(spinlock_irqsave)(&mpu->timer_lock);
        if (mpu->timer_invoked) {
                mpu->timer_invoked &= input ? ~MPU401_MODE_INPUT_TIMER :
                        ~MPU401_MODE_OUTPUT_TIMER;
                if (! mpu->timer_invoked)
                        timer_delete(&mpu->timer);
        }
-       spin_unlock_irqrestore (&mpu->timer_lock, flags);
 }
 
 /*
@@ -210,10 +197,9 @@ static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input)
 static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd,
                               int ack)
 {
-       unsigned long flags;
        int timeout, ok;
 
-       spin_lock_irqsave(&mpu->input_lock, flags);
+       guard(spinlock_irqsave)(&mpu->input_lock);
        if (mpu->hardware != MPU401_HW_TRID4DWAVE) {
                mpu->write(mpu, 0x00, MPU401D(mpu));
                /*snd_mpu401_uart_clear_rx(mpu);*/
@@ -244,7 +230,6 @@ static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd,
                        ok = 1;
        } else
                ok = 1;
-       spin_unlock_irqrestore(&mpu->input_lock, flags);
        if (!ok) {
                dev_err(mpu->rmidi->dev,
                        "cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)\n",
@@ -358,7 +343,6 @@ static int snd_mpu401_uart_output_close(struct snd_rawmidi_substream *substream)
 static void
 snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
 {
-       unsigned long flags;
        struct snd_mpu401 *mpu;
        int max = 64;
 
@@ -374,9 +358,8 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
                }
                
                /* read data in advance */
-               spin_lock_irqsave(&mpu->input_lock, flags);
+               guard(spinlock_irqsave)(&mpu->input_lock);
                snd_mpu401_uart_input_read(mpu);
-               spin_unlock_irqrestore(&mpu->input_lock, flags);
        } else {
                if (mpu->info_flags & MPU401_INFO_USE_TIMER)
                        snd_mpu401_uart_remove_timer(mpu, 1);
@@ -445,7 +428,6 @@ static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu)
 static void
 snd_mpu401_uart_output_trigger(struct snd_rawmidi_substream *substream, int up)
 {
-       unsigned long flags;
        struct snd_mpu401 *mpu;
 
        mpu = substream->rmidi->private_data;
@@ -460,9 +442,8 @@ snd_mpu401_uart_output_trigger(struct snd_rawmidi_substream *substream, int up)
                        snd_mpu401_uart_add_timer(mpu, 0);
 
                /* output pending data */
-               spin_lock_irqsave(&mpu->output_lock, flags);
+               guard(spinlock_irqsave)(&mpu->output_lock);
                snd_mpu401_uart_output_write(mpu);
-               spin_unlock_irqrestore(&mpu->output_lock, flags);
        } else {
                if (! (mpu->info_flags & MPU401_INFO_TX_IRQ))
                        snd_mpu401_uart_remove_timer(mpu, 0);