Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Takashi Sakamoto and committed by
Takashi Iwai
873608dc 5b14ec25

+13 -25
+6 -11
sound/firewire/bebob/bebob.c
··· 128 128 129 129 static void bebob_free(struct snd_bebob *bebob) 130 130 { 131 + mutex_lock(&devices_mutex); 132 + clear_bit(bebob->card_index, devices_used); 133 + mutex_unlock(&devices_mutex); 134 + 131 135 snd_bebob_stream_destroy_duplex(bebob); 132 136 } 133 137 ··· 144 140 static void 145 141 bebob_card_free(struct snd_card *card) 146 142 { 147 - struct snd_bebob *bebob = card->private_data; 148 - 149 - mutex_lock(&devices_mutex); 150 - clear_bit(bebob->card_index, devices_used); 151 - mutex_unlock(&devices_mutex); 152 - 153 143 bebob_free(card->private_data); 154 144 } 155 145 ··· 184 186 return; 185 187 186 188 mutex_lock(&devices_mutex); 187 - 188 189 for (card_index = 0; card_index < SNDRV_CARDS; card_index++) { 189 190 if (!test_bit(card_index, devices_used) && enable[card_index]) 190 191 break; ··· 199 202 mutex_unlock(&devices_mutex); 200 203 return; 201 204 } 205 + set_bit(card_index, devices_used); 206 + mutex_unlock(&devices_mutex); 202 207 203 208 err = name_device(bebob); 204 209 if (err < 0) ··· 241 242 if (err < 0) 242 243 goto error; 243 244 244 - set_bit(card_index, devices_used); 245 - mutex_unlock(&devices_mutex); 246 - 247 245 /* 248 246 * After registered, bebob instance can be released corresponding to 249 247 * releasing the sound card instance. ··· 251 255 252 256 return; 253 257 error: 254 - mutex_unlock(&devices_mutex); 255 258 snd_bebob_stream_destroy_duplex(bebob); 256 259 snd_card_free(bebob->card); 257 260 dev_info(&bebob->unit->device,
+7 -14
sound/firewire/fireworks/fireworks.c
··· 186 186 187 187 static void efw_free(struct snd_efw *efw) 188 188 { 189 + mutex_lock(&devices_mutex); 190 + clear_bit(efw->card_index, devices_used); 191 + mutex_unlock(&devices_mutex); 192 + 189 193 snd_efw_stream_destroy_duplex(efw); 190 194 snd_efw_transaction_remove_instance(efw); 191 195 } ··· 203 199 static void 204 200 efw_card_free(struct snd_card *card) 205 201 { 206 - struct snd_efw *efw = card->private_data; 207 - 208 - if (efw->card_index >= 0) { 209 - mutex_lock(&devices_mutex); 210 - clear_bit(efw->card_index, devices_used); 211 - mutex_unlock(&devices_mutex); 212 - } 213 - 214 202 efw_free(card->private_data); 215 203 } 216 204 ··· 216 220 if (efw->registered) 217 221 return; 218 222 219 - mutex_lock(&devices_mutex); 220 - 221 223 /* check registered cards */ 224 + mutex_lock(&devices_mutex); 222 225 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) { 223 226 if (!test_bit(card_index, devices_used) && enable[card_index]) 224 227 break; ··· 233 238 mutex_unlock(&devices_mutex); 234 239 return; 235 240 } 241 + set_bit(card_index, devices_used); 242 + mutex_unlock(&devices_mutex); 236 243 237 244 /* prepare response buffer */ 238 245 snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, ··· 276 279 if (err < 0) 277 280 goto error; 278 281 279 - set_bit(card_index, devices_used); 280 - mutex_unlock(&devices_mutex); 281 - 282 282 /* 283 283 * After registered, efw instance can be released corresponding to 284 284 * releasing the sound card instance. ··· 286 292 287 293 return; 288 294 error: 289 - mutex_unlock(&devices_mutex); 290 295 snd_efw_transaction_remove_instance(efw); 291 296 snd_efw_stream_destroy_duplex(efw); 292 297 snd_card_free(efw->card);