summaryrefslogtreecommitdiffstats
path: root/sound/firewire/motu/motu.c
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2018-10-03 01:21:50 +0200
committerTakashi Iwai <tiwai@suse.de>2018-10-04 07:54:01 +0200
commit366a20d7a75cff7f89dede6fdfd41bd491aaf8ac (patch)
tree76d2420ee45eff7139a3ede8cd020cf7df7ed98a /sound/firewire/motu/motu.c
parentMerge branch 'for-linus' into for-next (diff)
downloadlinux-366a20d7a75cff7f89dede6fdfd41bd491aaf8ac.tar.xz
linux-366a20d7a75cff7f89dede6fdfd41bd491aaf8ac.zip
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>
Diffstat (limited to 'sound/firewire/motu/motu.c')
-rw-r--r--sound/firewire/motu/motu.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/sound/firewire/motu/motu.c b/sound/firewire/motu/motu.c
index 300d31b6f191..fd5726424c7a 100644
--- a/sound/firewire/motu/motu.c
+++ b/sound/firewire/motu/motu.c
@@ -57,10 +57,9 @@ static void motu_free(struct snd_motu *motu)
snd_motu_transaction_unregister(motu);
snd_motu_stream_destroy_duplex(motu);
- fw_unit_put(motu->unit);
mutex_destroy(&motu->mutex);
- kfree(motu);
+ fw_unit_put(motu->unit);
}
/*
@@ -143,14 +142,13 @@ static int motu_probe(struct fw_unit *unit,
struct snd_motu *motu;
/* Allocate this independently of sound card instance. */
- motu = kzalloc(sizeof(struct snd_motu), GFP_KERNEL);
- if (motu == NULL)
+ motu = devm_kzalloc(&unit->device, sizeof(struct snd_motu), GFP_KERNEL);
+ if (!motu)
return -ENOMEM;
-
- motu->spec = (const struct snd_motu_spec *)entry->driver_data;
motu->unit = fw_unit_get(unit);
dev_set_drvdata(&unit->device, motu);
+ motu->spec = (const struct snd_motu_spec *)entry->driver_data;
mutex_init(&motu->mutex);
spin_lock_init(&motu->lock);
init_waitqueue_head(&motu->hwdep_wait);