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 <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto
2018-10-10 15:35:02 +09:00
committed by Takashi Iwai
parent 873608dc6b
commit 3babca4555
8 changed files with 49 additions and 143 deletions

View File

@@ -122,21 +122,12 @@ static void dice_card_strings(struct snd_dice *dice)
strcpy(card->mixername, "DICE");
}
static void dice_free(struct snd_dice *dice)
{
snd_dice_stream_destroy_duplex(dice);
snd_dice_transaction_destroy(dice);
}
/*
* 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 dice_card_free(struct snd_card *card)
{
dice_free(card->private_data);
struct snd_dice *dice = card->private_data;
snd_dice_stream_destroy_duplex(dice);
snd_dice_transaction_destroy(dice);
}
static void do_registration(struct work_struct *work)
@@ -151,6 +142,8 @@ static void do_registration(struct work_struct *work)
&dice->card);
if (err < 0)
return;
dice->card->private_free = dice_card_free;
dice->card->private_data = dice;
err = snd_dice_transaction_init(dice);
if (err < 0)
@@ -188,19 +181,10 @@ static void do_registration(struct work_struct *work)
if (err < 0)
goto error;
/*
* After registered, dice instance can be released corresponding to
* releasing the sound card instance.
*/
dice->card->private_free = dice_card_free;
dice->card->private_data = dice;
dice->registered = true;
return;
error:
snd_dice_stream_destroy_duplex(dice);
snd_dice_transaction_destroy(dice);
snd_dice_stream_destroy_duplex(dice);
snd_card_free(dice->card);
dev_info(&dice->unit->device,
"Sound card registration failed: %d\n", err);