if (err < 0)
return err;
- mutex_lock(&motu->mutex);
-
- err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
- if (err >= 0) {
- ++motu->substreams_counter;
- err = snd_motu_stream_start_duplex(motu);
- if (err < 0)
- --motu->substreams_counter;
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
+ if (err >= 0) {
+ ++motu->substreams_counter;
+ err = snd_motu_stream_start_duplex(motu);
+ if (err < 0)
+ --motu->substreams_counter;
+ }
}
- mutex_unlock(&motu->mutex);
-
if (err < 0)
snd_motu_stream_lock_release(motu);
{
struct snd_motu *motu = substream->rmidi->private_data;
- mutex_lock(&motu->mutex);
-
- --motu->substreams_counter;
- snd_motu_stream_stop_duplex(motu);
-
- mutex_unlock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
+ --motu->substreams_counter;
+ snd_motu_stream_stop_duplex(motu);
+ }
snd_motu_stream_lock_release(motu);
return 0;
if (err < 0)
return err;
- mutex_lock(&motu->mutex);
-
- err = snd_motu_stream_cache_packet_formats(motu);
- if (err < 0)
- goto err_locked;
-
- err = init_hw_info(motu, substream);
- if (err < 0)
- goto err_locked;
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_cache_packet_formats(motu);
+ if (err < 0)
+ goto err_locked;
- err = snd_motu_protocol_get_clock_source(motu, &src);
- if (err < 0)
- goto err_locked;
-
- // 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 ((src != SND_MOTU_CLOCK_SOURCE_INTERNAL &&
- src != SND_MOTU_CLOCK_SOURCE_SPH) ||
- (motu->substreams_counter > 0 && d->events_per_period > 0)) {
- unsigned int frames_per_period = d->events_per_period;
- unsigned int frames_per_buffer = d->events_per_buffer;
- unsigned int rate;
-
- err = snd_motu_protocol_get_clock_rate(motu, &rate);
+ err = init_hw_info(motu, substream);
if (err < 0)
goto err_locked;
- substream->runtime->hw.rate_min = rate;
- substream->runtime->hw.rate_max = rate;
+ err = snd_motu_protocol_get_clock_source(motu, &src);
+ if (err < 0)
+ goto err_locked;
- if (frames_per_period > 0) {
- err = snd_pcm_hw_constraint_minmax(substream->runtime,
- SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
- frames_per_period, frames_per_period);
+ // 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 ((src != SND_MOTU_CLOCK_SOURCE_INTERNAL &&
+ src != SND_MOTU_CLOCK_SOURCE_SPH) ||
+ (motu->substreams_counter > 0 && d->events_per_period > 0)) {
+ unsigned int frames_per_period = d->events_per_period;
+ unsigned int frames_per_buffer = d->events_per_buffer;
+ unsigned int rate;
+
+ err = snd_motu_protocol_get_clock_rate(motu, &rate);
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;
+ substream->runtime->hw.rate_min = rate;
+ substream->runtime->hw.rate_max = rate;
+
+ if (frames_per_period > 0) {
+ 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;
+ }
}
}
snd_pcm_set_sync(substream);
- mutex_unlock(&motu->mutex);
-
return 0;
err_locked:
- mutex_unlock(&motu->mutex);
snd_motu_stream_lock_release(motu);
return err;
}
unsigned int frames_per_period = params_period_size(hw_params);
unsigned int frames_per_buffer = params_buffer_size(hw_params);
- mutex_lock(&motu->mutex);
+ guard(mutex)(&motu->mutex);
err = snd_motu_stream_reserve_duplex(motu, rate,
frames_per_period, frames_per_buffer);
if (err >= 0)
++motu->substreams_counter;
- mutex_unlock(&motu->mutex);
}
return err;
{
struct snd_motu *motu = substream->private_data;
- mutex_lock(&motu->mutex);
+ guard(mutex)(&motu->mutex);
if (substream->runtime->state != SNDRV_PCM_STATE_OPEN)
--motu->substreams_counter;
snd_motu_stream_stop_duplex(motu);
- mutex_unlock(&motu->mutex);
-
return 0;
}
struct snd_motu *motu = substream->private_data;
int err;
- mutex_lock(&motu->mutex);
- err = snd_motu_stream_start_duplex(motu);
- mutex_unlock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_start_duplex(motu);
+ }
if (err >= 0)
amdtp_stream_pcm_prepare(&motu->tx_stream);
struct snd_motu *motu = substream->private_data;
int err;
- mutex_lock(&motu->mutex);
- err = snd_motu_stream_start_duplex(motu);
- mutex_unlock(&motu->mutex);
+ scoped_guard(mutex, &motu->mutex) {
+ err = snd_motu_stream_start_duplex(motu);
+ }
if (err >= 0)
amdtp_stream_pcm_prepare(&motu->rx_stream);