summaryrefslogtreecommitdiffstats
path: root/sound/firewire/motu
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2018-10-02 19:21:50 -0400
committerTakashi Iwai <tiwai@suse.de>2018-10-04 01:54:01 -0400
commit366a20d7a75cff7f89dede6fdfd41bd491aaf8ac (patch)
tree76d2420ee45eff7139a3ede8cd020cf7df7ed98a /sound/firewire/motu
parent4a9a72e0db5e584267944f4d868f46419b2fab59 (diff)
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')
-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)
57 snd_motu_transaction_unregister(motu); 57 snd_motu_transaction_unregister(motu);
58 58
59 snd_motu_stream_destroy_duplex(motu); 59 snd_motu_stream_destroy_duplex(motu);
60 fw_unit_put(motu->unit);
61 60
62 mutex_destroy(&motu->mutex); 61 mutex_destroy(&motu->mutex);
63 kfree(motu); 62 fw_unit_put(motu->unit);
64} 63}
65 64
66/* 65/*
@@ -143,14 +142,13 @@ static int motu_probe(struct fw_unit *unit,
143 struct snd_motu *motu; 142 struct snd_motu *motu;
144 143
145 /* Allocate this independently of sound card instance. */ 144 /* Allocate this independently of sound card instance. */
146 motu = kzalloc(sizeof(struct snd_motu), GFP_KERNEL); 145 motu = devm_kzalloc(&unit->device, sizeof(struct snd_motu), GFP_KERNEL);
147 if (motu == NULL) 146 if (!motu)
148 return -ENOMEM; 147 return -ENOMEM;
149
150 motu->spec = (const struct snd_motu_spec *)entry->driver_data;
151 motu->unit = fw_unit_get(unit); 148 motu->unit = fw_unit_get(unit);
152 dev_set_drvdata(&unit->device, motu); 149 dev_set_drvdata(&unit->device, motu);
153 150
151 motu->spec = (const struct snd_motu_spec *)entry->driver_data;
154 mutex_init(&motu->mutex); 152 mutex_init(&motu->mutex);
155 spin_lock_init(&motu->lock); 153 spin_lock_init(&motu->lock);
156 init_waitqueue_head(&motu->hwdep_wait); 154 init_waitqueue_head(&motu->hwdep_wait);