diff options
Diffstat (limited to 'sound/firewire/oxfw')
-rw-r--r-- | sound/firewire/oxfw/oxfw-hwdep.c | 37 | ||||
-rw-r--r-- | sound/firewire/oxfw/oxfw-midi.c | 62 | ||||
-rw-r--r-- | sound/firewire/oxfw/oxfw-pcm.c | 92 | ||||
-rw-r--r-- | sound/firewire/oxfw/oxfw-stream.c | 21 | ||||
-rw-r--r-- | sound/firewire/oxfw/oxfw.c | 3 |
5 files changed, 79 insertions, 136 deletions
diff --git a/sound/firewire/oxfw/oxfw-hwdep.c b/sound/firewire/oxfw/oxfw-hwdep.c index 3be214d8a922..f8ac362fc73a 100644 --- a/sound/firewire/oxfw/oxfw-hwdep.c +++ b/sound/firewire/oxfw/oxfw-hwdep.c @@ -53,18 +53,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait) { struct snd_oxfw *oxfw = hwdep->private_data; - __poll_t events; poll_wait(file, &oxfw->hwdep_wait, wait); - spin_lock_irq(&oxfw->lock); + guard(spinlock_irq)(&oxfw->lock); if (oxfw->dev_lock_changed) - events = EPOLLIN | EPOLLRDNORM; + return EPOLLIN | EPOLLRDNORM; else - events = 0; - spin_unlock_irq(&oxfw->lock); - - return events; + return 0; } static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg) @@ -88,48 +84,35 @@ static int hwdep_get_info(struct snd_oxfw *oxfw, void __user *arg) static int hwdep_lock(struct snd_oxfw *oxfw) { - int err; - - spin_lock_irq(&oxfw->lock); + guard(spinlock_irq)(&oxfw->lock); if (oxfw->dev_lock_count == 0) { oxfw->dev_lock_count = -1; - err = 0; + return 0; } else { - err = -EBUSY; + return -EBUSY; } - - spin_unlock_irq(&oxfw->lock); - - return err; } static int hwdep_unlock(struct snd_oxfw *oxfw) { - int err; - - spin_lock_irq(&oxfw->lock); + guard(spinlock_irq)(&oxfw->lock); if (oxfw->dev_lock_count == -1) { oxfw->dev_lock_count = 0; - err = 0; + return 0; } else { - err = -EBADFD; + return -EBADFD; } - - spin_unlock_irq(&oxfw->lock); - - return err; } static int hwdep_release(struct snd_hwdep *hwdep, struct file *file) { struct snd_oxfw *oxfw = hwdep->private_data; - spin_lock_irq(&oxfw->lock); + guard(spinlock_irq)(&oxfw->lock); if (oxfw->dev_lock_count == -1) oxfw->dev_lock_count = 0; - spin_unlock_irq(&oxfw->lock); return 0; } diff --git a/sound/firewire/oxfw/oxfw-midi.c b/sound/firewire/oxfw/oxfw-midi.c index c215fa6f7a03..a16bf885f918 100644 --- a/sound/firewire/oxfw/oxfw-midi.c +++ b/sound/firewire/oxfw/oxfw-midi.c @@ -16,18 +16,16 @@ static int midi_capture_open(struct snd_rawmidi_substream *substream) if (err < 0) return err; - mutex_lock(&oxfw->mutex); - - err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream, 0, 0, 0, 0); - if (err >= 0) { - ++oxfw->substreams_count; - err = snd_oxfw_stream_start_duplex(oxfw); - if (err < 0) - --oxfw->substreams_count; + scoped_guard(mutex, &oxfw->mutex) { + err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream, 0, 0, 0, 0); + if (err >= 0) { + ++oxfw->substreams_count; + err = snd_oxfw_stream_start_duplex(oxfw); + if (err < 0) + --oxfw->substreams_count; + } } - mutex_unlock(&oxfw->mutex); - if (err < 0) snd_oxfw_stream_lock_release(oxfw); @@ -43,16 +41,14 @@ static int midi_playback_open(struct snd_rawmidi_substream *substream) if (err < 0) return err; - mutex_lock(&oxfw->mutex); - - err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream, 0, 0, 0, 0); - if (err >= 0) { - ++oxfw->substreams_count; - err = snd_oxfw_stream_start_duplex(oxfw); + scoped_guard(mutex, &oxfw->mutex) { + err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream, 0, 0, 0, 0); + if (err >= 0) { + ++oxfw->substreams_count; + err = snd_oxfw_stream_start_duplex(oxfw); + } } - mutex_unlock(&oxfw->mutex); - if (err < 0) snd_oxfw_stream_lock_release(oxfw); @@ -63,12 +59,10 @@ static int midi_capture_close(struct snd_rawmidi_substream *substream) { struct snd_oxfw *oxfw = substream->rmidi->private_data; - mutex_lock(&oxfw->mutex); - - --oxfw->substreams_count; - snd_oxfw_stream_stop_duplex(oxfw); - - mutex_unlock(&oxfw->mutex); + scoped_guard(mutex, &oxfw->mutex) { + --oxfw->substreams_count; + snd_oxfw_stream_stop_duplex(oxfw); + } snd_oxfw_stream_lock_release(oxfw); return 0; @@ -78,12 +72,10 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream) { struct snd_oxfw *oxfw = substream->rmidi->private_data; - mutex_lock(&oxfw->mutex); - - --oxfw->substreams_count; - snd_oxfw_stream_stop_duplex(oxfw); - - mutex_unlock(&oxfw->mutex); + scoped_guard(mutex, &oxfw->mutex) { + --oxfw->substreams_count; + snd_oxfw_stream_stop_duplex(oxfw); + } snd_oxfw_stream_lock_release(oxfw); return 0; @@ -92,9 +84,8 @@ static int midi_playback_close(struct snd_rawmidi_substream *substream) static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) { struct snd_oxfw *oxfw = substrm->rmidi->private_data; - unsigned long flags; - spin_lock_irqsave(&oxfw->lock, flags); + guard(spinlock_irqsave)(&oxfw->lock); if (up) amdtp_am824_midi_trigger(&oxfw->tx_stream, @@ -102,16 +93,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) else amdtp_am824_midi_trigger(&oxfw->tx_stream, substrm->number, NULL); - - spin_unlock_irqrestore(&oxfw->lock, flags); } static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) { struct snd_oxfw *oxfw = substrm->rmidi->private_data; - unsigned long flags; - spin_lock_irqsave(&oxfw->lock, flags); + guard(spinlock_irqsave)(&oxfw->lock); if (up) amdtp_am824_midi_trigger(&oxfw->rx_stream, @@ -119,8 +107,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) else amdtp_am824_midi_trigger(&oxfw->rx_stream, substrm->number, NULL); - - spin_unlock_irqrestore(&oxfw->lock, flags); } static void set_midi_substream_names(struct snd_oxfw *oxfw, diff --git a/sound/firewire/oxfw/oxfw-pcm.c b/sound/firewire/oxfw/oxfw-pcm.c index e13dc817fc28..774b8a763795 100644 --- a/sound/firewire/oxfw/oxfw-pcm.c +++ b/sound/firewire/oxfw/oxfw-pcm.c @@ -181,42 +181,34 @@ static int pcm_open(struct snd_pcm_substream *substream) if (err < 0) goto err_locked; - mutex_lock(&oxfw->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 (oxfw->substreams_count > 0 && d->events_per_period > 0) { - unsigned int frames_per_period = d->events_per_period; - unsigned int frames_per_buffer = d->events_per_buffer; - - err = limit_to_current_params(substream); - if (err < 0) { - mutex_unlock(&oxfw->mutex); - 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); - if (err < 0) { - mutex_unlock(&oxfw->mutex); + scoped_guard(mutex, &oxfw->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 (oxfw->substreams_count > 0 && d->events_per_period > 0) { + unsigned int frames_per_period = d->events_per_period; + unsigned int frames_per_buffer = d->events_per_buffer; + + err = limit_to_current_params(substream); + 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) { - mutex_unlock(&oxfw->mutex); - 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); + 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(&oxfw->mutex); - snd_pcm_set_sync(substream); return 0; @@ -245,13 +237,12 @@ static int pcm_capture_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(&oxfw->mutex); + guard(mutex)(&oxfw->mutex); err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->tx_stream, rate, channels, frames_per_period, frames_per_buffer); if (err >= 0) ++oxfw->substreams_count; - mutex_unlock(&oxfw->mutex); } return err; @@ -268,13 +259,12 @@ static int pcm_playback_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(&oxfw->mutex); + guard(mutex)(&oxfw->mutex); err = snd_oxfw_stream_reserve_duplex(oxfw, &oxfw->rx_stream, rate, channels, frames_per_period, frames_per_buffer); if (err >= 0) ++oxfw->substreams_count; - mutex_unlock(&oxfw->mutex); } return err; @@ -284,30 +274,26 @@ static int pcm_capture_hw_free(struct snd_pcm_substream *substream) { struct snd_oxfw *oxfw = substream->private_data; - mutex_lock(&oxfw->mutex); + guard(mutex)(&oxfw->mutex); if (substream->runtime->state != SNDRV_PCM_STATE_OPEN) --oxfw->substreams_count; snd_oxfw_stream_stop_duplex(oxfw); - mutex_unlock(&oxfw->mutex); - return 0; } static int pcm_playback_hw_free(struct snd_pcm_substream *substream) { struct snd_oxfw *oxfw = substream->private_data; - mutex_lock(&oxfw->mutex); + guard(mutex)(&oxfw->mutex); if (substream->runtime->state != SNDRV_PCM_STATE_OPEN) --oxfw->substreams_count; snd_oxfw_stream_stop_duplex(oxfw); - mutex_unlock(&oxfw->mutex); - return 0; } @@ -316,30 +302,28 @@ static int pcm_capture_prepare(struct snd_pcm_substream *substream) struct snd_oxfw *oxfw = substream->private_data; int err; - mutex_lock(&oxfw->mutex); - err = snd_oxfw_stream_start_duplex(oxfw); - mutex_unlock(&oxfw->mutex); - if (err < 0) - goto end; + scoped_guard(mutex, &oxfw->mutex) { + err = snd_oxfw_stream_start_duplex(oxfw); + if (err < 0) + return err; + } amdtp_stream_pcm_prepare(&oxfw->tx_stream); -end: - return err; + return 0; } static int pcm_playback_prepare(struct snd_pcm_substream *substream) { struct snd_oxfw *oxfw = substream->private_data; int err; - mutex_lock(&oxfw->mutex); - err = snd_oxfw_stream_start_duplex(oxfw); - mutex_unlock(&oxfw->mutex); - if (err < 0) - goto end; + scoped_guard(mutex, &oxfw->mutex) { + err = snd_oxfw_stream_start_duplex(oxfw); + if (err < 0) + return err; + } amdtp_stream_pcm_prepare(&oxfw->rx_stream); -end: - return err; + return 0; } static int pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd) diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c index 00f7feb91f92..5e36d7153a7b 100644 --- a/sound/firewire/oxfw/oxfw-stream.c +++ b/sound/firewire/oxfw/oxfw-stream.c @@ -866,33 +866,24 @@ void snd_oxfw_stream_lock_changed(struct snd_oxfw *oxfw) int snd_oxfw_stream_lock_try(struct snd_oxfw *oxfw) { - int err; - - spin_lock_irq(&oxfw->lock); + guard(spinlock_irq)(&oxfw->lock); /* user land lock this */ - if (oxfw->dev_lock_count < 0) { - err = -EBUSY; - goto end; - } + if (oxfw->dev_lock_count < 0) + return -EBUSY; /* this is the first time */ if (oxfw->dev_lock_count++ == 0) snd_oxfw_stream_lock_changed(oxfw); - err = 0; -end: - spin_unlock_irq(&oxfw->lock); - return err; + return 0; } void snd_oxfw_stream_lock_release(struct snd_oxfw *oxfw) { - spin_lock_irq(&oxfw->lock); + guard(spinlock_irq)(&oxfw->lock); if (WARN_ON(oxfw->dev_lock_count <= 0)) - goto end; + return; if (--oxfw->dev_lock_count == 0) snd_oxfw_stream_lock_changed(oxfw); -end: - spin_unlock_irq(&oxfw->lock); } diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c index 7a985f3cb8f6..5039bd79b18e 100644 --- a/sound/firewire/oxfw/oxfw.c +++ b/sound/firewire/oxfw/oxfw.c @@ -283,9 +283,8 @@ static void oxfw_bus_reset(struct fw_unit *unit) fcp_bus_reset(oxfw->unit); if (oxfw->has_output || oxfw->has_input) { - mutex_lock(&oxfw->mutex); + guard(mutex)(&oxfw->mutex); snd_oxfw_stream_update_duplex(oxfw); - mutex_unlock(&oxfw->mutex); } if (oxfw->quirks & SND_OXFW_QUIRK_SCS_TRANSACTION) |