]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: via82xx: Use guard() for spin locks
authorTakashi Iwai <tiwai@suse.de>
Fri, 29 Aug 2025 14:43:34 +0000 (16:43 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 1 Sep 2025 11:52:43 +0000 (13:52 +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/20250829144342.4290-60-tiwai@suse.de
sound/pci/via82xx.c
sound/pci/via82xx_modem.c

index 0753c0c73f514395100b1921120011db2a215185..2b0f9e38863eddd70acecdfec796dd2703edfbef 100644 (file)
@@ -628,7 +628,7 @@ static irqreturn_t snd_via686_interrupt(int irq, void *dev_id)
        }
 
        /* check status for each stream */
-       spin_lock(&chip->reg_lock);
+       guard(spinlock)(&chip->reg_lock);
        for (i = 0; i < chip->num_devs; i++) {
                struct viadev *viadev = &chip->devs[i];
                unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
@@ -652,7 +652,6 @@ static irqreturn_t snd_via686_interrupt(int irq, void *dev_id)
                }
                outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
        }
-       spin_unlock(&chip->reg_lock);
        return IRQ_HANDLED;
 }
 
@@ -667,7 +666,7 @@ static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id)
        int irqreturn = 0;
 
        /* check status for each stream */
-       spin_lock(&chip->reg_lock);
+       guard(spinlock)(&chip->reg_lock);
        status = inl(VIAREG(chip, SGD_SHADOW));
 
        for (i = 0; i < chip->num_devs; i++) {
@@ -706,7 +705,6 @@ static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id)
                outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
                irqreturn = 1;
        }
-       spin_unlock(&chip->reg_lock);
        return IRQ_RETVAL(irqreturn);
 }
 
@@ -833,7 +831,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
        if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
                return 0;
 
-       spin_lock(&chip->reg_lock);
+       guard(spinlock)(&chip->reg_lock);
        count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff;
        /* The via686a does not have the current index register,
         * so we need to calculate the index from CURR_PTR.
@@ -845,7 +843,6 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
                idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
        res = calc_linear_pos(chip, viadev, idx, count);
        viadev->lastpos = res; /* remember the last position */
-       spin_unlock(&chip->reg_lock);
 
        return bytes_to_frames(substream->runtime, res);
 }
@@ -863,7 +860,7 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *subst
        if (snd_BUG_ON(!viadev->tbl_entries))
                return 0;
 
-       spin_lock(&chip->reg_lock);
+       guard(spinlock)(&chip->reg_lock);
        count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
        status = viadev->in_interrupt;
        if (!status)
@@ -904,7 +901,6 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *subst
        }                           
 unlock:
        viadev->lastpos = res;
-       spin_unlock(&chip->reg_lock);
 
        return bytes_to_frames(substream->runtime, res);
 }
@@ -997,7 +993,7 @@ static int via_lock_rate(struct via_rate_lock *rec, int rate)
 {
        int changed = 0;
 
-       spin_lock_irq(&rec->lock);
+       guard(spinlock_irq)(&rec->lock);
        if (rec->rate != rate) {
                if (rec->rate && rec->used > 1) /* already set */
                        changed = -EINVAL;
@@ -1006,7 +1002,6 @@ static int via_lock_rate(struct via_rate_lock *rec, int rate)
                        changed = 1;
                }
        }
-       spin_unlock_irq(&rec->lock);
        return changed;
 }
 
@@ -1167,33 +1162,33 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
        
        /* set the hw rate condition */
        ratep = &chip->rates[viadev->direction];
