]> www.infradead.org Git - users/hch/misc.git/commitdiff
ALSA: firewire: tascam: Use guard() for mutex locks
authorTakashi Iwai <tiwai@suse.de>
Thu, 28 Aug 2025 13:27:11 +0000 (15:27 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sat, 30 Aug 2025 08:02:21 +0000 (10:02 +0200)
Replace the manual mutex lock/unlock pairs with guard() for code
simplification.

Only code refactoring, and no behavior change.

Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250828132802.9032-8-tiwai@suse.de
sound/firewire/tascam/tascam-pcm.c
sound/firewire/tascam/tascam.c

index a73003ac11e67c0753290600ba9c3dfe6dc345f7..d885fef0c8cae73a93d132850b21e94abc80cb46 100644 (file)
@@ -59,43 +59,35 @@ static int pcm_open(struct snd_pcm_substream *substream)
        if (err < 0)
                goto err_locked;
 
-       mutex_lock(&tscm->mutex);
-
-       // When source of clock is not internal or any stream is reserved for
-       // transmission of PCM frames, the available sampling rate is limited
-       // at current one.
-       if (clock != SND_TSCM_CLOCK_INTERNAL || tscm->substreams_counter > 0) {
-               unsigned int frames_per_period = d->events_per_period;
-               unsigned int frames_per_buffer = d->events_per_buffer;
-               unsigned int rate;
-
-               err = snd_tscm_stream_get_rate(tscm, &rate);
-               if (err < 0) {
-                       mutex_unlock(&tscm->mutex);
-                       goto err_locked;
-               }
-               substream->runtime->hw.rate_min = rate;
-               substream->runtime->hw.rate_max = rate;
-
-               err = snd_pcm_hw_constraint_minmax(substream->runtime,
-                                       SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
-                                       frames_per_period, frames_per_period);
-               if (err < 0) {
-                       mutex_unlock(&tscm->mutex);
-                       goto err_locked;
-               }
-
-               err = snd_pcm_hw_constraint_minmax(substream->runtime,
-                                       SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
-                                       frames_per_buffer, frames_per_buffer);
-               if (err < 0) {
-                       mutex_unlock(&tscm->mutex);
-                       goto err_locked;
+       scoped_guard(mutex, &tscm->mutex) {
+               // When source of clock is not internal or any stream is reserved for
+               // transmission of PCM frames, the available sampling rate is limited
+               // at current one.
+               if (clock != SND_TSCM_CLOCK_INTERNAL || tscm->substreams_counter > 0) {
+                       unsigned int frames_per_period = d->events_per_period;
+                       unsigned int frames_per_buffer = d->events_per_buffer;
+                       unsigned int rate;
+
+                       err = snd_tscm_stream_get_rate(tscm, &rate);
+                       if (err < 0)
+                               goto err_locked;
+                       substream->runtime->hw.rate_min = rate;
+                       substream->runtime->hw.rate_max = rate;
+
+                       err = snd_pcm_hw_constraint_minmax(substream->runtime,
+                                                          SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+                                                          frames_per_period, frames_per_period);
+                       if (err < 0)
+                               goto err_locked;
+
+                       err = snd_pcm_hw_constraint_minmax(substream->runtime,
+                                                          SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+                                                          frames_per_buffer, frames_per_buffer);
+                       if (err < 0)
+                               goto err_locked;
                }
        }
 
-       mutex_unlock(&tscm->mutex);
-
        snd_pcm_set_sync(substream);
 
        return 0;
@@ -124,12 +116,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
                unsigned int frames_per_period = params_period_size(hw_params);
                unsigned int frames_per_buffer = params_buffer_size(hw_params);
 
-               mutex_lock(&tscm->mutex);
+               guard(mutex)(&tscm->mutex);
                err = snd_tscm_stream_reserve_duplex(tscm, rate,
                                        frames_per_period, frames_per_buffer);
                if (err >= 0)
                        ++tscm->substreams_counter;
-               mutex_unlock(&tscm->mutex);
        }
 
        return err;
@@ -139,15 +130,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream)
 {
        struct snd_tscm *tscm = substream->private_data;
 
-       mutex_lock(&tscm->mutex);
+       guard(mutex)(&tscm->mutex);
 
        if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
                --tscm->substreams_counter;
 
        snd_tscm_stream_stop_duplex(tscm);
 
-       mutex_unlock(&tscm->mutex);
-
        return 0;
 }
 
@@ -157,14 +146,12 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
-       mutex_lock(&tscm->mutex);
+       guard(mutex)(&tscm->mutex);
 
        err = snd_tscm_stream_start_duplex(tscm, runtime->rate);
        if (err >= 0)
                amdtp_stream_pcm_prepare(&tscm->tx_stream);
 
-       mutex_unlock(&tscm->mutex);
-
        return err;
 }
 
@@ -174,14 +161,12 @@ static int pcm_playback_prepare(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
-       mutex_lock(&tscm->mutex);
+       guard(mutex)(&tscm->mutex);
 
        err = snd_tscm_stream_start_duplex(tscm, runtime->rate);
        if (err >= 0)
                amdtp_stream_pcm_prepare(&tscm->rx_stream);
 
-       mutex_unlock(&tscm->mutex);
-
        return err;
 }
 
index 4f68bb4c58bcd46d4b17be57c3c69d1ccf40fc7f..f4092df8650c3f9d2f147fcb86e8461f15e7b2c9 100644 (file)
@@ -158,9 +158,8 @@ static void snd_tscm_update(struct fw_unit *unit)
 
        snd_tscm_transaction_reregister(tscm);
 
-       mutex_lock(&tscm->mutex);
+       guard(mutex)(&tscm->mutex);
        snd_tscm_stream_update_duplex(tscm);
-       mutex_unlock(&tscm->mutex);
 }
 
 static void snd_tscm_remove(struct fw_unit *unit)