Skip to content

Commit

Permalink
ALSA: firewire: simplify cleanup process when failing to register sou…
Browse files Browse the repository at this point in the history
…nd 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>
  • Loading branch information
Takashi Sakamoto authored and Takashi Iwai committed Oct 10, 2018
1 parent 873608d commit 3babca4
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 138 deletions.
27 changes: 7 additions & 20 deletions sound/firewire/bebob/bebob.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,18 @@ name_device(struct snd_bebob *bebob)
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);

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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 5 additions & 21 deletions sound/firewire/dice/dice.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,14 @@ static void dice_card_strings(struct snd_dice *dice)
strcpy(card->mixername, "DICE");
}

static void dice_free(struct snd_dice *dice)
static void dice_card_free(struct snd_card *card)
{
struct snd_dice *dice = card->private_data;

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);
}

static void do_registration(struct work_struct *work)
{
struct snd_dice *dice = container_of(work, struct snd_dice, dwork.work);
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions sound/firewire/digi00x/digi00x.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ static int name_card(struct snd_dg00x *dg00x)
return 0;
}

static void dg00x_free(struct snd_dg00x *dg00x)
static void dg00x_card_free(struct snd_card *card)
{
struct snd_dg00x *dg00x = card->private_data;

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);
}

static void do_registration(struct work_struct *work)
{
struct snd_dg00x *dg00x =
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions sound/firewire/fireface/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ 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)
static void ff_card_free(struct snd_card *card)
{
struct snd_ff *ff = card->private_data;

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);
}

static void do_registration(struct work_struct *work)
{
struct snd_ff *ff = container_of(work, struct snd_ff, dwork.work);
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 7 additions & 21 deletions sound/firewire/fireworks/fireworks.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ get_hardware_info(struct snd_efw *efw)
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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 5 additions & 21 deletions sound/firewire/motu/motu.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,14 @@ 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)
static void motu_card_free(struct snd_card *card)
{
snd_motu_transaction_unregister(motu);
struct snd_motu *motu = card->private_data;

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);
}

static void do_registration(struct work_struct *work)
{
struct snd_motu *motu = container_of(work, struct snd_motu, dwork.work);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
26 changes: 5 additions & 21 deletions sound/firewire/oxfw/oxfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,15 @@ static int name_card(struct snd_oxfw *oxfw)
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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 3babca4

Please sign in to comment.