Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3babca45 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai
Browse files

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: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 873608dc
Loading
Loading
Loading
Loading
+7 −20
Original line number Diff line number Diff line
@@ -126,8 +126,11 @@ 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);
@@ -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);
+5 −21
Original line number Diff line number Diff line
@@ -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);
@@ -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);
+5 −10
Original line number Diff line number Diff line
@@ -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 =
@@ -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);
+5 −10
Original line number Diff line number Diff line
@@ -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);
@@ -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);
+7 −21
Original line number Diff line number Diff line
@@ -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);
@@ -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);
Loading