From 3babca4555b20fc80aff4776662fb237257d9afd Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 10 Oct 2018 15:35:02 +0900 Subject: ALSA: firewire: simplify cleanup process when failing to register sound card In former commits, .private_free callback releases resources just for data transmission. This release function can be called without the resources are actually allocated in error paths. This commit applies a small refactoring to clean up codes in error paths. Signed-off-by: Takashi Sakamoto Signed-off-by: Takashi Iwai --- sound/firewire/fireworks/fireworks.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'sound/firewire/fireworks') diff --git a/sound/firewire/fireworks/fireworks.c b/sound/firewire/fireworks/fireworks.c index da0c31033821..faf0e001c4c5 100644 --- a/sound/firewire/fireworks/fireworks.c +++ b/sound/firewire/fireworks/fireworks.c @@ -184,8 +184,11 @@ end: return err; } -static void efw_free(struct snd_efw *efw) +static void +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); @@ -194,18 +197,6 @@ static void efw_free(struct snd_efw *efw) snd_efw_transaction_remove_instance(efw); } -/* - * This module releases the FireWire unit data after all ALSA character devices - * are released by applications. This is for releasing stream data or finishing - * transactions safely. Thus at returning from .remove(), this module still keep - * references for the unit. - */ -static void -efw_card_free(struct snd_card *card) -{ - efw_free(card->private_data); -} - static void do_registration(struct work_struct *work) { @@ -236,6 +227,9 @@ do_registration(struct work_struct *work) set_bit(card_index, devices_used); mutex_unlock(&devices_mutex); + efw->card->private_free = efw_card_free; + efw->card->private_data = efw; + /* prepare response buffer */ snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size, SND_EFW_RESPONSE_MAXIMUM_BYTES, 4096U); @@ -276,18 +270,10 @@ do_registration(struct work_struct *work) if (err < 0) goto error; - /* - * After registered, efw instance can be released corresponding to - * releasing the sound card instance. - */ - efw->card->private_free = efw_card_free; - efw->card->private_data = efw; efw->registered = true; return; error: - snd_efw_transaction_remove_instance(efw); - snd_efw_stream_destroy_duplex(efw); snd_card_free(efw->card); dev_info(&efw->unit->device, "Sound card registration failed: %d\n", err); -- cgit v1.2.3