diff options
Diffstat (limited to 'sound/firewire/fireworks/fireworks_pcm.c')
-rw-r--r-- | sound/firewire/fireworks/fireworks_pcm.c | 69 |
1 files changed, 29 insertions, 40 deletions
diff --git a/sound/firewire/fireworks/fireworks_pcm.c b/sound/firewire/fireworks/fireworks_pcm.c index eaf7778211de..9399293a9fe9 100644 --- a/sound/firewire/fireworks/fireworks_pcm.c +++ b/sound/firewire/fireworks/fireworks_pcm.c @@ -189,46 +189,38 @@ static int pcm_open(struct snd_pcm_substream *substream) if (err < 0) goto err_locked; - mutex_lock(&efw->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_source != SND_EFW_CLOCK_SOURCE_INTERNAL) || - (efw->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 sampling_rate; - - err = snd_efw_command_get_sampling_rate(efw, &sampling_rate); - if (err < 0) { - mutex_unlock(&efw->mutex); - goto err_locked; - } - substream->runtime->hw.rate_min = sampling_rate; - substream->runtime->hw.rate_max = sampling_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) { - mutex_unlock(&efw->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(&efw->mutex); + scoped_guard(mutex, &efw->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_source != SND_EFW_CLOCK_SOURCE_INTERNAL) || + (efw->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 sampling_rate; + + err = snd_efw_command_get_sampling_rate(efw, &sampling_rate); + if (err < 0) goto err_locked; + substream->runtime->hw.rate_min = sampling_rate; + substream->runtime->hw.rate_max = sampling_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; } } } - mutex_unlock(&efw->mutex); - snd_pcm_set_sync(substream); return 0; @@ -255,12 +247,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(&efw->mutex); + guard(mutex)(&efw->mutex); err = snd_efw_stream_reserve_duplex(efw, rate, frames_per_period, frames_per_buffer); if (err >= 0) ++efw->substreams_counter; - mutex_unlock(&efw->mutex); } return err; @@ -270,15 +261,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_efw *efw = substream->private_data; - mutex_lock(&efw->mutex); + guard(mutex)(&efw->mutex); if (substream->runtime->state != SNDRV_PCM_STATE_OPEN) --efw->substreams_counter; snd_efw_stream_stop_duplex(efw); - mutex_unlock(&efw->mutex); - return 0; } |