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/bebob/bebob.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'sound/firewire/bebob') diff --git a/sound/firewire/bebob/bebob.c b/sound/firewire/bebob/bebob.c index 3bc68499974a..672d13488454 100644 --- a/sound/firewire/bebob/bebob.c +++ b/sound/firewire/bebob/bebob.c @@ -126,8 +126,11 @@ end: return err; } -static void bebob_free(struct snd_bebob *bebob) +static void +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); @@ -135,18 +138,6 @@ static void bebob_free(struct snd_bebob *bebob) snd_bebob_stream_destroy_duplex(bebob); } -/* - * 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 -bebob_card_free(struct snd_card *card) -{ - bebob_free(card->private_data); -} - static const struct snd_bebob_spec * get_saffire_spec(struct fw_unit *unit) { @@ -202,6 +193,9 @@ do_registration(struct work_struct *work) set_bit(card_index, devices_used); mutex_unlock(&devices_mutex); + bebob->card->private_free = bebob_card_free; + bebob->card->private_data = bebob; + err = name_device(bebob); if (err < 0) goto error; @@ -241,17 +235,10 @@ do_registration(struct work_struct *work) if (err < 0) goto error; - /* - * After registered, bebob instance can be released corresponding to - * releasing the sound card instance. - */ - bebob->card->private_free = bebob_card_free; - bebob->card->private_data = bebob; bebob->registered = true; return; error: - snd_bebob_stream_destroy_duplex(bebob); snd_card_free(bebob->card); dev_info(&bebob->unit->device, "Sound card registration failed: %d\n", err); -- cgit v1.2.3