hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/firewire/bebob/bebob.c
....@@ -1,9 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * bebob.c - a part of driver for BeBoB based devices
34 *
45 * Copyright (c) 2013-2014 Takashi Sakamoto
5
- *
6
- * Licensed under the terms of the GNU General Public License, version 2.
76 */
87
98 /*
....@@ -127,23 +126,6 @@
127126 return err;
128127 }
129128
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
- */
147129 static void
148130 bebob_card_free(struct snd_card *card)
149131 {
....@@ -153,7 +135,7 @@
153135 clear_bit(bebob->card_index, devices_used);
154136 mutex_unlock(&devices_mutex);
155137
156
- bebob_free(card->private_data);
138
+ snd_bebob_stream_destroy_duplex(bebob);
157139 }
158140
159141 static const struct snd_bebob_spec *
....@@ -193,7 +175,6 @@
193175 return;
194176
195177 mutex_lock(&devices_mutex);
196
-
197178 for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
198179 if (!test_bit(card_index, devices_used) && enable[card_index])
199180 break;
....@@ -209,6 +190,11 @@
209190 mutex_unlock(&devices_mutex);
210191 return;
211192 }
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;
212198
213199 err = name_device(bebob);
214200 if (err < 0)
....@@ -249,23 +235,10 @@
249235 if (err < 0)
250236 goto error;
251237
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;
261238 bebob->registered = true;
262239
263240 return;
264241 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;
269242 snd_card_free(bebob->card);
270243 dev_info(&bebob->unit->device,
271244 "Sound card registration failed: %d\n", err);
....@@ -296,15 +269,15 @@
296269 }
297270
298271 /* 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)
301275 return -ENOMEM;
302
-
303276 bebob->unit = fw_unit_get(unit);
304
- bebob->entry = entry;
305
- bebob->spec = spec;
306277 dev_set_drvdata(&unit->device, bebob);
307278
279
+ bebob->entry = entry;
280
+ bebob->spec = spec;
308281 mutex_init(&bebob->mutex);
309282 spin_lock_init(&bebob->lock);
310283 init_waitqueue_head(&bebob->hwdep_wait);
....@@ -380,12 +353,12 @@
380353 cancel_delayed_work_sync(&bebob->dwork);
381354
382355 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);
388358 }
359
+
360
+ mutex_destroy(&bebob->mutex);
361
+ fw_unit_put(bebob->unit);
389362 }
390363
391364 static const struct snd_bebob_rate_spec normal_rate_spec = {
....@@ -539,7 +512,7 @@
539512 static struct fw_driver bebob_driver = {
540513 .driver = {
541514 .owner = THIS_MODULE,
542
- .name = "snd-bebob",
515
+ .name = KBUILD_MODNAME,
543516 .bus = &fw_bus_type,
544517 },
545518 .probe = bebob_probe,