From 873608dc6b5da7a2571419bfa10e0d088d39cee0 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 10 Oct 2018 15:35:01 +0900 Subject: ALSA: bebob/fireworks: simplify handling of local device entry table In drivers of ALSA firewire stack, bebob and fireworks drivers have local device entry table. At present, critical section to operate the table is from the beginning/end of 'do_registration' call. This can be more narrow and simplify codes. This commit applies small refactoring for the above purpose. Signed-off-by: Takashi Sakamoto Signed-off-by: Takashi Iwai --- sound/firewire/fireworks/fireworks.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'sound/firewire/fireworks') diff --git a/sound/firewire/fireworks/fireworks.c b/sound/firewire/fireworks/fireworks.c index 5854d2a87a18..da0c31033821 100644 --- a/sound/firewire/fireworks/fireworks.c +++ b/sound/firewire/fireworks/fireworks.c @@ -186,6 +186,10 @@ end: static void efw_free(struct snd_efw *efw) { + mutex_lock(&devices_mutex); + clear_bit(efw->card_index, devices_used); + mutex_unlock(&devices_mutex); + snd_efw_stream_destroy_duplex(efw); snd_efw_transaction_remove_instance(efw); } @@ -199,14 +203,6 @@ static void efw_free(struct snd_efw *efw) static void efw_card_free(struct snd_card *card) { - struct snd_efw *efw = card->private_data; - - if (efw->card_index >= 0) { - mutex_lock(&devices_mutex); - clear_bit(efw->card_index, devices_used); - mutex_unlock(&devices_mutex); - } - efw_free(card->private_data); } @@ -220,9 +216,8 @@ do_registration(struct work_struct *work) if (efw->registered) return; - mutex_lock(&devices_mutex); - /* 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; @@ -238,6 +233,8 @@ do_registration(struct work_struct *work) mutex_unlock(&devices_mutex); return; } + set_bit(card_index, devices_used); + mutex_unlock(&devices_mutex); /* prepare response buffer */ snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, @@ -279,9 +276,6 @@ do_registration(struct work_struct *work) if (err < 0) goto error; - set_bit(card_index, devices_used); - mutex_unlock(&devices_mutex); - /* * After registered, efw instance can be released corresponding to * releasing the sound card instance. @@ -292,7 +286,6 @@ do_registration(struct work_struct *work) return; error: - mutex_unlock(&devices_mutex); snd_efw_transaction_remove_instance(efw); snd_efw_stream_destroy_duplex(efw); snd_card_free(efw->card); -- cgit v1.2.3