mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 03:44:45 +01:00
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
This commit is contained in:
parent
a4b45e101d
commit
760c91a25a
3 changed files with 57 additions and 74 deletions
|
|
@ -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;
|
||||
}
|
||||
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) {
|
||||
mutex_unlock(&devices_mutex);
|
||||
return err;
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
return err;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -189,46 +189,38 @@ static int pcm_open(struct snd_pcm_substream *substream)
|
|||
if (err < 0)
|
||||
goto err_locked;
|
||||
|
||||
mutex_lock(&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;
|
||||
|
||||
// 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);
|
||||
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;
|
||||
|
||||
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);
|
||||
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(&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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue