.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * bebob.c - a part of driver for BeBoB based devices |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2013-2014 Takashi Sakamoto |
---|
5 | | - * |
---|
6 | | - * Licensed under the terms of the GNU General Public License, version 2. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | /* |
---|
.. | .. |
---|
127 | 126 | return err; |
---|
128 | 127 | } |
---|
129 | 128 | |
---|
130 | | -static void bebob_free(struct snd_bebob *bebob) |
---|
131 | | -{ |
---|
132 | | - snd_bebob_stream_destroy_duplex(bebob); |
---|
133 | | - fw_unit_put(bebob->unit); |
---|
134 | | - |
---|
135 | | - kfree(bebob->maudio_special_quirk); |
---|
136 | | - |
---|
137 | | - mutex_destroy(&bebob->mutex); |
---|
138 | | - kfree(bebob); |
---|
139 | | -} |
---|
140 | | - |
---|
141 | | -/* |
---|
142 | | - * This module releases the FireWire unit data after all ALSA character devices |
---|
143 | | - * are released by applications. This is for releasing stream data or finishing |
---|
144 | | - * transactions safely. Thus at returning from .remove(), this module still keep |
---|
145 | | - * references for the unit. |
---|
146 | | - */ |
---|
147 | 129 | static void |
---|
148 | 130 | bebob_card_free(struct snd_card *card) |
---|
149 | 131 | { |
---|
.. | .. |
---|
153 | 135 | clear_bit(bebob->card_index, devices_used); |
---|
154 | 136 | mutex_unlock(&devices_mutex); |
---|
155 | 137 | |
---|
156 | | - bebob_free(card->private_data); |
---|
| 138 | + snd_bebob_stream_destroy_duplex(bebob); |
---|
157 | 139 | } |
---|
158 | 140 | |
---|
159 | 141 | static const struct snd_bebob_spec * |
---|
.. | .. |
---|
193 | 175 | return; |
---|
194 | 176 | |
---|
195 | 177 | mutex_lock(&devices_mutex); |
---|
196 | | - |
---|
197 | 178 | for (card_index = 0; card_index < SNDRV_CARDS; card_index++) { |
---|
198 | 179 | if (!test_bit(card_index, devices_used) && enable[card_index]) |
---|
199 | 180 | break; |
---|
.. | .. |
---|
209 | 190 | mutex_unlock(&devices_mutex); |
---|
210 | 191 | return; |
---|
211 | 192 | } |
---|
| 193 | + set_bit(card_index, devices_used); |
---|
| 194 | + mutex_unlock(&devices_mutex); |
---|
| 195 | + |
---|
| 196 | + bebob->card->private_free = bebob_card_free; |
---|
| 197 | + bebob->card->private_data = bebob; |
---|
212 | 198 | |
---|
213 | 199 | err = name_device(bebob); |
---|
214 | 200 | if (err < 0) |
---|
.. | .. |
---|
249 | 235 | if (err < 0) |
---|
250 | 236 | goto error; |
---|
251 | 237 | |
---|
252 | | - set_bit(card_index, devices_used); |
---|
253 | | - mutex_unlock(&devices_mutex); |
---|
254 | | - |
---|
255 | | - /* |
---|
256 | | - * After registered, bebob instance can be released corresponding to |
---|
257 | | - * releasing the sound card instance. |
---|
258 | | - */ |
---|
259 | | - bebob->card->private_free = bebob_card_free; |
---|
260 | | - bebob->card->private_data = bebob; |
---|
261 | 238 | bebob->registered = true; |
---|
262 | 239 | |
---|
263 | 240 | return; |
---|
264 | 241 | error: |
---|
265 | | - mutex_unlock(&devices_mutex); |
---|
266 | | - snd_bebob_stream_destroy_duplex(bebob); |
---|
267 | | - kfree(bebob->maudio_special_quirk); |
---|
268 | | - bebob->maudio_special_quirk = NULL; |
---|
269 | 242 | snd_card_free(bebob->card); |
---|
270 | 243 | dev_info(&bebob->unit->device, |
---|
271 | 244 | "Sound card registration failed: %d\n", err); |
---|
.. | .. |
---|
296 | 269 | } |
---|
297 | 270 | |
---|
298 | 271 | /* Allocate this independent of sound card instance. */ |
---|
299 | | - bebob = kzalloc(sizeof(struct snd_bebob), GFP_KERNEL); |
---|
300 | | - if (bebob == NULL) |
---|
| 272 | + bebob = devm_kzalloc(&unit->device, sizeof(struct snd_bebob), |
---|
| 273 | + GFP_KERNEL); |
---|
| 274 | + if (!bebob) |
---|
301 | 275 | return -ENOMEM; |
---|
302 | | - |
---|
303 | 276 | bebob->unit = fw_unit_get(unit); |
---|
304 | | - bebob->entry = entry; |
---|
305 | | - bebob->spec = spec; |
---|
306 | 277 | dev_set_drvdata(&unit->device, bebob); |
---|
307 | 278 | |
---|
| 279 | + bebob->entry = entry; |
---|
| 280 | + bebob->spec = spec; |
---|
308 | 281 | mutex_init(&bebob->mutex); |
---|
309 | 282 | spin_lock_init(&bebob->lock); |
---|
310 | 283 | init_waitqueue_head(&bebob->hwdep_wait); |
---|
.. | .. |
---|
380 | 353 | cancel_delayed_work_sync(&bebob->dwork); |
---|
381 | 354 | |
---|
382 | 355 | if (bebob->registered) { |
---|
383 | | - /* No need to wait for releasing card object in this context. */ |
---|
384 | | - snd_card_free_when_closed(bebob->card); |
---|
385 | | - } else { |
---|
386 | | - /* Don't forget this case. */ |
---|
387 | | - bebob_free(bebob); |
---|
| 356 | + // Block till all of ALSA character devices are released. |
---|
| 357 | + snd_card_free(bebob->card); |
---|
388 | 358 | } |
---|
| 359 | + |
---|
| 360 | + mutex_destroy(&bebob->mutex); |
---|
| 361 | + fw_unit_put(bebob->unit); |
---|
389 | 362 | } |
---|
390 | 363 | |
---|
391 | 364 | static const struct snd_bebob_rate_spec normal_rate_spec = { |
---|
.. | .. |
---|
539 | 512 | static struct fw_driver bebob_driver = { |
---|
540 | 513 | .driver = { |
---|
541 | 514 | .owner = THIS_MODULE, |
---|
542 | | - .name = "snd-bebob", |
---|
| 515 | + .name = KBUILD_MODNAME, |
---|
543 | 516 | .bus = &fw_bus_type, |
---|
544 | 517 | }, |
---|
545 | 518 | .probe = bebob_probe, |
---|