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

index 26c515ec76e9b26fe93e1bff6eb230d89242fddb..d16acf83668a1043c65243a72cf1e1d88ab65967 100644 (file)
@@ -568,25 +568,19 @@ static void snd_korg1212_SendStop(struct snd_korg1212 *korg1212)
 
 static void snd_korg1212_SendStopAndWait(struct snd_korg1212 *korg1212)
 {
-       unsigned long flags;
-       spin_lock_irqsave(&korg1212->lock, flags);
-       snd_korg1212_SendStop(korg1212);
-       spin_unlock_irqrestore(&korg1212->lock, flags);
+       scoped_guard(spinlock_irqsave, &korg1212->lock) {
+               snd_korg1212_SendStop(korg1212);
+       }
        wait_event_timeout(korg1212->wait, !korg1212->dsp_stop_processing, HZ);
 }
 
 static int snd_korg1212_TurnOnIdleMonitor(struct snd_korg1212 *korg1212)
 {
-       unsigned long flags;
-       int rc;
-
         udelay(INTERCOMMAND_DELAY);
-       spin_lock_irqsave(&korg1212->lock, flags);
+       guard(spinlock_irqsave)(&korg1212->lock);
         korg1212->idleMonitorOn = 1;
-        rc = snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode,
-                                         K1212_MODE_MonitorOn, 0, 0, 0);
-        spin_unlock_irqrestore(&korg1212->lock, flags);
-       return rc;
+       return snd_korg1212_Send1212Command(korg1212, K1212_DB_SelectPlayMode,
+                                           K1212_MODE_MonitorOn, 0, 0, 0);
 }
 
 static void snd_korg1212_TurnOffIdleMonitor(struct snd_korg1212 *korg1212)
@@ -838,7 +832,6 @@ static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212)
         u16       controlValue;    // this keeps the current value to be written to
                                    //  the card's eeprom control register.
         u16       count;
-       unsigned long flags;
 
        K1212_DEBUG_PRINTK("K1212_DEBUG: WriteADCSensivity [%s]\n",
                           stateName[korg1212->cardState]);
@@ -859,7 +852,7 @@ static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212)
         } else
                 monModeSet = 0;
 
-       spin_lock_irqsave(&korg1212->lock, flags);
+       guard(spinlock_irqsave)(&korg1212->lock);
 
         // ----------------------------------------------------------------------------
         // we are about to send new values to the card, so clear the new values queued
@@ -968,8 +961,6 @@ static int snd_korg1212_WriteADCSensitivity(struct snd_korg1212 *korg1212)
                                           rc, stateName[korg1212->cardState]);
         }
 
-       spin_unlock_irqrestore(&korg1212->lock, flags);
-
         return 1;
 }
 
@@ -1061,7 +1052,7 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id)
         if (!doorbellValue)
                return IRQ_NONE;
 
-       spin_lock(&korg1212->lock);
+       guard(spinlock)(&korg1212->lock);
 
        writel(doorbellValue, korg1212->inDoorbellPtr);
 
@@ -1139,8 +1130,6 @@ static irqreturn_t snd_korg1212_interrupt(int irq, void *dev_id)
 
        korg1212->inIRQ--;
 
-       spin_unlock(&korg1212->lock);
-
        return IRQ_HANDLED;
 }
 
@@ -1326,7 +1315,6 @@ static void snd_korg1212_free_pcm(struct snd_pcm *pcm)
 
 static int snd_korg1212_playback_open(struct snd_pcm_substream *substream)
 {
-        unsigned long flags;
         struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
         struct snd_pcm_runtime *runtime = substream->runtime;
 
@@ -1338,15 +1326,13 @@ static int snd_korg1212_playback_open(struct snd_pcm_substream *substream)
         runtime->hw = snd_korg1212_playback_info;
        snd_pcm_set_runtime_buffer(substream, korg1212->dma_play);
 
-        spin_lock_irqsave(&korg1212->lock, flags);
-
-        korg1212->playback_substream = substream;
-       korg1212->playback_pid = current->pid;
-        korg1212->periodsize = K1212_PERIODS;
-       korg1212->channels = K1212_CHANNELS;
-       korg1212->errorcnt = 0;
-
-        spin_unlock_irqrestore(&korg1212->lock, flags);
+       scoped_guard(spinlock_irqsave, &korg1212->lock) {
+               korg1212->playback_substream = substream;
+               korg1212->playback_pid = current->pid;
+               korg1212->periodsize = K1212_PERIODS;
+               korg1212->channels = K1212_CHANNELS;
+               korg1212->errorcnt = 0;
+       }
 
        snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
                                     kPlayBufferFrames);