-       spin_lock_irq(&ratep->lock);
-       ratep->used++;
-       if (chip->spdif_on && viadev->reg_offset == 0x30) {
-               /* DXS#3 and spdif is on */
-               runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF];
-               snd_pcm_limit_hw_rates(runtime);
-       } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) {
-               /* fixed DXS playback rate */
-               runtime->hw.rates = SNDRV_PCM_RATE_48000;
-               runtime->hw.rate_min = runtime->hw.rate_max = 48000;
-       } else if (chip->dxs_src && viadev->reg_offset < 0x40) {
-               /* use full SRC capabilities of DXS */
-               runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS |
-                                    SNDRV_PCM_RATE_8000_48000);
-               runtime->hw.rate_min = 8000;
-               runtime->hw.rate_max = 48000;
-               use_src = true;
-       } else if (! ratep->rate) {
-               int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
-               runtime->hw.rates = chip->ac97->rates[idx];
-               snd_pcm_limit_hw_rates(runtime);
-       } else {
-               /* a fixed rate */
-               runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
-               runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate;
+       scoped_guard(spinlock_irq, &ratep->lock) {
+               ratep->used++;
+               if (chip->spdif_on && viadev->reg_offset == 0x30) {
+                       /* DXS#3 and spdif is on */
+                       runtime->hw.rates = chip->ac97->rates[AC97_RATES_SPDIF];
+                       snd_pcm_limit_hw_rates(runtime);
+               } else if (chip->dxs_fixed && viadev->reg_offset < 0x40) {
+                       /* fixed DXS playback rate */
+                       runtime->hw.rates = SNDRV_PCM_RATE_48000;
+                       runtime->hw.rate_min = runtime->hw.rate_max = 48000;
+               } else if (chip->dxs_src && viadev->reg_offset < 0x40) {
+                       /* use full SRC capabilities of DXS */
+                       runtime->hw.rates = (SNDRV_PCM_RATE_CONTINUOUS |
+                                            SNDRV_PCM_RATE_8000_48000);
+                       runtime->hw.rate_min = 8000;
+                       runtime->hw.rate_max = 48000;
+                       use_src = true;
+               } else if (!ratep->rate) {
+                       int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
+                       runtime->hw.rates = chip->ac97->rates[idx];
+                       snd_pcm_limit_hw_rates(runtime);
+               } else {
+                       /* a fixed rate */
+                       runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
+                       runtime->hw.rate_max = runtime->hw.rate_min = ratep->rate;
+               }
        }
-       spin_unlock_irq(&ratep->lock);
 
        /* we may remove following constaint when we modify table entries
           in interrupt */
@@ -1311,11 +1306,11 @@ static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream)
 
        /* release the rate lock */
        ratep = &chip->rates[viadev->direction];
-       spin_lock_irq(&ratep->lock);
-       ratep->used--;
-       if (! ratep->used)
-               ratep->rate = 0;
-       spin_unlock_irq(&ratep->lock);
+       scoped_guard(spinlock_irq, &ratep->lock) {
+               ratep->used--;
+               if (!ratep->used)
+                       ratep->rate = 0;
+       }
        if (! ratep->rate) {
                if (! viadev->direction) {
                        snd_ac97_update_power(chip->ac97,
@@ -1606,14 +1601,13 @@ static int snd_via8233_capture_source_put(struct snd_kcontrol *kcontrol,
        unsigned long port = chip->port + (kcontrol->id.index ? (VIA_REG_CAPTURE_CHANNEL + 0x10) : VIA_REG_CAPTURE_CHANNEL);
        u8 val, oval;
 
-       spin_lock_irq(&chip->reg_lock);
+       guard(spinlock_irq)(&chip->reg_lock);
        oval = inb(port);
        val = oval & ~VIA_REG_CAPTURE_CHANNEL_MIC;
        if (ucontrol->value.enumerated.item[0])
                val |= VIA_REG_CAPTURE_CHANNEL_MIC;
        if (val != oval)
                outb(val, port);
-       spin_unlock_irq(&chip->reg_lock);
        return val != oval;
 }
 
index 12a8c620724d2ad55244795a1c569790b7ffd9fd..6ce2cd88cda6c2dd1967321c74a38917a7ec8338 100644 (file)
@@ -483,7 +483,7 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id)
 // _skip_sgd:
 
        /* check status for each stream */
-       spin_lock(&chip->reg_lock);
+       guard(spinlock)(&chip->reg_lock);
        for (i = 0; i < chip->num_devs; i++) {
                struct viadev *viadev = &chip->devs[i];
                unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
@@ -497,7 +497,6 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id)
                }
                outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
        }
-       spin_unlock(&chip->reg_lock);
        return IRQ_HANDLED;
 }
 
@@ -616,7 +615,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
        if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
                return 0;
 
-       spin_lock(&chip->reg_lock);
+       guard(spinlock)(&chip->reg_lock);
        count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)) & 0xffffff;
        /* The via686a does not have the current index register,
         * so we need to calculate the index from CURR_PTR.
@@ -628,7 +627,6 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
                idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) %
                        viadev->tbl_entries;
        res = calc_linear_pos(chip, viadev, idx, count);
-       spin_unlock(&chip->reg_lock);
 
        return bytes_to_frames(substream->runtime, res);
 }