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

ALSA: opl3: 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-5-tiwai@suse.de

+28 -60
+6 -20
sound/drivers/opl3/opl3_lib.c
··· 25 25 26 26 static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) 27 27 { 28 - unsigned long flags; 29 28 unsigned long port; 30 29 31 30 /* ··· 34 35 35 36 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; 36 37 37 - spin_lock_irqsave(&opl3->reg_lock, flags); 38 + guard(spinlock_irqsave)(&opl3->reg_lock); 38 39 39 40 outb((unsigned char) cmd, port); 40 41 udelay(10); 41 42 42 43 outb((unsigned char) val, port + 1); 43 44 udelay(30); 44 - 45 - spin_unlock_irqrestore(&opl3->reg_lock, flags); 46 45 } 47 46 48 47 static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) 49 48 { 50 - unsigned long flags; 51 49 unsigned long port; 52 50 53 51 /* ··· 54 58 55 59 port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; 56 60 57 - spin_lock_irqsave(&opl3->reg_lock, flags); 61 + guard(spinlock_irqsave)(&opl3->reg_lock); 58 62 59 63 outb((unsigned char) cmd, port); 60 64 inb(opl3->l_port); ··· 63 67 outb((unsigned char) val, port + 1); 64 68 inb(opl3->l_port); 65 69 inb(opl3->l_port); 66 - 67 - spin_unlock_irqrestore(&opl3->reg_lock, flags); 68 70 } 69 71 70 72 static int snd_opl3_detect(struct snd_opl3 * opl3) ··· 136 142 137 143 static int snd_opl3_timer1_start(struct snd_timer * timer) 138 144 { 139 - unsigned long flags; 140 145 unsigned char tmp; 141 146 unsigned int ticks; 142 147 struct snd_opl3 *opl3; 143 148 144 149 opl3 = snd_timer_chip(timer); 145 - spin_lock_irqsave(&opl3->timer_lock, flags); 150 + guard(spinlock_irqsave)(&opl3->timer_lock); 146 151 ticks = timer->sticks; 147 152 tmp = (opl3->timer_enable | OPL3_TIMER1_START) & ~OPL3_TIMER1_MASK; 148 153 opl3->timer_enable = tmp; 149 154 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 256 - ticks); /* timer 1 count */ 150 155 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ 151 - spin_unlock_irqrestore(&opl3->timer_lock, flags); 152 156 return 0; 153 157 } 154 158 155 159 static int snd_opl3_timer1_stop(struct snd_timer * timer) 156 160 { 157 - unsigned long flags; 158 161 unsigned char tmp; 159 162 struct snd_opl3 *opl3; 160 163 161 164 opl3 = snd_timer_chip(timer); 162 - spin_lock_irqsave(&opl3->timer_lock, flags); 165 + guard(spinlock_irqsave)(&opl3->timer_lock); 163 166 tmp = (opl3->timer_enable | OPL3_TIMER1_MASK) & ~OPL3_TIMER1_START; 164 167 opl3->timer_enable = tmp; 165 168 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ 166 - spin_unlock_irqrestore(&opl3->timer_lock, flags); 167 169 return 0; 168 170 } 169 171 ··· 169 179 170 180 static int snd_opl3_timer2_start(struct snd_timer * timer) 171 181 { 172 - unsigned long flags; 173 182 unsigned char tmp; 174 183 unsigned int ticks; 175 184 struct snd_opl3 *opl3; 176 185 177 186 opl3 = snd_timer_chip(timer); 178 - spin_lock_irqsave(&opl3->timer_lock, flags); 187 + guard(spinlock_irqsave)(&opl3->timer_lock); 179 188 ticks = timer->sticks; 180 189 tmp = (opl3->timer_enable | OPL3_TIMER2_START) & ~OPL3_TIMER2_MASK; 181 190 opl3->timer_enable = tmp; 182 191 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER2, 256 - ticks); /* timer 1 count */ 183 192 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ 184 - spin_unlock_irqrestore(&opl3->timer_lock, flags); 185 193 return 0; 186 194 } 187 195 188 196 static int snd_opl3_timer2_stop(struct snd_timer * timer) 189 197 { 190 - unsigned long flags; 191 198 unsigned char tmp; 192 199 struct snd_opl3 *opl3; 193 200 194 201 opl3 = snd_timer_chip(timer); 195 - spin_lock_irqsave(&opl3->timer_lock, flags); 202 + guard(spinlock_irqsave)(&opl3->timer_lock); 196 203 tmp = (opl3->timer_enable | OPL3_TIMER2_MASK) & ~OPL3_TIMER2_START; 197 204 opl3->timer_enable = tmp; 198 205 opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ 199 - spin_unlock_irqrestore(&opl3->timer_lock, flags); 200 206 return 0; 201 207 } 202 208
+17 -34
sound/drivers/opl3/opl3_midi.c
··· 234 234 { 235 235 236 236 struct snd_opl3 *opl3 = timer_container_of(opl3, t, tlist); 237 - unsigned long flags; 238 237 int again = 0; 239 238 int i; 240 239 241 - spin_lock_irqsave(&opl3->voice_lock, flags); 242 - for (i = 0; i < opl3->max_voices; i++) { 243 - struct snd_opl3_voice *vp = &opl3->voices[i]; 244 - if (vp->state > 0 && vp->note_off_check) { 245 - if (vp->note_off == jiffies) 246 - snd_opl3_note_off_unsafe(opl3, vp->note, 0, 247 - vp->chan); 248 - else 249 - again++; 240 + scoped_guard(spinlock_irqsave, &opl3->voice_lock) { 241 + for (i = 0; i < opl3->max_voices; i++) { 242 + struct snd_opl3_voice *vp = &opl3->voices[i]; 243 + if (vp->state > 0 && vp->note_off_check) { 244 + if (vp->note_off == jiffies) 245 + snd_opl3_note_off_unsafe(opl3, vp->note, 0, 246 + vp->chan); 247 + else 248 + again++; 249 + } 250 250 } 251 251 } 252 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 253 252 254 - spin_lock_irqsave(&opl3->sys_timer_lock, flags); 253 + guard(spinlock_irqsave)(&opl3->sys_timer_lock); 255 254 if (again) 256 255 mod_timer(&opl3->tlist, jiffies + 1); /* invoke again */ 257 256 else 258 257 opl3->sys_timer_status = 0; 259 - spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); 260 258 } 261 259 262 260 /* ··· 262 264 */ 263 265 static void snd_opl3_start_timer(struct snd_opl3 *opl3) 264 266 { 265 - unsigned long flags; 266 - spin_lock_irqsave(&opl3->sys_timer_lock, flags); 267 + guard(spinlock_irqsave)(&opl3->sys_timer_lock); 267 268 if (! opl3->sys_timer_status) { 268 269 mod_timer(&opl3->tlist, jiffies + 1); 269 270 opl3->sys_timer_status = 1; 270 271 } 271 - spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); 272 272 } 273 273 274 274 /* ------------------------------ */ ··· 305 309 306 310 struct fm_patch *patch; 307 311 struct fm_instrument *fm; 308 - unsigned long flags; 309 312 310 313 opl3 = p; 311 314 ··· 332 337 prg = chan->midi_program; 333 338 } 334 339 335 - spin_lock_irqsave(&opl3->voice_lock, flags); 340 + guard(spinlock_irqsave)(&opl3->voice_lock); 336 341 337 342 if (use_internal_drums) { 338 343 snd_opl3_drum_switch(opl3, note, vel, 1, chan); 339 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 340 344 return; 341 345 } 342 346 343 347 __extra_prg: 344 348 patch = snd_opl3_find_patch(opl3, prg, bank, 0); 345 - if (!patch) { 346 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 349 + if (!patch) 347 350 return; 348 - } 349 351 350 352 fm = &patch->inst; 351 353 switch (patch->type) { ··· 356 364 } 357 365 fallthrough; 358 366 default: 359 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 360 367 return; 361 368 } 362 369 opl3_dbg(opl3, " --> OPL%i instrument: %s\n", ··· 369 378 voice = snd_opl3_oss_map[chan->number]; 370 379 } 371 380 372 - if (voice < 0) { 373 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 381 + if (voice < 0) 374 382 return; 375 - } 376 383 377 384 if (voice < MAX_OPL2_VOICES) { 378 385 /* Left register block for voices 0 .. 8 */ ··· 586 597 opl3_dbg(opl3, " *** allocating extra program\n"); 587 598 goto __extra_prg; 588 599 } 589 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 590 600 } 591 601 592 602 static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice) ··· 674 686 struct snd_midi_channel *chan) 675 687 { 676 688 struct snd_opl3 *opl3 = p; 677 - unsigned long flags; 678 689 679 - spin_lock_irqsave(&opl3->voice_lock, flags); 690 + guard(spinlock_irqsave)(&opl3->voice_lock); 680 691 snd_opl3_note_off_unsafe(p, note, vel, chan); 681 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 682 692 } 683 693 684 694 /* ··· 750 764 int voice; 751 765 struct snd_opl3_voice *vp; 752 766 753 - unsigned long flags; 754 - 755 - spin_lock_irqsave(&opl3->voice_lock, flags); 767 + guard(spinlock_irqsave)(&opl3->voice_lock); 756 768 757 769 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { 758 770 for (voice = 0; voice < opl3->max_voices; voice++) { ··· 766 782 snd_opl3_update_pitch(opl3, voice); 767 783 } 768 784 } 769 - spin_unlock_irqrestore(&opl3->voice_lock, flags); 770 785 } 771 786 772 787 /*
+5 -6
sound/drivers/opl3/opl3_seq.c
··· 66 66 67 67 void snd_opl3_synth_cleanup(struct snd_opl3 * opl3) 68 68 { 69 - unsigned long flags; 70 69 struct snd_hwdep *hwdep; 71 70 72 71 /* Stop system timer */ 73 - spin_lock_irqsave(&opl3->sys_timer_lock, flags); 74 - if (opl3->sys_timer_status) { 75 - timer_delete(&opl3->tlist); 76 - opl3->sys_timer_status = 0; 72 + scoped_guard(spinlock_irq, &opl3->sys_timer_lock) { 73 + if (opl3->sys_timer_status) { 74 + timer_delete(&opl3->tlist); 75 + opl3->sys_timer_status = 0; 76 + } 77 77 } 78 - spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); 79 78 80 79 snd_opl3_reset(opl3); 81 80 hwdep = opl3->hwdep;