summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2025-08-28 15:27:08 +0200
committerTakashi Iwai <tiwai@suse.de>2025-08-30 10:02:21 +0200
commit760c91a25af4f240d199cf719f008e7a98ab246b (patch)
tree6f20225ceb12176532bb2ce27cfd482300c17c7d
parenta4b45e101d14718f534541c6a32ddfb26dc76a6d (diff)
ALSA: firewire: fireworks: Use guard() for mutex locks
Replace the manual mutex lock/unlock pairs with guard() for code simplification. Only code refactoring, and no behavior change. Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250828132802.9032-5-tiwai@suse.de
-rw-r--r--sound/firewire/fireworks/fireworks.c41
-rw-r--r--sound/firewire/fireworks/fireworks_midi.c29
-rw-r--r--sound/firewire/fireworks/fireworks_pcm.c69
3 files changed, 61 insertions, 78 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_midi.c b/sound/firewire/fireworks/fireworks_midi.c
index 350bf4d299c2..90fe809a26c0 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;
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;
}