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

Commit 366a20d7 authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai
Browse files

ALSA: firewire: use managed-resource of fw unit device for private data



At present, private data of each driver in ALSA firewire stack is
allocated/freed by kernel slab allocator for corresponding unit on
IEEE 1394 bus. In this case, resource-managed slab allocator is
available to release memory object automatically just before releasing
device structure for the unit. This idea can prevent runtime from
memory leak due to programming mistakes.

This commit uses the allocator for the private data. These drivers
already use reference counter to maintain lifetime of device structure
for the unit by a pair of fw_unit_get()/fw_unit_put(). The private data
is safely released in a callback of 'struct snd_card.private_free().

Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 4a9a72e0
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -129,12 +129,11 @@ name_device(struct snd_bebob *bebob)
static void bebob_free(struct snd_bebob *bebob)
{
	snd_bebob_stream_destroy_duplex(bebob);
	fw_unit_put(bebob->unit);

	kfree(bebob->maudio_special_quirk);

	mutex_destroy(&bebob->mutex);
	kfree(bebob);
	fw_unit_put(bebob->unit);
}

/*
@@ -295,15 +294,15 @@ bebob_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
	}

	/* Allocate this independent of sound card instance. */
	bebob = kzalloc(sizeof(struct snd_bebob), GFP_KERNEL);
	if (bebob == NULL)
	bebob = devm_kzalloc(&unit->device, sizeof(struct snd_bebob),
			     GFP_KERNEL);
	if (!bebob)
		return -ENOMEM;

	bebob->unit = fw_unit_get(unit);
	bebob->entry = entry;
	bebob->spec = spec;
	dev_set_drvdata(&unit->device, bebob);

	bebob->entry = entry;
	bebob->spec = spec;
	mutex_init(&bebob->mutex);
	spin_lock_init(&bebob->lock);
	init_waitqueue_head(&bebob->hwdep_wait);
+3 −5
Original line number Diff line number Diff line
@@ -126,10 +126,9 @@ static void dice_free(struct snd_dice *dice)
{
	snd_dice_stream_destroy_duplex(dice);
	snd_dice_transaction_destroy(dice);
	fw_unit_put(dice->unit);

	mutex_destroy(&dice->mutex);
	kfree(dice);
	fw_unit_put(dice->unit);
}

/*
@@ -223,10 +222,9 @@ static int dice_probe(struct fw_unit *unit,
	}

	/* Allocate this independent of sound card instance. */
	dice = kzalloc(sizeof(struct snd_dice), GFP_KERNEL);
	if (dice == NULL)
	dice = devm_kzalloc(&unit->device, sizeof(struct snd_dice), GFP_KERNEL);
	if (!dice)
		return -ENOMEM;

	dice->unit = fw_unit_get(unit);
	dev_set_drvdata(&unit->device, dice);

+4 −5
Original line number Diff line number Diff line
@@ -46,10 +46,8 @@ static void dg00x_free(struct snd_dg00x *dg00x)
	snd_dg00x_stream_destroy_duplex(dg00x);
	snd_dg00x_transaction_unregister(dg00x);

	fw_unit_put(dg00x->unit);

	mutex_destroy(&dg00x->mutex);
	kfree(dg00x);
	fw_unit_put(dg00x->unit);
}

static void dg00x_card_free(struct snd_card *card)
@@ -120,8 +118,9 @@ static int snd_dg00x_probe(struct fw_unit *unit,
	struct snd_dg00x *dg00x;

	/* Allocate this independent of sound card instance. */
	dg00x = kzalloc(sizeof(struct snd_dg00x), GFP_KERNEL);
	if (dg00x == NULL)
	dg00x = devm_kzalloc(&unit->device, sizeof(struct snd_dg00x),
			     GFP_KERNEL);
	if (!dg00x)
		return -ENOMEM;

	dg00x->unit = fw_unit_get(unit);
+3 −7
Original line number Diff line number Diff line
@@ -32,10 +32,8 @@ static void ff_free(struct snd_ff *ff)
	snd_ff_stream_destroy_duplex(ff);
	snd_ff_transaction_unregister(ff);

	fw_unit_put(ff->unit);

	mutex_destroy(&ff->mutex);
	kfree(ff);
	fw_unit_put(ff->unit);
}

static void ff_card_free(struct snd_card *card)
@@ -102,11 +100,9 @@ static int snd_ff_probe(struct fw_unit *unit,
{
	struct snd_ff *ff;

	ff = kzalloc(sizeof(struct snd_ff), GFP_KERNEL);
	if (ff == NULL)
	ff = devm_kzalloc(&unit->device, sizeof(struct snd_ff), GFP_KERNEL);
	if (!ff)
		return -ENOMEM;

	/* initialize myself */
	ff->unit = fw_unit_get(unit);
	dev_set_drvdata(&unit->device, ff);

+2 −4
Original line number Diff line number Diff line
@@ -188,12 +188,11 @@ static void efw_free(struct snd_efw *efw)
{
	snd_efw_stream_destroy_duplex(efw);
	snd_efw_transaction_remove_instance(efw);
	fw_unit_put(efw->unit);

	kfree(efw->resp_buf);

	mutex_destroy(&efw->mutex);
	kfree(efw);
	fw_unit_put(efw->unit);
}

/*
@@ -312,10 +311,9 @@ efw_probe(struct fw_unit *unit, const struct ieee1394_device_id *entry)
{
	struct snd_efw *efw;

	efw = kzalloc(sizeof(struct snd_efw), GFP_KERNEL);
	efw = devm_kzalloc(&unit->device, sizeof(struct snd_efw), GFP_KERNEL);
	if (efw == NULL)
		return -ENOMEM;

	efw->unit = fw_unit_get(unit);
	dev_set_drvdata(&unit->device, efw);

Loading