]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: emu8000: Use guard() for spin locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 14:52:54 +0000 (16:52 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:53:02 +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/20250829145300.5460-15-tiwai@suse.de
sound/isa/sb/emu8000.c
sound/isa/sb/emu8000_pcm.c

index 312b217491d4ecfd17595969922e5b44b9e09f3a..12c296ee34ecf796bbc956d59eec30fa267a2298 100644 (file)
 /* Write a word */
 void snd_emu8000_poke(struct snd_emu8000 *emu, unsigned int port, unsigned int reg, unsigned int val)
 {
-       unsigned long flags;
-       spin_lock_irqsave(&emu->reg_lock, flags);
+       guard(spinlock_irqsave)(&emu->reg_lock);
        if (reg != emu->last_reg) {
                outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */
                emu->last_reg = reg;
        }
        outw((unsigned short)val, port); /* Send data */
-       spin_unlock_irqrestore(&emu->reg_lock, flags);
 }
 
 /* Read a word */
 unsigned short snd_emu8000_peek(struct snd_emu8000 *emu, unsigned int port, unsigned int reg)
 {
-       unsigned short res;
-       unsigned long flags;
-       spin_lock_irqsave(&emu->reg_lock, flags);
+       guard(spinlock_irqsave)(&emu->reg_lock);
        if (reg != emu->last_reg) {
                outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */
                emu->last_reg = reg;
        }
-       res = inw(port);        /* Read data */
-       spin_unlock_irqrestore(&emu->reg_lock, flags);
-       return res;
+       return inw(port);       /* Read data */
 }
 
 /* Write a double word */
 void snd_emu8000_poke_dw(struct snd_emu8000 *emu, unsigned int port, unsigned int reg, unsigned int val)
 {
-       unsigned long flags;
-       spin_lock_irqsave(&emu->reg_lock, flags);
+       guard(spinlock_irqsave)(&emu->reg_lock);
        if (reg != emu->last_reg) {
                outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */
                emu->last_reg = reg;
        }
        outw((unsigned short)val, port); /* Send low word of data */
        outw((unsigned short)(val>>16), port+2); /* Send high word of data */
-       spin_unlock_irqrestore(&emu->reg_lock, flags);
 }
 
 /* Read a double word */
 unsigned int snd_emu8000_peek_dw(struct snd_emu8000 *emu, unsigned int port, unsigned int reg)
 {
        unsigned short low;
-       unsigned int res;
-       unsigned long flags;
-       spin_lock_irqsave(&emu->reg_lock, flags);
+
+       guard(spinlock_irqsave)(&emu->reg_lock);
        if (reg != emu->last_reg) {
                outw((unsigned short)reg, EMU8000_PTR(emu)); /* Set register */
                emu->last_reg = reg;
        }
        low = inw(port);        /* Read low word of data */
-       res = low + (inw(port+2) << 16);
-       spin_unlock_irqrestore(&emu->reg_lock, flags);
-       return res;
+       return low + (inw(port+2) << 16);
 }
 
 /*
@@ -456,8 +445,6 @@ skip_detect:
 /*exported*/ void
 snd_emu8000_init_fm(struct snd_emu8000 *emu)
 {
-       unsigned long flags;
-
        /* Initialize the last two channels for DRAM refresh and producing
           the reverb and chorus effects for Yamaha OPL-3 synthesizer */
 
@@ -479,12 +466,12 @@ snd_emu8000_init_fm(struct snd_emu8000 *emu)
 
        snd_emu8000_poke((emu), EMU8000_DATA0(emu), EMU8000_CMD(1, (30)), 0);
 
-       spin_lock_irqsave(&emu->reg_lock, flags);
-       while (!(inw(EMU8000_PTR(emu)) & 0x1000))
-               ;
-       while ((inw(EMU8000_PTR(emu)) & 0x1000))
-               ;
-       spin_unlock_irqrestore(&emu->reg_lock, flags);
+       scoped_guard(spinlock_irqsave, &emu->reg_lock) {
+               while (!(inw(EMU8000_PTR(emu)) & 0x1000))
+                       ;
+               while ((inw(EMU8000_PTR(emu)) & 0x1000))
+                       ;
+       }
        snd_emu8000_poke((emu), EMU8000_DATA0(emu), EMU8000_CMD(1, (30)), 0x4828);
        /* this is really odd part.. */
        outb(0x3C, EMU8000_PTR(emu));
@@ -838,20 +825,19 @@ static int mixer_bass_treble_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
 static int mixer_bass_treble_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_emu8000 *emu = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
        int change;
        unsigned short val1;
        
        val1 = ucontrol->value.integer.value[0] % 12;
-       spin_lock_irqsave(&emu->control_lock, flags);
-       if (kcontrol->private_value) {
-               change = val1 != emu->treble_level;
-               emu->treble_level = val1;
-       } else {
-               change = val1 != emu->bass_level;
-               emu->bass_level = val1;
+       scoped_guard(spinlock_irqsave, &emu->control_lock) {
+               if (kcontrol->private_value) {
+                       change = val1 != emu->treble_level;
+                       emu->treble_level = val1;
+               } else {
+                       change = val1 != emu->bass_level;
+                       emu->bass_level = val1;
+               }
        }
-       spin_unlock_irqrestore(&emu->control_lock, flags);
        snd_emu8000_update_equalizer(emu);
        return change;
 }
@@ -899,21 +885,20 @@ static int mixer_chorus_reverb_get(struct snd_kcontrol *kcontrol, struct snd_ctl
 static int mixer_chorus_reverb_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_emu8000 *emu = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
        int change;
        unsigned short val1;
        
-       spin_lock_irqsave(&emu->control_lock, flags);
-       if (kcontrol->private_value) {
-               val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_CHORUS_NUMBERS;
-               change = val1 != emu->chorus_mode;
-               emu->chorus_mode = val1;
-       } else {
-               val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_REVERB_NUMBERS;
-               change = val1 != emu->reverb_mode;
-               emu->reverb_mode = val1;
+       scoped_guard(spinlock_irqsave, &emu->control_lock) {
+               if (kcontrol->private_value) {
+                       val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_CHORUS_NUMBERS;
+                       change = val1 != emu->chorus_mode;
+                       emu->chorus_mode = val1;
+               } else {
+                       val1 = ucontrol->value.integer.value[0] % SNDRV_EMU8000_REVERB_NUMBERS;
+                       change = val1 != emu->reverb_mode;
+                       emu->reverb_mode = val1;
+               }
        }
-       spin_unlock_irqrestore(&emu->control_lock, flags);
        if (change) {
                if (kcontrol->private_value)
                        snd_emu8000_update_chorus_mode(emu);
@@ -966,20 +951,19 @@ static int mixer_fm_depth_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
 static int mixer_fm_depth_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_emu8000 *emu = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
        int change;
        unsigned short val1;
        
        val1 = ucontrol->value.integer.value[0] % 256;
-       spin_lock_irqsave(&emu->control_lock, flags);
-       if (kcontrol->private_value) {
-               change = val1 != emu->fm_chorus_depth;
-               emu->fm_chorus_depth = val1;
-       } else {
-               change = val1 != emu->fm_reverb_depth;
-               emu->fm_reverb_depth = val1;
+       scoped_guard(spinlock_irqsave, &emu->control_lock) {
+               if (kcontrol->private_value) {
+                       change = val1 != emu->fm_chorus_depth;
+                       emu->fm_chorus_depth = val1;
+               } else {
+                       change = val1 != emu->fm_reverb_depth;
+                       emu->fm_reverb_depth = val1;
+               }
        }
-       spin_unlock_irqrestore(&emu->control_lock, flags);
        if (change)
                snd_emu8000_init_fm(emu);
        return change;
index 215bbcd0360e6bf310655a7700b5bbd088646f17..656a655d618d546069f810f2790793e9c71b7ebd 100644 (file)
@@ -184,28 +184,30 @@ static void emu8k_pcm_timer_func(struct timer_list *t)
 {
        struct snd_emu8k_pcm *rec = timer_container_of(rec, t, timer);
        int ptr, delta;
+       bool period_elapsed = false;
+
+       scoped_guard(spinlock, &rec->timer_lock) {
+               /* update the current pointer */
+               ptr = emu8k_get_curpos(rec, 0);
+               if (ptr < rec->last_ptr)
+                       delta = ptr + rec->buf_size - rec->last_ptr;
+               else
+                       delta = ptr - rec->last_ptr;
+               rec->period_pos += delta;
+               rec->last_ptr = ptr;
+
+               /* reprogram timer */
+               mod_timer(&rec->timer, jiffies + 1);
 
-       spin_lock(&rec->timer_lock);
-       /* update the current pointer */
-       ptr = emu8k_get_curpos(rec, 0);
-       if (ptr < rec->last_ptr)
-               delta = ptr + rec->buf_size - rec->last_ptr;
-       else
-               delta = ptr - rec->last_ptr;
-       rec->period_pos += delta;
-       rec->last_ptr = ptr;
-
-       /* reprogram timer */
-       mod_timer(&rec->timer, jiffies + 1);
+               /* update period */
+               if (rec->period_pos >= (int)rec->period_size) {
+                       rec->period_pos %= rec->period_size;
+                       period_elapsed = true;
+               }
+       }
 
-       /* update period */
-       if (rec->period_pos >= (int)rec->period_size) {
-               rec->period_pos %= rec->period_size;
-               spin_unlock(&rec->timer_lock);
+       if (period_elapsed)
                snd_pcm_period_elapsed(rec->substream);
-               return;
-       }
-       spin_unlock(&rec->timer_lock);
 }
 
 
@@ -321,7 +323,6 @@ static void setup_voice(struct snd_emu8k_pcm *rec, int ch)
  */
 static void start_voice(struct snd_emu8k_pcm *rec, int ch)
 {
-       unsigned long flags;
        struct snd_emu8000 *hw = rec->emu;
        unsigned int temp, aux;
        int pt = calc_pitch_target(rec->pitch);
@@ -343,12 +344,11 @@ static void start_voice(struct snd_emu8k_pcm *rec, int ch)
        EMU8000_CPF_WRITE(hw, ch, pt << 16);
 
        /* start timer */
-       spin_lock_irqsave(&rec->timer_lock, flags);
+       guard(spinlock_irqsave)(&rec->timer_lock);
        if (! rec->timer_running) {
                mod_timer(&rec->timer, jiffies + 1);
                rec->timer_running = 1;
        }
-       spin_unlock_irqrestore(&rec->timer_lock, flags);
 }
 
 /*
@@ -356,18 +356,16 @@ static void start_voice(struct snd_emu8k_pcm *rec, int ch)
  */
 static void stop_voice(struct snd_emu8k_pcm *rec, int ch)
 {
-       unsigned long flags;
        struct snd_emu8000 *hw = rec->emu;
 
        EMU8000_DCYSUSV_WRITE(hw, ch, 0x807F);
 
        /* stop timer */
-       spin_lock_irqsave(&rec->timer_lock, flags);
+       guard(spinlock_irqsave)(&rec->timer_lock);
        if (rec->timer_running) {
                timer_delete(&rec->timer);
                rec->timer_running = 0;
        }
-       spin_unlock_irqrestore(&rec->timer_lock, flags);
 }
 
 static int emu8k_pcm_trigger(struct snd_pcm_substream *subs, int cmd)