From 366a20d7a75cff7f89dede6fdfd41bd491aaf8ac Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 3 Oct 2018 08:21:50 +0900 Subject: 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: Takashi Sakamoto Signed-off-by: Takashi Iwai --- sound/firewire/dice/dice.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'sound/firewire/dice') diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c index 774eb2205668..9bf77adb3127 100644 --- a/sound/firewire/dice/dice.c +++ b/sound/firewire/dice/dice.c @@ -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); -- cgit