Commit 873608dc authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

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: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 5b14ec25
...@@ -128,6 +128,10 @@ name_device(struct snd_bebob *bebob) ...@@ -128,6 +128,10 @@ name_device(struct snd_bebob *bebob)
static void bebob_free(struct snd_bebob *bebob) static void bebob_free(struct snd_bebob *bebob)
{ {
mutex_lock(&devices_mutex);
clear_bit(bebob->card_index, devices_used);
mutex_unlock(&devices_mutex);
snd_bebob_stream_destroy_duplex(bebob); snd_bebob_stream_destroy_duplex(bebob);
} }
...@@ -140,12 +144,6 @@ static void bebob_free(struct snd_bebob *bebob) ...@@ -140,12 +144,6 @@ static void bebob_free(struct snd_bebob *bebob)
static void static void
bebob_card_free(struct snd_card *card) bebob_card_free(struct snd_card *card)
{ {
struct snd_bebob *bebob = card->private_data;
mutex_lock(&devices_mutex);
clear_bit(bebob->card_index, devices_used);
mutex_unlock(&devices_mutex);
bebob_free(card->private_data); bebob_free(card->private_data);
} }
...@@ -186,7 +184,6 @@ do_registration(struct work_struct *work) ...@@ -186,7 +184,6 @@ do_registration(struct work_struct *work)
return; return;
mutex_lock(&devices_mutex); mutex_lock(&devices_mutex);
for (card_index = 0; card_index < SNDRV_CARDS; card_index++) { for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
if (!test_bit(card_index, devices_used) && enable[card_index]) if (!test_bit(card_index, devices_used) && enable[card_index])
break; break;
...@@ -202,6 +199,8 @@ do_registration(struct work_struct *work) ...@@ -202,6 +199,8 @@ do_registration(struct work_struct *work)
mutex_unlock(&devices_mutex); mutex_unlock(&devices_mutex);
return; return;
} }
set_bit(card_index, devices_used);
mutex_unlock(&devices_mutex);
err = name_device(bebob); err = name_device(bebob);
if (err < 0) if (err < 0)
...@@ -242,9 +241,6 @@ do_registration(struct work_struct *work) ...@@ -242,9 +241,6 @@ do_registration(struct work_struct *work)
if (err < 0) if (err < 0)
goto error; goto error;
set_bit(card_index, devices_used);
mutex_unlock(&devices_mutex);
/* /*
* After registered, bebob instance can be released corresponding to * After registered, bebob instance can be released corresponding to
* releasing the sound card instance. * releasing the sound card instance.
...@@ -255,7 +251,6 @@ do_registration(struct work_struct *work) ...@@ -255,7 +251,6 @@ do_registration(struct work_struct *work)
return; return;
error: error:
mutex_unlock(&devices_mutex);
snd_bebob_stream_destroy_duplex(bebob); snd_bebob_stream_destroy_duplex(bebob);
snd_card_free(bebob->card); snd_card_free(bebob->card);
dev_info(&bebob->unit->device, dev_info(&bebob->unit->device,
......
...@@ -186,6 +186,10 @@ get_hardware_info(struct snd_efw *efw) ...@@ -186,6 +186,10 @@ get_hardware_info(struct snd_efw *efw)
static void efw_free(struct snd_efw *efw) 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_stream_destroy_duplex(efw);
snd_efw_transaction_remove_instance(efw); snd_efw_transaction_remove_instance(efw);
} }
...@@ -199,14 +203,6 @@ static void efw_free(struct snd_efw *efw) ...@@ -199,14 +203,6 @@ static void efw_free(struct snd_efw *efw)
static void static void
efw_card_free(struct snd_card *card) 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); efw_free(card->private_data);
} }
...@@ -220,9 +216,8 @@ do_registration(struct work_struct *work) ...@@ -220,9 +216,8 @@ do_registration(struct work_struct *work)
if (efw->registered) if (efw->registered)
return; return;
mutex_lock(&devices_mutex);
/* check registered cards */ /* check registered cards */
mutex_lock(&devices_mutex);
for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) { for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
if (!test_bit(card_index, devices_used) && enable[card_index]) if (!test_bit(card_index, devices_used) && enable[card_index])
break; break;
...@@ -238,6 +233,8 @@ do_registration(struct work_struct *work) ...@@ -238,6 +233,8 @@ do_registration(struct work_struct *work)
mutex_unlock(&devices_mutex); mutex_unlock(&devices_mutex);
return; return;
} }
set_bit(card_index, devices_used);
mutex_unlock(&devices_mutex);
/* prepare response buffer */ /* prepare response buffer */
snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size,
...@@ -279,9 +276,6 @@ do_registration(struct work_struct *work) ...@@ -279,9 +276,6 @@ do_registration(struct work_struct *work)
if (err < 0) if (err < 0)
goto error; goto error;
set_bit(card_index, devices_used);
mutex_unlock(&devices_mutex);
/* /*
* After registered, efw instance can be released corresponding to * After registered, efw instance can be released corresponding to
* releasing the sound card instance. * releasing the sound card instance.
...@@ -292,7 +286,6 @@ do_registration(struct work_struct *work) ...@@ -292,7 +286,6 @@ do_registration(struct work_struct *work)
return; return;
error: error:
mutex_unlock(&devices_mutex);
snd_efw_transaction_remove_instance(efw); snd_efw_transaction_remove_instance(efw);
snd_efw_stream_destroy_duplex(efw); snd_efw_stream_destroy_duplex(efw);
snd_card_free(efw->card); snd_card_free(efw->card);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment