diff options
Diffstat (limited to 'sound/firewire/dice')
-rw-r--r-- | sound/firewire/dice/dice-hwdep.c | 37 | ||||
-rw-r--r-- | sound/firewire/dice/dice-midi.c | 38 | ||||
-rw-r--r-- | sound/firewire/dice/dice-pcm.c | 93 | ||||
-rw-r--r-- | sound/firewire/dice/dice-stream.c | 21 | ||||
-rw-r--r-- | sound/firewire/dice/dice-transaction.c | 7 | ||||
-rw-r--r-- | sound/firewire/dice/dice.c | 3 |
6 files changed, 75 insertions, 124 deletions
diff --git a/sound/firewire/dice/dice-hwdep.c b/sound/firewire/dice/dice-hwdep.c index d165dd427bd3..747ff0952483 100644 --- a/sound/firewire/dice/dice-hwdep.c +++ b/sound/firewire/dice/dice-hwdep.c @@ -55,18 +55,14 @@ static __poll_t hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait) { struct snd_dice *dice = hwdep->private_data; - __poll_t events; poll_wait(file, &dice->hwdep_wait, wait); - spin_lock_irq(&dice->lock); + guard(spinlock_irq)(&dice->lock); if (dice->dev_lock_changed || dice->notification_bits != 0) - events = EPOLLIN | EPOLLRDNORM; + return EPOLLIN | EPOLLRDNORM; else - events = 0; - spin_unlock_irq(&dice->lock); - - return events; + return 0; } static int hwdep_get_info(struct snd_dice *dice, void __user *arg) @@ -90,48 +86,35 @@ static int hwdep_get_info(struct snd_dice *dice, void __user *arg) static int hwdep_lock(struct snd_dice *dice) { - int err; - - spin_lock_irq(&dice->lock); + guard(spinlock_irq)(&dice->lock); if (dice->dev_lock_count == 0) { dice->dev_lock_count = -1; - err = 0; + return 0; } else { - err = -EBUSY; + return -EBUSY; } - - spin_unlock_irq(&dice->lock); - - return err; } static int hwdep_unlock(struct snd_dice *dice) { - int err; - - spin_lock_irq(&dice->lock); + guard(spinlock_irq)(&dice->lock); if (dice->dev_lock_count == -1) { dice->dev_lock_count = 0; - err = 0; + return 0; } else { - err = -EBADFD; + return -EBADFD; } - - spin_unlock_irq(&dice->lock); - - return err; } static int hwdep_release(struct snd_hwdep *hwdep, struct file *file) { struct snd_dice *dice = hwdep->private_data; - spin_lock_irq(&dice->lock); + guard(spinlock_irq)(&dice->lock); if (dice->dev_lock_count == -1) dice->dev_lock_count = 0; - spin_unlock_irq(&dice->lock); return 0; } diff --git a/sound/firewire/dice/dice-midi.c b/sound/firewire/dice/dice-midi.c index 78988e44b8bc..722bce379345 100644 --- a/sound/firewire/dice/dice-midi.c +++ b/sound/firewire/dice/dice-midi.c @@ -15,18 +15,16 @@ static int midi_open(struct snd_rawmidi_substream *substream) if (err < 0) return err; - mutex_lock(&dice->mutex); - - err = snd_dice_stream_reserve_duplex(dice, 0, 0, 0); - if (err >= 0) { - ++dice->substreams_counter; - err = snd_dice_stream_start_duplex(dice); - if (err < 0) - --dice->substreams_counter; + scoped_guard(mutex, &dice->mutex) { + err = snd_dice_stream_reserve_duplex(dice, 0, 0, 0); + if (err >= 0) { + ++dice->substreams_counter; + err = snd_dice_stream_start_duplex(dice); + if (err < 0) + --dice->substreams_counter; + } } - mutex_unlock(&dice->mutex); - if (err < 0) snd_dice_stream_lock_release(dice); @@ -37,12 +35,10 @@ static int midi_close(struct snd_rawmidi_substream *substream) { struct snd_dice *dice = substream->rmidi->private_data; - mutex_lock(&dice->mutex); - - --dice->substreams_counter; - snd_dice_stream_stop_duplex(dice); - - mutex_unlock(&dice->mutex); + scoped_guard(mutex, &dice->mutex) { + --dice->substreams_counter; + snd_dice_stream_stop_duplex(dice); + } snd_dice_stream_lock_release(dice); return 0; @@ -51,9 +47,8 @@ static int midi_close(struct snd_rawmidi_substream *substream) static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) { struct snd_dice *dice = substrm->rmidi->private_data; - unsigned long flags; - spin_lock_irqsave(&dice->lock, flags); + guard(spinlock_irqsave)(&dice->lock); if (up) amdtp_am824_midi_trigger(&dice->tx_stream[0], @@ -61,16 +56,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) else amdtp_am824_midi_trigger(&dice->tx_stream[0], substrm->number, NULL); - - spin_unlock_irqrestore(&dice->lock, flags); } static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) { struct snd_dice *dice = substrm->rmidi->private_data; - unsigned long flags; - spin_lock_irqsave(&dice->lock, flags); + guard(spinlock_irqsave)(&dice->lock); if (up) amdtp_am824_midi_trigger(&dice->rx_stream[0], @@ -78,8 +70,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) else amdtp_am824_midi_trigger(&dice->rx_stream[0], substrm->number, NULL); - - spin_unlock_irqrestore(&dice->lock, flags); } static void set_midi_substream_names(struct snd_dice *dice, diff --git a/sound/firewire/dice/dice-pcm.c b/sound/firewire/dice/dice-pcm.c index cfc19bd0d5dd..d5319cd2cc6f 100644 --- a/sound/firewire/dice/dice-pcm.c +++ b/sound/firewire/dice/dice-pcm.c @@ -196,53 +196,45 @@ static int pcm_open(struct snd_pcm_substream *substream) break; } - mutex_lock(&dice->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 (!internal || - (dice->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_dice_transaction_get_rate(dice, &rate); - if (err < 0) { - mutex_unlock(&dice->mutex); - goto err_locked; - } - - substream->runtime->hw.rate_min = rate; - substream->runtime->hw.rate_max = rate; - - if (frames_per_period > 0) { - // For double_pcm_frame quirk. - if (rate > 96000 && !dice->disable_double_pcm_frames) { - frames_per_period *= 2; - frames_per_buffer *= 2; - } - - 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(&dice->mutex); + scoped_guard(mutex, &dice->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 (!internal || + (dice->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_dice_transaction_get_rate(dice, &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) { - mutex_unlock(&dice->mutex); - goto err_locked; + substream->runtime->hw.rate_min = rate; + substream->runtime->hw.rate_max = rate; + + if (frames_per_period > 0) { + // For double_pcm_frame quirk. + if (rate > 96000 && !dice->disable_double_pcm_frames) { + frames_per_period *= 2; + frames_per_buffer *= 2; + } + + 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(&dice->mutex); - snd_pcm_set_sync(substream); return 0; @@ -271,7 +263,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream, unsigned int events_per_period = params_period_size(hw_params); unsigned int events_per_buffer = params_buffer_size(hw_params); - mutex_lock(&dice->mutex); + guard(mutex)(&dice->mutex); // For double_pcm_frame quirk. if (rate > 96000 && !dice->disable_double_pcm_frames) { events_per_period /= 2; @@ -281,7 +273,6 @@ static int pcm_hw_params(struct snd_pcm_substream *substream, events_per_period, events_per_buffer); if (err >= 0) ++dice->substreams_counter; - mutex_unlock(&dice->mutex); } return err; @@ -291,15 +282,13 @@ static int pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_dice *dice = substream->private_data; - mutex_lock(&dice->mutex); + guard(mutex)(&dice->mutex); if (substream->runtime->state != SNDRV_PCM_STATE_OPEN) --dice->substreams_counter; snd_dice_stream_stop_duplex(dice); - mutex_unlock(&dice->mutex); - return 0; } @@ -309,9 +298,9 @@ static int capture_prepare(struct snd_pcm_substream *substream) struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device]; int err; - mutex_lock(&dice->mutex); - err = snd_dice_stream_start_duplex(dice); - mutex_unlock(&dice->mutex); + scoped_guard(mutex, &dice->mutex) { + err = snd_dice_stream_start_duplex(dice); + } if (err >= 0) amdtp_stream_pcm_prepare(stream); @@ -323,9 +312,9 @@ static int playback_prepare(struct snd_pcm_substream *substream) struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device]; int err; - mutex_lock(&dice->mutex); - err = snd_dice_stream_start_duplex(dice); - mutex_unlock(&dice->mutex); + scoped_guard(mutex, &dice->mutex) { + err = snd_dice_stream_start_duplex(dice); + } if (err >= 0) amdtp_stream_pcm_prepare(stream); diff --git a/sound/firewire/dice/dice-stream.c b/sound/firewire/dice/dice-stream.c index 4c677c8546c7..d5ffe7c82993 100644 --- a/sound/firewire/dice/dice-stream.c +++ b/sound/firewire/dice/dice-stream.c @@ -677,32 +677,23 @@ static void dice_lock_changed(struct snd_dice *dice) int snd_dice_stream_lock_try(struct snd_dice *dice) { - int err; - - spin_lock_irq(&dice->lock); + guard(spinlock_irq)(&dice->lock); - if (dice->dev_lock_count < 0) { - err = -EBUSY; - goto out; - } + if (dice->dev_lock_count < 0) + return -EBUSY; if (dice->dev_lock_count++ == 0) dice_lock_changed(dice); - err = 0; -out: - spin_unlock_irq(&dice->lock); - return err; + return 0; } void snd_dice_stream_lock_release(struct snd_dice *dice) { - spin_lock_irq(&dice->lock); + guard(spinlock_irq)(&dice->lock); if (WARN_ON(dice->dev_lock_count <= 0)) - goto out; + return; if (--dice->dev_lock_count == 0) dice_lock_changed(dice); -out: - spin_unlock_irq(&dice->lock); } diff --git a/sound/firewire/dice/dice-transaction.c b/sound/firewire/dice/dice-transaction.c index 92941ef83cd5..a3f7dfa990a4 100644 --- a/sound/firewire/dice/dice-transaction.c +++ b/sound/firewire/dice/dice-transaction.c @@ -136,7 +136,6 @@ static void dice_notification(struct fw_card *card, struct fw_request *request, { struct snd_dice *dice = callback_data; u32 bits; - unsigned long flags; if (tcode != TCODE_WRITE_QUADLET_REQUEST) { fw_send_response(card, request, RCODE_TYPE_ERROR); @@ -149,9 +148,9 @@ static void dice_notification(struct fw_card *card, struct fw_request *request, bits = be32_to_cpup(data); - spin_lock_irqsave(&dice->lock, flags); - dice->notification_bits |= bits; - spin_unlock_irqrestore(&dice->lock, flags); + scoped_guard(spinlock_irqsave, &dice->lock) { + dice->notification_bits |= bits; + } fw_send_response(card, request, RCODE_COMPLETE); diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c index 9675ec14271d..bcbe80344328 100644 --- a/sound/firewire/dice/dice.c +++ b/sound/firewire/dice/dice.c @@ -238,9 +238,8 @@ static void dice_bus_reset(struct fw_unit *unit) /* The handler address register becomes initialized. */ snd_dice_transaction_reinit(dice); - mutex_lock(&dice->mutex); + guard(mutex)(&dice->mutex); snd_dice_stream_update_duplex(dice); - mutex_unlock(&dice->mutex); } #define DICE_INTERFACE 0x000001 |