diff options
Diffstat (limited to 'sound/firewire/fireworks')
-rw-r--r-- | sound/firewire/fireworks/fireworks.c | 41 | ||||
-rw-r--r-- | sound/firewire/fireworks/fireworks_command.c | 16 | ||||
-rw-r--r-- | sound/firewire/fireworks/fireworks_hwdep.c | 41 | ||||
-rw-r--r-- | sound/firewire/fireworks/fireworks_midi.c | 39 | ||||
-rw-r--r-- | sound/firewire/fireworks/fireworks_pcm.c | 69 | ||||
-rw-r--r-- | sound/firewire/fireworks/fireworks_stream.c | 21 | ||||
-rw-r--r-- | sound/firewire/fireworks/fireworks_transaction.c | 39 |
7 files changed, 103 insertions, 163 deletions
diff --git a/sound/firewire/fireworks/fireworks.c b/sound/firewire/fireworks/fireworks.c index 69f722244362..3378c7dce88a 100644 --- a/sound/firewire/fireworks/fireworks.c +++ b/sound/firewire/fireworks/fireworks.c @@ -188,9 +188,9 @@ efw_card_free(struct snd_card *card) { struct snd_efw *efw = card->private_data; - mutex_lock(&devices_mutex); - clear_bit(efw->card_index, devices_used); - mutex_unlock(&devices_mutex); + scoped_guard(mutex, &devices_mutex) { + clear_bit(efw->card_index, devices_used); + } snd_efw_stream_destroy_duplex(efw); snd_efw_transaction_remove_instance(efw); @@ -207,25 +207,21 @@ static int efw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entr int err; // check registered cards. - mutex_lock(&devices_mutex); - for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) { - if (!test_bit(card_index, devices_used) && enable[card_index]) - break; - } - if (card_index >= SNDRV_CARDS) { - mutex_unlock(&devices_mutex); - return -ENOENT; - } - - err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE, - sizeof(*efw), &card); - if (err < 0) { - mutex_unlock(&devices_mutex); - return err; + scoped_guard(mutex, &devices_mutex) { + for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) { + if (!test_bit(card_index, devices_used) && enable[card_index]) + break; + } + if (card_index >= SNDRV_CARDS) + return -ENOENT; + + err = snd_card_new(&unit->device, index[card_index], id[card_index], THIS_MODULE, + sizeof(*efw), &card); + if (err < 0) + return err; + card->private_free = efw_card_free; + set_bit(card_index, devices_used); } - card->private_free = efw_card_free; - set_bit(card_index, devices_used); - mutex_unlock(&devices_mutex); efw = card->private_data; efw->unit = fw_unit_get(unit); @@ -287,9 +283,8 @@ static void efw_update(struct fw_unit *unit) snd_efw_transaction_bus_reset(efw->unit); - mutex_lock(&efw->mutex); + guard(mutex)(&efw->mutex); snd_efw_stream_update_duplex(efw); - mutex_unlock(&efw->mutex); } static void efw_remove(struct fw_unit *unit) diff --git a/sound/firewire/fireworks/fireworks_command.c b/sound/firewire/fireworks/fireworks_command.c index 7e255fc2c6e4..2b595ee0bc35 100644 --- a/sound/firewire/fireworks/fireworks_command.c +++ b/sound/firewire/fireworks/fireworks_command.c @@ -119,14 +119,14 @@ efw_transaction(struct snd_efw *efw, unsigned int category, return -ENOMEM; /* to keep consistency of sequence number */ - spin_lock(&efw->lock); - if ((efw->seqnum < KERNEL_SEQNUM_MIN) || - (efw->seqnum >= KERNEL_SEQNUM_MAX - 2)) - efw->seqnum = KERNEL_SEQNUM_MIN; - else - efw->seqnum += 2; - seqnum = efw->seqnum; - spin_unlock(&efw->lock); + scoped_guard(spinlock, &efw->lock) { + if ((efw->seqnum < KERNEL_SEQNUM_MIN) || + (efw->seqnum >= KERNEL_SEQNUM_MAX - 2)) + efw->seqnum = KERNEL_SEQNUM_MIN; + else + efw->seqnum += 2; + seqnum = efw->seqnum; + } /* fill transaction header fields */ cmd_bytes = sizeof(struct snd_efw_transaction) + param_bytes; diff --git a/sound/firewire/fireworks/fireworks_hwdep.c b/sound/firewire/fireworks/fireworks_hwdep.c index 037833cd066e..7d6bd8ceeab3 100644 --- a/sound/firewire/fireworks/fireworks_hwdep.c +++ b/sound/firewire/fireworks/fireworks_hwdep.c @@ -103,12 +103,10 @@ hwdep_read_locked(struct snd_efw *efw, char __user *buf, long count, .lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS, }; - spin_lock_irq(&efw->lock); - - event.lock_status.status = (efw->dev_lock_count > 0); - efw->dev_lock_changed = false; - - spin_unlock_irq(&efw->lock); + scoped_guard(spinlock_irq, &efw->lock) { + event.lock_status.status = (efw->dev_lock_count > 0); + efw->dev_lock_changed = false; + } count = min_t(long, count, sizeof(event.lock_status)); @@ -192,13 +190,11 @@ hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait) poll_wait(file, &efw->hwdep_wait, wait); - spin_lock_irq(&efw->lock); + guard(spinlock_irq)(&efw->lock); if (efw->dev_lock_changed || efw->pull_ptr != efw->push_ptr) events = EPOLLIN | EPOLLRDNORM; else events = 0; - spin_unlock_irq(&efw->lock); - return events | EPOLLOUT; } @@ -225,39 +221,27 @@ hwdep_get_info(struct snd_efw *efw, void __user *arg) static int hwdep_lock(struct snd_efw *efw) { - int err; - - spin_lock_irq(&efw->lock); + guard(spinlock_irq)(&efw->lock); if (efw->dev_lock_count == 0) { efw->dev_lock_count = -1; - err = 0; + return 0; } else { - err = -EBUSY; + return -EBUSY; } - - spin_unlock_irq(&efw->lock); - - return err; } static int hwdep_unlock(struct snd_efw *efw) { - int err; - - spin_lock_irq(&efw->lock); + guard(spinlock_irq)(&efw->lock); if (efw->dev_lock_count == -1) { efw->dev_lock_count = 0; - err = 0; + return 0; } else { - err = -EBADFD; + return -EBADFD; } - - spin_unlock_irq(&efw->lock); - - return err; } static int @@ -265,10 +249,9 @@ hwdep_release(struct snd_hwdep *hwdep, struct file *file) { struct snd_efw *efw = hwdep->private_data; - spin_lock_irq(&efw->lock); + guard(spinlock_irq)(&efw->lock); if (efw->dev_lock_count == -1) efw->dev_lock_count = 0; - spin_unlock_irq(&efw->lock); return 0; } diff --git a/sound/firewire/fireworks/fireworks_midi.c b/sound/firewire/fireworks/fireworks_midi.c index 350bf4d299c2..405106a6aef9 100644 --- a/sound/firewire/fireworks/fireworks_midi.c +++ b/sound/firewire/fireworks/fireworks_midi.c @@ -14,20 +14,19 @@ static int midi_open(struct snd_rawmidi_substream *substream) err = snd_efw_stream_lock_try(efw); if (err < 0) - goto end; - - mutex_lock(&efw->mutex); - err = snd_efw_stream_reserve_duplex(efw, 0, 0, 0); - if (err >= 0) { - ++efw->substreams_counter; - err = snd_efw_stream_start_duplex(efw); - if (err < 0) - --efw->substreams_counter; + return err; + + scoped_guard(mutex, &efw->mutex) { + err = snd_efw_stream_reserve_duplex(efw, 0, 0, 0); + if (err >= 0) { + ++efw->substreams_counter; + err = snd_efw_stream_start_duplex(efw); + if (err < 0) + --efw->substreams_counter; + } } - mutex_unlock(&efw->mutex); if (err < 0) snd_efw_stream_lock_release(efw); -end: return err; } @@ -35,10 +34,10 @@ static int midi_close(struct snd_rawmidi_substream *substream) { struct snd_efw *efw = substream->rmidi->private_data; - mutex_lock(&efw->mutex); - --efw->substreams_counter; - snd_efw_stream_stop_duplex(efw); - mutex_unlock(&efw->mutex); + scoped_guard(mutex, &efw->mutex) { + --efw->substreams_counter; + snd_efw_stream_stop_duplex(efw); + } snd_efw_stream_lock_release(efw); return 0; @@ -47,9 +46,8 @@ static int midi_close(struct snd_rawmidi_substream *substream) static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) { struct snd_efw *efw = substrm->rmidi->private_data; - unsigned long flags; - spin_lock_irqsave(&efw->lock, flags); + guard(spinlock_irqsave)(&efw->lock); if (up) amdtp_am824_midi_trigger(&efw->tx_stream, @@ -57,16 +55,13 @@ static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up) else amdtp_am824_midi_trigger(&efw->tx_stream, substrm->number, NULL); - - spin_unlock_irqrestore(&efw->lock, flags); } static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) { struct snd_efw *efw = substrm->rmidi->private_data; - unsigned long flags; - spin_lock_irqsave(&efw->lock, flags); + guard(spinlock_irqsave)(&efw->lock); if (up) amdtp_am824_midi_trigger(&efw->rx_stream, @@ -74,8 +69,6 @@ static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up) else amdtp_am824_midi_trigger(&efw->rx_stream, substrm->number, NULL); - - spin_unlock_irqrestore(&efw->lock, flags); } static void set_midi_substream_names(struct snd_efw *efw, 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; } diff --git a/sound/firewire/fireworks/fireworks_stream.c b/sound/firewire/fireworks/fireworks_stream.c index 53dbd4d4b0d0..974084e1c083 100644 --- a/sound/firewire/fireworks/fireworks_stream.c +++ b/sound/firewire/fireworks/fireworks_stream.c @@ -345,33 +345,24 @@ void snd_efw_stream_lock_changed(struct snd_efw *efw) int snd_efw_stream_lock_try(struct snd_efw *efw) { - int err; - - spin_lock_irq(&efw->lock); + guard(spinlock_irq)(&efw->lock); /* user land lock this */ - if (efw->dev_lock_count < 0) { - err = -EBUSY; - goto end; - } + if (efw->dev_lock_count < 0) + return -EBUSY; /* this is the first time */ if (efw->dev_lock_count++ == 0) snd_efw_stream_lock_changed(efw); - err = 0; -end: - spin_unlock_irq(&efw->lock); - return err; + return 0; } void snd_efw_stream_lock_release(struct snd_efw *efw) { - spin_lock_irq(&efw->lock); + guard(spinlock_irq)(&efw->lock); if (WARN_ON(efw->dev_lock_count <= 0)) - goto end; + return; if (--efw->dev_lock_count == 0) snd_efw_stream_lock_changed(efw); -end: - spin_unlock_irq(&efw->lock); } diff --git a/sound/firewire/fireworks/fireworks_transaction.c b/sound/firewire/fireworks/fireworks_transaction.c index 9f8c53b39f95..5c859773fe06 100644 --- a/sound/firewire/fireworks/fireworks_transaction.c +++ b/sound/firewire/fireworks/fireworks_transaction.c @@ -82,9 +82,9 @@ int snd_efw_transaction_run(struct fw_unit *unit, t.state = STATE_PENDING; init_waitqueue_head(&t.wait); - spin_lock_irq(&transaction_queues_lock); - list_add_tail(&t.list, &transaction_queues); - spin_unlock_irq(&transaction_queues_lock); + scoped_guard(spinlock_irq, &transaction_queues_lock) { + list_add_tail(&t.list, &transaction_queues); + } tries = 0; do { @@ -107,9 +107,9 @@ int snd_efw_transaction_run(struct fw_unit *unit, } } while (1); - spin_lock_irq(&transaction_queues_lock); - list_del(&t.list); - spin_unlock_irq(&transaction_queues_lock); + scoped_guard(spinlock_irq, &transaction_queues_lock) { + list_del(&t.list); + } return ret; } @@ -123,7 +123,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode) t = (struct snd_efw_transaction *)data; length = min_t(size_t, be32_to_cpu(t->length) * sizeof(u32), length); - spin_lock(&efw->lock); + guard(spinlock)(&efw->lock); if (efw->push_ptr < efw->pull_ptr) capacity = (unsigned int)(efw->pull_ptr - efw->push_ptr); @@ -134,7 +134,7 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode) /* confirm enough space for this response */ if (capacity < length) { *rcode = RCODE_CONFLICT_ERROR; - goto end; + return; } /* copy to ring buffer */ @@ -157,8 +157,6 @@ copy_resp_to_buf(struct snd_efw *efw, void *data, size_t length, int *rcode) wake_up(&efw->hwdep_wait); *rcode = RCODE_COMPLETE; -end: - spin_unlock_irq(&efw->lock); } static void @@ -169,7 +167,7 @@ handle_resp_for_user(struct fw_card *card, int generation, int source, struct snd_efw *efw; unsigned int i; - spin_lock_irq(&instances_lock); + guard(spinlock_irq)(&instances_lock); for (i = 0; i < SNDRV_CARDS; i++) { efw = instances[i]; @@ -186,11 +184,9 @@ handle_resp_for_user(struct fw_card *card, int generation, int source, break; } if (i == SNDRV_CARDS) - goto end; + return; copy_resp_to_buf(efw, data, length, rcode); -end: - spin_unlock(&instances_lock); } static void @@ -199,9 +195,8 @@ handle_resp_for_kernel(struct fw_card *card, int generation, int source, { struct fw_device *device; struct transaction_queue *t; - unsigned long flags; - spin_lock_irqsave(&transaction_queues_lock, flags); + guard(spinlock_irqsave)(&transaction_queues_lock); list_for_each_entry(t, &transaction_queues, list) { device = fw_parent_device(t->unit); if ((device->card != card) || @@ -219,7 +214,6 @@ handle_resp_for_kernel(struct fw_card *card, int generation, int source, *rcode = RCODE_COMPLETE; } } - spin_unlock_irqrestore(&transaction_queues_lock, flags); } static void @@ -259,7 +253,7 @@ void snd_efw_transaction_add_instance(struct snd_efw *efw) { unsigned int i; - spin_lock_irq(&instances_lock); + guard(spinlock_irq)(&instances_lock); for (i = 0; i < SNDRV_CARDS; i++) { if (instances[i] != NULL) @@ -267,30 +261,26 @@ void snd_efw_transaction_add_instance(struct snd_efw *efw) instances[i] = efw; break; } - - spin_unlock_irq(&instances_lock); } void snd_efw_transaction_remove_instance(struct snd_efw *efw) { unsigned int i; - spin_lock_irq(&instances_lock); + guard(spinlock_irq)(&instances_lock); for (i = 0; i < SNDRV_CARDS; i++) { if (instances[i] != efw) continue; instances[i] = NULL; } - - spin_unlock_irq(&instances_lock); } void snd_efw_transaction_bus_reset(struct fw_unit *unit) { struct transaction_queue *t; - spin_lock_irq(&transaction_queues_lock); + guard(spinlock_irq)(&transaction_queues_lock); list_for_each_entry(t, &transaction_queues, list) { if ((t->unit == unit) && (t->state == STATE_PENDING)) { @@ -298,7 +288,6 @@ void snd_efw_transaction_bus_reset(struct fw_unit *unit) wake_up(&t->wait); } } - spin_unlock_irq(&transaction_queues_lock); } static struct fw_address_handler resp_register_handler = { |