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 <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
此提交包含在:
Takashi Sakamoto
2018-10-03 08:21:50 +09:00
提交者 Takashi Iwai
父節點 4a9a72e0db
當前提交 366a20d7a7
共有 8 個檔案被更改,包括 29 行新增48 行删除

查看文件

@@ -129,12 +129,11 @@ end:
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);