Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: mpu401: Use guard() for spin locks

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

+11 -30
+11 -30
sound/drivers/mpu401/mpu401_uart.c
··· 81 81 82 82 static void uart_interrupt_tx(struct snd_mpu401 *mpu) 83 83 { 84 - unsigned long flags; 85 - 86 84 if (test_bit(MPU401_MODE_BIT_OUTPUT, &mpu->mode) && 87 85 test_bit(MPU401_MODE_BIT_OUTPUT_TRIGGER, &mpu->mode)) { 88 - spin_lock_irqsave(&mpu->output_lock, flags); 86 + guard(spinlock_irqsave)(&mpu->output_lock); 89 87 snd_mpu401_uart_output_write(mpu); 90 - spin_unlock_irqrestore(&mpu->output_lock, flags); 91 88 } 92 89 } 93 90 94 91 static void _snd_mpu401_uart_interrupt(struct snd_mpu401 *mpu) 95 92 { 96 - unsigned long flags; 97 - 98 93 if (mpu->info_flags & MPU401_INFO_INPUT) { 99 - spin_lock_irqsave(&mpu->input_lock, flags); 94 + guard(spinlock_irqsave)(&mpu->input_lock); 100 95 if (test_bit(MPU401_MODE_BIT_INPUT, &mpu->mode)) 101 96 snd_mpu401_uart_input_read(mpu); 102 97 else 103 98 snd_mpu401_uart_clear_rx(mpu); 104 - spin_unlock_irqrestore(&mpu->input_lock, flags); 105 99 } 106 100 if (! (mpu->info_flags & MPU401_INFO_TX_IRQ)) 107 101 /* ok. for better Tx performance try do some output ··· 152 158 static void snd_mpu401_uart_timer(struct timer_list *t) 153 159 { 154 160 struct snd_mpu401 *mpu = timer_container_of(mpu, t, timer); 155 - unsigned long flags; 156 161 157 - spin_lock_irqsave(&mpu->timer_lock, flags); 158 - /*mpu->mode |= MPU401_MODE_TIMER;*/ 159 - mod_timer(&mpu->timer, 1 + jiffies); 160 - spin_unlock_irqrestore(&mpu->timer_lock, flags); 162 + scoped_guard(spinlock_irqsave, &mpu->timer_lock) { 163 + /*mpu->mode |= MPU401_MODE_TIMER;*/ 164 + mod_timer(&mpu->timer, 1 + jiffies); 165 + } 161 166 if (mpu->rmidi) 162 167 _snd_mpu401_uart_interrupt(mpu); 163 168 } ··· 166 173 */ 167 174 static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input) 168 175 { 169 - unsigned long flags; 170 - 171 - spin_lock_irqsave (&mpu->timer_lock, flags); 176 + guard(spinlock_irqsave)(&mpu->timer_lock); 172 177 if (mpu->timer_invoked == 0) { 173 178 timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0); 174 179 mod_timer(&mpu->timer, 1 + jiffies); 175 180 } 176 181 mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER : 177 182 MPU401_MODE_OUTPUT_TIMER; 178 - spin_unlock_irqrestore (&mpu->timer_lock, flags); 179 183 } 180 184 181 185 /* ··· 180 190 */ 181 191 static void snd_mpu401_uart_remove_timer (struct snd_mpu401 *mpu, int input) 182 192 { 183 - unsigned long flags; 184 - 185 - spin_lock_irqsave (&mpu->timer_lock, flags); 193 + guard(spinlock_irqsave)(&mpu->timer_lock); 186 194 if (mpu->timer_invoked) { 187 195 mpu->timer_invoked &= input ? ~MPU401_MODE_INPUT_TIMER : 188 196 ~MPU401_MODE_OUTPUT_TIMER; 189 197 if (! mpu->timer_invoked) 190 198 timer_delete(&mpu->timer); 191 199 } 192 - spin_unlock_irqrestore (&mpu->timer_lock, flags); 193 200 } 194 201 195 202 /* ··· 197 210 static int snd_mpu401_uart_cmd(struct snd_mpu401 * mpu, unsigned char cmd, 198 211 int ack) 199 212 { 200 - unsigned long flags; 201 213 int timeout, ok; 202 214 203 - spin_lock_irqsave(&mpu->input_lock, flags); 215 + guard(spinlock_irqsave)(&mpu->input_lock); 204 216 if (mpu->hardware != MPU401_HW_TRID4DWAVE) { 205 217 mpu->write(mpu, 0x00, MPU401D(mpu)); 206 218 /*snd_mpu401_uart_clear_rx(mpu);*/ ··· 230 244 ok = 1; 231 245 } else 232 246 ok = 1; 233 - spin_unlock_irqrestore(&mpu->input_lock, flags); 234 247 if (!ok) { 235 248 dev_err(mpu->rmidi->dev, 236 249 "cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)\n", ··· 343 358 static void 344 359 snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up) 345 360 { 346 - unsigned long flags; 347 361 struct snd_mpu401 *mpu; 348 362 int max = 64; 349 363 ··· 358 374 } 359 375 360 376 /* read data in advance */ 361 - spin_lock_irqsave(&mpu->input_lock, flags); 377 + guard(spinlock_irqsave)(&mpu->input_lock); 362 378 snd_mpu401_uart_input_read(mpu); 363 - spin_unlock_irqrestore(&mpu->input_lock, flags); 364 379 } else { 365 380 if (mpu->info_flags & MPU401_INFO_USE_TIMER) 366 381 snd_mpu401_uart_remove_timer(mpu, 1); ··· 428 445 static void 429 446 snd_mpu401_uart_output_trigger(struct snd_rawmidi_substream *substream, int up) 430 447 { 431 - unsigned long flags; 432 448 struct snd_mpu401 *mpu; 433 449 434 450 mpu = substream->rmidi->private_data; ··· 442 460 snd_mpu401_uart_add_timer(mpu, 0); 443 461 444 462 /* output pending data */ 445 - spin_lock_irqsave(&mpu->output_lock, flags); 463 + guard(spinlock_irqsave)(&mpu->output_lock); 446 464 snd_mpu401_uart_output_write(mpu); 447 - spin_unlock_irqrestore(&mpu->output_lock, flags); 448 465 } else { 449 466 if (! (mpu->info_flags & MPU401_INFO_TX_IRQ)) 450 467 snd_mpu401_uart_remove_timer(mpu, 0);