@@ -1357,7 +1343,6 @@ static int snd_korg1212_playback_open(struct snd_pcm_substream *substream)
 
 static int snd_korg1212_capture_open(struct snd_pcm_substream *substream)
 {
-        unsigned long flags;
         struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
         struct snd_pcm_runtime *runtime = substream->runtime;
 
@@ -1369,14 +1354,12 @@ static int snd_korg1212_capture_open(struct snd_pcm_substream *substream)
         runtime->hw = snd_korg1212_capture_info;
        snd_pcm_set_runtime_buffer(substream, korg1212->dma_rec);
 
-        spin_lock_irqsave(&korg1212->lock, flags);
-
-        korg1212->capture_substream = substream;
-       korg1212->capture_pid = current->pid;
-        korg1212->periodsize = K1212_PERIODS;
-       korg1212->channels = K1212_CHANNELS;
-
-        spin_unlock_irqrestore(&korg1212->lock, flags);
+       scoped_guard(spinlock_irqsave, &korg1212->lock) {
+               korg1212->capture_substream = substream;
+               korg1212->capture_pid = current->pid;
+               korg1212->periodsize = K1212_PERIODS;
+               korg1212->channels = K1212_CHANNELS;
+       }
 
        snd_pcm_hw_constraint_single(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
                                     kPlayBufferFrames);
@@ -1385,7 +1368,6 @@ static int snd_korg1212_capture_open(struct snd_pcm_substream *substream)
 
 static int snd_korg1212_playback_close(struct snd_pcm_substream *substream)
 {
-        unsigned long flags;
         struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
 
        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_playback_close [%s]\n",
@@ -1393,13 +1375,11 @@ static int snd_korg1212_playback_close(struct snd_pcm_substream *substream)
 
        snd_korg1212_silence(korg1212, 0, K1212_MAX_SAMPLES, 0, korg1212->channels * 2);
 
-        spin_lock_irqsave(&korg1212->lock, flags);
-
-       korg1212->playback_pid = -1;
-        korg1212->playback_substream = NULL;
-        korg1212->periodsize = 0;
-
-        spin_unlock_irqrestore(&korg1212->lock, flags);
+       scoped_guard(spinlock_irqsave, &korg1212->lock) {
+               korg1212->playback_pid = -1;
+               korg1212->playback_substream = NULL;
+               korg1212->periodsize = 0;
+       }
 
        snd_korg1212_CloseCard(korg1212);
         return 0;
@@ -1407,19 +1387,16 @@ static int snd_korg1212_playback_close(struct snd_pcm_substream *substream)
 
 static int snd_korg1212_capture_close(struct snd_pcm_substream *substream)
 {
-        unsigned long flags;
         struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
 
        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_capture_close [%s]\n",
                           stateName[korg1212->cardState]);
 
-        spin_lock_irqsave(&korg1212->lock, flags);
-
-       korg1212->capture_pid = -1;
-        korg1212->capture_substream = NULL;
-        korg1212->periodsize = 0;
-
-        spin_unlock_irqrestore(&korg1212->lock, flags);
+       scoped_guard(spinlock_irqsave, &korg1212->lock) {
+               korg1212->capture_pid = -1;
+               korg1212->capture_substream = NULL;
+               korg1212->periodsize = 0;
+       }
 
        snd_korg1212_CloseCard(korg1212);
         return 0;
@@ -1445,7 +1422,6 @@ static int snd_korg1212_ioctl(struct snd_pcm_substream *substream,
 static int snd_korg1212_hw_params(struct snd_pcm_substream *substream,
                              struct snd_pcm_hw_params *params)
 {
-        unsigned long flags;
         struct snd_korg1212 *korg1212 = snd_pcm_substream_chip(substream);
         int err;
        pid_t this_pid;
@@ -1454,7 +1430,7 @@ static int snd_korg1212_hw_params(struct snd_pcm_substream *substream,
        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_hw_params [%s]\n",
                           stateName[korg1212->cardState]);
 
-        spin_lock_irqsave(&korg1212->lock, flags);
+       guard(spinlock_irqsave)(&korg1212->lock);
 
        if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                this_pid = korg1212->playback_pid;
@@ -1472,26 +1448,20 @@ static int snd_korg1212_hw_params(struct snd_pcm_substream *substream,
                 */
 
                if ((int)params_rate(params) != korg1212->clkRate) {
-                       spin_unlock_irqrestore(&korg1212->lock, flags);
                        _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
                        return -EBUSY;
                }
 
-               spin_unlock_irqrestore(&korg1212->lock, flags);
                return 0;
        }
 
        err = snd_korg1212_SetRate(korg1212, params_rate(params));
-       if (err < 0) {
-                spin_unlock_irqrestore(&korg1212->lock, flags);
+       if (err < 0)
                 return err;
-        }
 
        korg1212->channels = params_channels(params);
         korg1212->periodsize = K1212_PERIOD_BYTES;
 
-        spin_unlock_irqrestore(&korg1212->lock, flags);
-
         return 0;
 }
 
@@ -1511,15 +1481,13 @@ static int snd_korg1212_prepare(struct snd_pcm_substream *substream)
        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_prepare [%s]\n",
                           stateName[korg1212->cardState]);
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
        korg1212->dsp_stop_processing = 0;
 
         rc = snd_korg1212_SetupForPlay(korg1212);
 
         korg1212->currentBuffer = 0;
 
-        spin_unlock_irq(&korg1212->lock);
-
        return rc ? -EINVAL : 0;
 }
 
@@ -1532,7 +1500,7 @@ static int snd_korg1212_trigger(struct snd_pcm_substream *substream,
        K1212_DEBUG_PRINTK("K1212_DEBUG: snd_korg1212_trigger [%s] cmd=%d\n",
                           stateName[korg1212->cardState], cmd);
 
-       spin_lock(&korg1212->lock);
+       guard(spinlock)(&korg1212->lock);
         switch (cmd) {
                 case SNDRV_PCM_TRIGGER_START:
 /*
@@ -1560,7 +1528,6 @@ static int snd_korg1212_trigger(struct snd_pcm_substream *substream,
                        rc = 1;
                        break;
         }
-       spin_unlock(&korg1212->lock);
         return rc ? -EINVAL : 0;
 }
 
@@ -1660,15 +1627,13 @@ static int snd_korg1212_control_phase_get(struct snd_kcontrol *kcontrol,
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
        int i = kcontrol->private_value;
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
         u->value.integer.value[0] = korg1212->volumePhase[i];
 
        if (i >= 8)
                u->value.integer.value[1] = korg1212->volumePhase[i+1];
 
-       spin_unlock_irq(&korg1212->lock);
-
         return 0;
 }
 
@@ -1679,7 +1644,7 @@ static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol,
         int change = 0;
         int i, val;
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
        i = kcontrol->private_value;
 
@@ -1705,8 +1670,6 @@ static int snd_korg1212_control_phase_put(struct snd_kcontrol *kcontrol,
                }
        }
 
-       spin_unlock_irq(&korg1212->lock);
-
         return change;
 }
 
@@ -1726,7 +1689,7 @@ static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol,
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
         int i;
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
        i = kcontrol->private_value;
         u->value.integer.value[0] = abs(korg1212->sharedBufferPtr->volumeData[i]);
@@ -1734,8 +1697,6 @@ static int snd_korg1212_control_volume_get(struct snd_kcontrol *kcontrol,
        if (i >= 8) 
                 u->value.integer.value[1] = abs(korg1212->sharedBufferPtr->volumeData[i+1]);
 
-        spin_unlock_irq(&korg1212->lock);
-
         return 0;
 }
 
@@ -1747,7 +1708,7 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol,
         int i;
        int val;
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
        i = kcontrol->private_value;
 
@@ -1773,8 +1734,6 @@ static int snd_korg1212_control_volume_put(struct snd_kcontrol *kcontrol,
                }
        }
 
-       spin_unlock_irq(&korg1212->lock);
-
         return change;
 }
 
@@ -1792,7 +1751,7 @@ static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol,
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
         int i;
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
        i = kcontrol->private_value;
        u->value.enumerated.item[0] = korg1212->sharedBufferPtr->routeData[i];
@@ -1800,8 +1759,6 @@ static int snd_korg1212_control_route_get(struct snd_kcontrol *kcontrol,
        if (i >= 8) 
                u->value.enumerated.item[1] = korg1212->sharedBufferPtr->routeData[i+1];
 
-        spin_unlock_irq(&korg1212->lock);
-
         return 0;
 }
 
@@ -1811,7 +1768,7 @@ static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol,
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
         int change = 0, i;
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
        i = kcontrol->private_value;
 
@@ -1831,8 +1788,6 @@ static int snd_korg1212_control_route_put(struct snd_kcontrol *kcontrol,
                }
        }
 
-       spin_unlock_irq(&korg1212->lock);
-
         return change;
 }
 
@@ -1851,13 +1806,11 @@ static int snd_korg1212_control_get(struct snd_kcontrol *kcontrol,
 {
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
         u->value.integer.value[0] = korg1212->leftADCInSens;
         u->value.integer.value[1] = korg1212->rightADCInSens;
 
-       spin_unlock_irq(&korg1212->lock);
-
         return 0;
 }
 
@@ -1867,22 +1820,20 @@ static int snd_korg1212_control_put(struct snd_kcontrol *kcontrol,
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
         int change = 0;
 
-       spin_lock_irq(&korg1212->lock);
-
-       if (u->value.integer.value[0] >= k1212MinADCSens &&
-           u->value.integer.value[0] <= k1212MaxADCSens &&
-           u->value.integer.value[0] != korg1212->leftADCInSens) {
-                korg1212->leftADCInSens = u->value.integer.value[0];
-                change = 1;
-        }
-       if (u->value.integer.value[1] >= k1212MinADCSens &&
-           u->value.integer.value[1] <= k1212MaxADCSens &&
-           u->value.integer.value[1] != korg1212->rightADCInSens) {
-                korg1212->rightADCInSens = u->value.integer.value[1];
-                change = 1;
-        }
-
-       spin_unlock_irq(&korg1212->lock);
+       scoped_guard(spinlock_irq, &korg1212->lock) {
+               if (u->value.integer.value[0] >= k1212MinADCSens &&
+                   u->value.integer.value[0] <= k1212MaxADCSens &&
+                   u->value.integer.value[0] != korg1212->leftADCInSens) {
+                       korg1212->leftADCInSens = u->value.integer.value[0];
+                       change = 1;
+               }
+               if (u->value.integer.value[1] >= k1212MinADCSens &&
+                   u->value.integer.value[1] <= k1212MaxADCSens &&
+                   u->value.integer.value[1] != korg1212->rightADCInSens) {
+                       korg1212->rightADCInSens = u->value.integer.value[1];
+                       change = 1;
+               }
+       }
 
         if (change)
                 snd_korg1212_WriteADCSensitivity(korg1212);
@@ -1901,11 +1852,9 @@ static int snd_korg1212_control_sync_get(struct snd_kcontrol *kcontrol,
 {
        struct snd_korg1212 *korg1212 = snd_kcontrol_chip(kcontrol);
 
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
 
        ucontrol->value.enumerated.item[0] = korg1212->clkSource;
-
-       spin_unlock_irq(&korg1212->lock);
        return 0;
 }
 
@@ -1917,10 +1866,9 @@ static int snd_korg1212_control_sync_put(struct snd_kcontrol *kcontrol,
        int change;
 
        val = ucontrol->value.enumerated.item[0] % 3;
-       spin_lock_irq(&korg1212->lock);
+       guard(spinlock_irq)(&korg1212->lock);
        change = val != korg1212->clkSource;
         snd_korg1212_SetClockSource(korg1212, val);
-       spin_unlock_irq(&korg1212->lock);
        return change;
 }