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:
Родитель
873608dc6b
Коммит
3babca4555
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -41,15 +41,12 @@ static int name_card(struct snd_dg00x *dg00x)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dg00x_free(struct snd_dg00x *dg00x)
|
||||
{
|
||||
snd_dg00x_stream_destroy_duplex(dg00x);
|
||||
snd_dg00x_transaction_unregister(dg00x);
|
||||
}
|
||||
|
||||
static void dg00x_card_free(struct snd_card *card)
|
||||
{
|
||||
dg00x_free(card->private_data);
|
||||
struct snd_dg00x *dg00x = card->private_data;
|
||||
|
||||
snd_dg00x_stream_destroy_duplex(dg00x);
|
||||
snd_dg00x_transaction_unregister(dg00x);
|
||||
}
|
||||
|
||||
static void do_registration(struct work_struct *work)
|
||||
|
@ -65,6 +62,8 @@ static void do_registration(struct work_struct *work)
|
|||
&dg00x->card);
|
||||
if (err < 0)
|
||||
return;
|
||||
dg00x->card->private_free = dg00x_card_free;
|
||||
dg00x->card->private_data = dg00x;
|
||||
|
||||
err = name_card(dg00x);
|
||||
if (err < 0)
|
||||
|
@ -96,14 +95,10 @@ static void do_registration(struct work_struct *work)
|
|||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
dg00x->card->private_free = dg00x_card_free;
|
||||
dg00x->card->private_data = dg00x;
|
||||
dg00x->registered = true;
|
||||
|
||||
return;
|
||||
error:
|
||||
snd_dg00x_transaction_unregister(dg00x);
|
||||
snd_dg00x_stream_destroy_duplex(dg00x);
|
||||
snd_card_free(dg00x->card);
|
||||
dev_info(&dg00x->unit->device,
|
||||
"Sound card registration failed: %d\n", err);
|
||||
|
|
|
@ -27,15 +27,12 @@ static void name_card(struct snd_ff *ff)
|
|||
dev_name(&ff->unit->device), 100 << fw_dev->max_speed);
|
||||
}
|
||||
|
||||
static void ff_free(struct snd_ff *ff)
|
||||
{
|
||||
snd_ff_stream_destroy_duplex(ff);
|
||||
snd_ff_transaction_unregister(ff);
|
||||
}
|
||||
|
||||
static void ff_card_free(struct snd_card *card)
|
||||
{
|
||||
ff_free(card->private_data);
|
||||
struct snd_ff *ff = card->private_data;
|
||||
|
||||
snd_ff_stream_destroy_duplex(ff);
|
||||
snd_ff_transaction_unregister(ff);
|
||||
}
|
||||
|
||||
static void do_registration(struct work_struct *work)
|
||||
|
@ -50,6 +47,8 @@ static void do_registration(struct work_struct *work)
|
|||
&ff->card);
|
||||
if (err < 0)
|
||||
return;
|
||||
ff->card->private_free = ff_card_free;
|
||||
ff->card->private_data = ff;
|
||||
|
||||
err = snd_ff_transaction_register(ff);
|
||||
if (err < 0)
|
||||
|
@ -79,14 +78,10 @@ static void do_registration(struct work_struct *work)
|
|||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
ff->card->private_free = ff_card_free;
|
||||
ff->card->private_data = ff;
|
||||
ff->registered = true;
|
||||
|
||||
return;
|
||||
error:
|
||||
snd_ff_transaction_unregister(ff);
|
||||
snd_ff_stream_destroy_duplex(ff);
|
||||
snd_card_free(ff->card);
|
||||
dev_info(&ff->unit->device,
|
||||
"Sound card registration failed: %d\n", err);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -52,22 +52,12 @@ static void name_card(struct snd_motu *motu)
|
|||
dev_name(&motu->unit->device), 100 << fw_dev->max_speed);
|
||||
}
|
||||
|
||||
static void motu_free(struct snd_motu *motu)
|
||||
{
|
||||
snd_motu_transaction_unregister(motu);
|
||||
|
||||
snd_motu_stream_destroy_duplex(motu);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 motu_card_free(struct snd_card *card)
|
||||
{
|
||||
motu_free(card->private_data);
|
||||
struct snd_motu *motu = card->private_data;
|
||||
|
||||
snd_motu_transaction_unregister(motu);
|
||||
snd_motu_stream_destroy_duplex(motu);
|
||||
}
|
||||
|
||||
static void do_registration(struct work_struct *work)
|
||||
|
@ -82,6 +72,8 @@ static void do_registration(struct work_struct *work)
|
|||
&motu->card);
|
||||
if (err < 0)
|
||||
return;
|
||||
motu->card->private_free = motu_card_free;
|
||||
motu->card->private_data = motu;
|
||||
|
||||
name_card(motu);
|
||||
|
||||
|
@ -116,18 +108,10 @@ static void do_registration(struct work_struct *work)
|
|||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* After registered, motu instance can be released corresponding to
|
||||
* releasing the sound card instance.
|
||||
*/
|
||||
motu->card->private_free = motu_card_free;
|
||||
motu->card->private_data = motu;
|
||||
motu->registered = true;
|
||||
|
||||
return;
|
||||
error:
|
||||
snd_motu_transaction_unregister(motu);
|
||||
snd_motu_stream_destroy_duplex(motu);
|
||||
snd_card_free(motu->card);
|
||||
dev_info(&motu->unit->device,
|
||||
"Sound card registration failed: %d\n", err);
|
||||
|
|
|
@ -113,24 +113,15 @@ end:
|
|||
return err;
|
||||
}
|
||||
|
||||
static void oxfw_free(struct snd_oxfw *oxfw)
|
||||
static void oxfw_card_free(struct snd_card *card)
|
||||
{
|
||||
struct snd_oxfw *oxfw = card->private_data;
|
||||
|
||||
snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
|
||||
if (oxfw->has_output)
|
||||
snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 oxfw_card_free(struct snd_card *card)
|
||||
{
|
||||
oxfw_free(card->private_data);
|
||||
}
|
||||
|
||||
static int detect_quirks(struct snd_oxfw *oxfw)
|
||||
{
|
||||
struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
|
||||
|
@ -204,6 +195,8 @@ static void do_registration(struct work_struct *work)
|
|||
&oxfw->card);
|
||||
if (err < 0)
|
||||
return;
|
||||
oxfw->card->private_free = oxfw_card_free;
|
||||
oxfw->card->private_data = oxfw;
|
||||
|
||||
err = name_card(oxfw);
|
||||
if (err < 0)
|
||||
|
@ -244,19 +237,10 @@ static void do_registration(struct work_struct *work)
|
|||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* After registered, oxfw instance can be released corresponding to
|
||||
* releasing the sound card instance.
|
||||
*/
|
||||
oxfw->card->private_free = oxfw_card_free;
|
||||
oxfw->card->private_data = oxfw;
|
||||
oxfw->registered = true;
|
||||
|
||||
return;
|
||||
error:
|
||||
snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
|
||||
if (oxfw->has_output)
|
||||
snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
|
||||
snd_card_free(oxfw->card);
|
||||
dev_info(&oxfw->unit->device,
|
||||
"Sound card registration failed: %d\n", err);
|
||||
|
|
|
@ -85,15 +85,12 @@ static int identify_model(struct snd_tscm *tscm)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void tscm_free(struct snd_tscm *tscm)
|
||||
{
|
||||
snd_tscm_transaction_unregister(tscm);
|
||||
snd_tscm_stream_destroy_duplex(tscm);
|
||||
}
|
||||
|
||||
static void tscm_card_free(struct snd_card *card)
|
||||
{
|
||||
tscm_free(card->private_data);
|
||||
struct snd_tscm *tscm = card->private_data;
|
||||
|
||||
snd_tscm_transaction_unregister(tscm);
|
||||
snd_tscm_stream_destroy_duplex(tscm);
|
||||
}
|
||||
|
||||
static void do_registration(struct work_struct *work)
|
||||
|
@ -105,6 +102,8 @@ static void do_registration(struct work_struct *work)
|
|||
&tscm->card);
|
||||
if (err < 0)
|
||||
return;
|
||||
tscm->card->private_free = tscm_card_free;
|
||||
tscm->card->private_data = tscm;
|
||||
|
||||
err = identify_model(tscm);
|
||||
if (err < 0)
|
||||
|
@ -136,18 +135,10 @@ static void do_registration(struct work_struct *work)
|
|||
if (err < 0)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* After registered, tscm instance can be released corresponding to
|
||||
* releasing the sound card instance.
|
||||
*/
|
||||
tscm->card->private_free = tscm_card_free;
|
||||
tscm->card->private_data = tscm;
|
||||
tscm->registered = true;
|
||||
|
||||
return;
|
||||
error:
|
||||
snd_tscm_transaction_unregister(tscm);
|
||||
snd_tscm_stream_destroy_duplex(tscm);
|
||||
snd_card_free(tscm->card);
|
||||
dev_info(&tscm->unit->device,
|
||||
"Sound card registration failed: %d\n", err);
|
||||
|
|
Загрузка…
Ссылка в новой задаче