diff options
author | Takashi Iwai <tiwai@suse.de> | 2025-08-29 17:00:15 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2025-09-01 13:53:34 +0200 |
commit | ec6ac1d5e15a14e403630c5fbf8e41daf184ec83 (patch) | |
tree | 48e759b46a9d13b352cce043d019942fe41e48cb | |
parent | 6a6da5ca9795d59f2e8b851f2b8d2ce8bc536c6e (diff) |
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
-rw-r--r-- | sound/drivers/opl3/opl3_lib.c | 26 | ||||
-rw-r--r-- | sound/drivers/opl3/opl3_midi.c | 51 | ||||
-rw-r--r-- | sound/drivers/opl3/opl3_seq.c | 11 |
3 files changed, 28 insertions, 60 deletions
diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c index cd9642a6689b..fa8a2ccbbd51 100644 --- a/sound/drivers/opl3/opl3_lib.c +++ b/sound/drivers/opl3/opl3_lib.c @@ -25,7 +25,6 @@ MODULE_LICENSE("GPL"); static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) { - unsigned long flags; unsigned long port; /* @@ -35,20 +34,17 @@ static void snd_opl2_command(struct snd_opl3 * opl3, unsigned short cmd, unsigne port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; - spin_lock_irqsave(&opl3->reg_lock, flags); + guard(spinlock_irqsave)(&opl3->reg_lock); outb((unsigned char) cmd, port); udelay(10); outb((unsigned char) val, port + 1); udelay(30); - - spin_unlock_irqrestore(&opl3->reg_lock, flags); } static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigned char val) { - unsigned long flags; unsigned long port; /* @@ -58,7 +54,7 @@ static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigne port = (cmd & OPL3_RIGHT) ? opl3->r_port : opl3->l_port; - spin_lock_irqsave(&opl3->reg_lock, flags); + guard(spinlock_irqsave)(&opl3->reg_lock); outb((unsigned char) cmd, port); inb(opl3->l_port); @@ -67,8 +63,6 @@ static void snd_opl3_command(struct snd_opl3 * opl3, unsigned short cmd, unsigne outb((unsigned char) val, port + 1); inb(opl3->l_port); inb(opl3->l_port); - - spin_unlock_irqrestore(&opl3->reg_lock, flags); } static int snd_opl3_detect(struct snd_opl3 * opl3) @@ -142,34 +136,30 @@ static int snd_opl3_detect(struct snd_opl3 * opl3) static int snd_opl3_timer1_start(struct snd_timer * timer) { - unsigned long flags; unsigned char tmp; unsigned int ticks; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); - spin_lock_irqsave(&opl3->timer_lock, flags); + guard(spinlock_irqsave)(&opl3->timer_lock); ticks = timer->sticks; tmp = (opl3->timer_enable | OPL3_TIMER1_START) & ~OPL3_TIMER1_MASK; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER1, 256 - ticks); /* timer 1 count */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ - spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } static int snd_opl3_timer1_stop(struct snd_timer * timer) { - unsigned long flags; unsigned char tmp; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); - spin_lock_irqsave(&opl3->timer_lock, flags); + guard(spinlock_irqsave)(&opl3->timer_lock); tmp = (opl3->timer_enable | OPL3_TIMER1_MASK) & ~OPL3_TIMER1_START; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ - spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } @@ -179,34 +169,30 @@ static int snd_opl3_timer1_stop(struct snd_timer * timer) static int snd_opl3_timer2_start(struct snd_timer * timer) { - unsigned long flags; unsigned char tmp; unsigned int ticks; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); - spin_lock_irqsave(&opl3->timer_lock, flags); + guard(spinlock_irqsave)(&opl3->timer_lock); ticks = timer->sticks; tmp = (opl3->timer_enable | OPL3_TIMER2_START) & ~OPL3_TIMER2_MASK; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER2, 256 - ticks); /* timer 1 count */ opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* enable timer 1 IRQ */ - spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } static int snd_opl3_timer2_stop(struct snd_timer * timer) { - unsigned long flags; unsigned char tmp; struct snd_opl3 *opl3; opl3 = snd_timer_chip(timer); - spin_lock_irqsave(&opl3->timer_lock, flags); + guard(spinlock_irqsave)(&opl3->timer_lock); tmp = (opl3->timer_enable | OPL3_TIMER2_MASK) & ~OPL3_TIMER2_START; opl3->timer_enable = tmp; opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, tmp); /* disable timer #1 */ - spin_unlock_irqrestore(&opl3->timer_lock, flags); return 0; } diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c index de7449cb6515..6d3c5b5a35ff 100644 --- a/sound/drivers/opl3/opl3_midi.c +++ b/sound/drivers/opl3/opl3_midi.c @@ -234,29 +234,27 @@ void snd_opl3_timer_func(struct timer_list *t) { struct snd_opl3 *opl3 = timer_container_of(opl3, t, tlist); - unsigned long flags; int again = 0; int i; - spin_lock_irqsave(&opl3->voice_lock, flags); - for (i = 0; i < opl3->max_voices; i++) { - struct snd_opl3_voice *vp = &opl3->voices[i]; - if (vp->state > 0 && vp->note_off_check) { - if (vp->note_off == jiffies) - snd_opl3_note_off_unsafe(opl3, vp->note, 0, - vp->chan); - else - again++; + scoped_guard(spinlock_irqsave, &opl3->voice_lock) { + for (i = 0; i < opl3->max_voices; i++) { + struct snd_opl3_voice *vp = &opl3->voices[i]; + if (vp->state > 0 && vp->note_off_check) { + if (vp->note_off == jiffies) + snd_opl3_note_off_unsafe(opl3, vp->note, 0, + vp->chan); + else + again++; + } } } - spin_unlock_irqrestore(&opl3->voice_lock, flags); - spin_lock_irqsave(&opl3->sys_timer_lock, flags); + guard(spinlock_irqsave)(&opl3->sys_timer_lock); if (again) mod_timer(&opl3->tlist, jiffies + 1); /* invoke again */ else opl3->sys_timer_status = 0; - spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); } /* @@ -264,13 +262,11 @@ void snd_opl3_timer_func(struct timer_list *t) */ static void snd_opl3_start_timer(struct snd_opl3 *opl3) { - unsigned long flags; - spin_lock_irqsave(&opl3->sys_timer_lock, flags); + guard(spinlock_irqsave)(&opl3->sys_timer_lock); if (! opl3->sys_timer_status) { mod_timer(&opl3->tlist, jiffies + 1); opl3->sys_timer_status = 1; } - spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); } /* ------------------------------ */ @@ -309,7 +305,6 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) struct fm_patch *patch; struct fm_instrument *fm; - unsigned long flags; opl3 = p; @@ -337,20 +332,17 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) prg = chan->midi_program; } - spin_lock_irqsave(&opl3->voice_lock, flags); + guard(spinlock_irqsave)(&opl3->voice_lock); if (use_internal_drums) { snd_opl3_drum_switch(opl3, note, vel, 1, chan); - spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } __extra_prg: patch = snd_opl3_find_patch(opl3, prg, bank, 0); - if (!patch) { - spin_unlock_irqrestore(&opl3->voice_lock, flags); + if (!patch) return; - } fm = &patch->inst; switch (patch->type) { @@ -364,7 +356,6 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) } fallthrough; default: - spin_unlock_irqrestore(&opl3->voice_lock, flags); return; } opl3_dbg(opl3, " --> OPL%i instrument: %s\n", @@ -378,10 +369,8 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) voice = snd_opl3_oss_map[chan->number]; } - if (voice < 0) { - spin_unlock_irqrestore(&opl3->voice_lock, flags); + if (voice < 0) return; - } if (voice < MAX_OPL2_VOICES) { /* Left register block for voices 0 .. 8 */ @@ -597,7 +586,6 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan) opl3_dbg(opl3, " *** allocating extra program\n"); goto __extra_prg; } - spin_unlock_irqrestore(&opl3->voice_lock, flags); } static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice) @@ -686,11 +674,9 @@ void snd_opl3_note_off(void *p, int note, int vel, struct snd_midi_channel *chan) { struct snd_opl3 *opl3 = p; - unsigned long flags; - spin_lock_irqsave(&opl3->voice_lock, flags); + guard(spinlock_irqsave)(&opl3->voice_lock); snd_opl3_note_off_unsafe(p, note, vel, chan); - spin_unlock_irqrestore(&opl3->voice_lock, flags); } /* @@ -764,9 +750,7 @@ static void snd_opl3_pitch_ctrl(struct snd_opl3 *opl3, struct snd_midi_channel * int voice; struct snd_opl3_voice *vp; - unsigned long flags; - - spin_lock_irqsave(&opl3->voice_lock, flags); + guard(spinlock_irqsave)(&opl3->voice_lock); if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { for (voice = 0; voice < opl3->max_voices; voice++) { @@ -782,7 +766,6 @@ static void snd_opl3_pitch_ctrl(struct snd_opl3 *opl3, struct snd_midi_channel * snd_opl3_update_pitch(opl3, voice); } } - spin_unlock_irqrestore(&opl3->voice_lock, flags); } /* diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c index 8db77a81476c..d3278428d360 100644 --- a/sound/drivers/opl3/opl3_seq.c +++ b/sound/drivers/opl3/opl3_seq.c @@ -66,16 +66,15 @@ int snd_opl3_synth_setup(struct snd_opl3 * opl3) void snd_opl3_synth_cleanup(struct snd_opl3 * opl3) { - unsigned long flags; struct snd_hwdep *hwdep; /* Stop system timer */ - spin_lock_irqsave(&opl3->sys_timer_lock, flags); - if (opl3->sys_timer_status) { - timer_delete(&opl3->tlist); - opl3->sys_timer_status = 0; + scoped_guard(spinlock_irq, &opl3->sys_timer_lock) { + if (opl3->sys_timer_status) { + timer_delete(&opl3->tlist); + opl3->sys_timer_status = 0; + } } - spin_unlock_irqrestore(&opl3->sys_timer_lock, flags); snd_opl3_reset(opl3); hwdep = opl3->hwdep; |