forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/firewire/fireworks/fireworks.c
....@@ -1,10 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * fireworks.c - a part of driver for Fireworks based devices
34 *
45 * Copyright (c) 2009-2010 Clemens Ladisch
56 * Copyright (c) 2013-2014 Takashi Sakamoto
6
- *
7
- * Licensed under the terms of the GNU General Public License, version 2.
87 */
98
109 /*
....@@ -184,36 +183,17 @@
184183 return err;
185184 }
186185
187
-static void efw_free(struct snd_efw *efw)
188
-{
189
- snd_efw_stream_destroy_duplex(efw);
190
- snd_efw_transaction_remove_instance(efw);
191
- fw_unit_put(efw->unit);
192
-
193
- kfree(efw->resp_buf);
194
-
195
- mutex_destroy(&efw->mutex);
196
- kfree(efw);
197
-}
198
-
199
-/*
200
- * This module releases the FireWire unit data after all ALSA character devices
201
- * are released by applications. This is for releasing stream data or finishing
202
- * transactions safely. Thus at returning from .remove(), this module still keep
203
- * references for the unit.
204
- */
205186 static void
206187 efw_card_free(struct snd_card *card)
207188 {
208189 struct snd_efw *efw = card->private_data;
209190
210
- if (efw->card_index >= 0) {
211
- mutex_lock(&devices_mutex);
212
- clear_bit(efw->card_index, devices_used);
213
- mutex_unlock(&devices_mutex);
214
- }
191
+ mutex_lock(&devices_mutex);
192
+ clear_bit(efw->card_index, devices_used);
193
+ mutex_unlock(&devices_mutex);
215194
216
- efw_free(card->private_data);
195
+ snd_efw_stream_destroy_duplex(efw);
196
+ snd_efw_transaction_remove_instance(efw);
217197 }
218198
219199 static void
....@@ -226,9 +206,8 @@
226206 if (efw->registered)
227207 return;
228208
229
- mutex_lock(&devices_mutex);
230
-
231209 /* check registered cards */
210
+ mutex_lock(&devices_mutex);
232211 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
233212 if (!test_bit(card_index, devices_used) && enable[card_index])
234213 break;
....@@ -244,12 +223,18 @@
244223 mutex_unlock(&devices_mutex);
245224 return;
246225 }
226
+ set_bit(card_index, devices_used);
227
+ mutex_unlock(&devices_mutex);
228
+
229
+ efw->card->private_free = efw_card_free;
230
+ efw->card->private_data = efw;
247231
248232 /* prepare response buffer */
249233 snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size,
250234 SND_EFW_RESPONSE_MAXIMUM_BYTES, 4096U);
251
- efw->resp_buf = kzalloc(snd_efw_resp_buf_size, GFP_KERNEL);
252
- if (efw->resp_buf == NULL) {
235
+ efw->resp_buf = devm_kzalloc(&efw->card->card_dev,
236
+ snd_efw_resp_buf_size, GFP_KERNEL);
237
+ if (!efw->resp_buf) {
253238 err = -ENOMEM;
254239 goto error;
255240 }
....@@ -284,25 +269,11 @@
284269 if (err < 0)
285270 goto error;
286271
287
- set_bit(card_index, devices_used);
288
- mutex_unlock(&devices_mutex);
289
-
290
- /*
291
- * After registered, efw instance can be released corresponding to
292
- * releasing the sound card instance.
293
- */
294
- efw->card->private_free = efw_card_free;
295
- efw->card->private_data = efw;
296272 efw->registered = true;
297273
298274 return;
299275 error:
300
- mutex_unlock(&devices_mutex);
301
- snd_efw_transaction_remove_instance(efw);
302
- snd_efw_stream_destroy_duplex(efw);
303276 snd_card_free(efw->card);
304
- kfree(efw->resp_buf);
305
- efw->resp_buf = NULL;
306277 dev_info(&efw->unit->device,
307278 "Sound card registration failed: %d\n", err);
308279 }
....@@ -312,10 +283,9 @@
312283 {
313284 struct snd_efw *efw;
314285
315
- efw = kzalloc(sizeof(struct snd_efw), GFP_KERNEL);
286
+ efw = devm_kzalloc(&unit->device, sizeof(struct snd_efw), GFP_KERNEL);
316287 if (efw == NULL)
317288 return -ENOMEM;
318
-
319289 efw->unit = fw_unit_get(unit);
320290 dev_set_drvdata(&unit->device, efw);
321291
....@@ -363,12 +333,12 @@
363333 cancel_delayed_work_sync(&efw->dwork);
364334
365335 if (efw->registered) {
366
- /* No need to wait for releasing card object in this context. */
367
- snd_card_free_when_closed(efw->card);
368
- } else {
369
- /* Don't forget this case. */
370
- efw_free(efw);
336
+ // Block till all of ALSA character devices are released.
337
+ snd_card_free(efw->card);
371338 }
339
+
340
+ mutex_destroy(&efw->mutex);
341
+ fw_unit_put(efw->unit);
372342 }
373343
374344 static const struct ieee1394_device_id efw_id_table[] = {
....@@ -392,7 +362,7 @@
392362 static struct fw_driver efw_driver = {
393363 .driver = {
394364 .owner = THIS_MODULE,
395
- .name = "snd-fireworks",
365
+ .name = KBUILD_MODNAME,
396366 .bus = &fw_bus_type,
397367 },
398368 .probe = efw_probe,