forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/sound/firewire/oxfw/oxfw.c
....@@ -1,8 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * oxfw.c - a part of driver for OXFW970/971 based devices
34 *
45 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5
- * Licensed under the terms of the GNU General Public License, version 2.
66 */
77
88 #include "oxfw.h"
....@@ -114,35 +114,12 @@
114114 return err;
115115 }
116116
117
-static void oxfw_free(struct snd_oxfw *oxfw)
118
-{
119
- unsigned int i;
120
-
121
- snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
122
- if (oxfw->has_output)
123
- snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
124
-
125
- fw_unit_put(oxfw->unit);
126
-
127
- for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
128
- kfree(oxfw->tx_stream_formats[i]);
129
- kfree(oxfw->rx_stream_formats[i]);
130
- }
131
-
132
- kfree(oxfw->spec);
133
- mutex_destroy(&oxfw->mutex);
134
- kfree(oxfw);
135
-}
136
-
137
-/*
138
- * This module releases the FireWire unit data after all ALSA character devices
139
- * are released by applications. This is for releasing stream data or finishing
140
- * transactions safely. Thus at returning from .remove(), this module still keep
141
- * references for the unit.
142
- */
143117 static void oxfw_card_free(struct snd_card *card)
144118 {
145
- oxfw_free(card->private_data);
119
+ struct snd_oxfw *oxfw = card->private_data;
120
+
121
+ if (oxfw->has_output || oxfw->has_input)
122
+ snd_oxfw_stream_destroy_duplex(oxfw);
146123 }
147124
148125 static int detect_quirks(struct snd_oxfw *oxfw)
....@@ -206,7 +183,6 @@
206183 static void do_registration(struct work_struct *work)
207184 {
208185 struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work);
209
- int i;
210186 int err;
211187
212188 if (oxfw->registered)
....@@ -216,6 +192,8 @@
216192 &oxfw->card);
217193 if (err < 0)
218194 return;
195
+ oxfw->card->private_free = oxfw_card_free;
196
+ oxfw->card->private_data = oxfw;
219197
220198 err = name_card(oxfw);
221199 if (err < 0)
....@@ -229,55 +207,35 @@
229207 if (err < 0)
230208 goto error;
231209
232
- err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
233
- if (err < 0)
234
- goto error;
235
- if (oxfw->has_output) {
236
- err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
210
+ if (oxfw->has_output || oxfw->has_input) {
211
+ err = snd_oxfw_stream_init_duplex(oxfw);
212
+ if (err < 0)
213
+ goto error;
214
+
215
+ err = snd_oxfw_create_pcm(oxfw);
216
+ if (err < 0)
217
+ goto error;
218
+
219
+ snd_oxfw_proc_init(oxfw);
220
+
221
+ err = snd_oxfw_create_midi(oxfw);
222
+ if (err < 0)
223
+ goto error;
224
+
225
+ err = snd_oxfw_create_hwdep(oxfw);
237226 if (err < 0)
238227 goto error;
239228 }
240
-
241
- err = snd_oxfw_create_pcm(oxfw);
242
- if (err < 0)
243
- goto error;
244
-
245
- snd_oxfw_proc_init(oxfw);
246
-
247
- err = snd_oxfw_create_midi(oxfw);
248
- if (err < 0)
249
- goto error;
250
-
251
- err = snd_oxfw_create_hwdep(oxfw);
252
- if (err < 0)
253
- goto error;
254229
255230 err = snd_card_register(oxfw->card);
256231 if (err < 0)
257232 goto error;
258233
259
- /*
260
- * After registered, oxfw instance can be released corresponding to
261
- * releasing the sound card instance.
262
- */
263
- oxfw->card->private_free = oxfw_card_free;
264
- oxfw->card->private_data = oxfw;
265234 oxfw->registered = true;
266235
267236 return;
268237 error:
269
- snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
270
- if (oxfw->has_output)
271
- snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
272
- for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; ++i) {
273
- kfree(oxfw->tx_stream_formats[i]);
274
- oxfw->tx_stream_formats[i] = NULL;
275
- kfree(oxfw->rx_stream_formats[i]);
276
- oxfw->rx_stream_formats[i] = NULL;
277
- }
278238 snd_card_free(oxfw->card);
279
- kfree(oxfw->spec);
280
- oxfw->spec = NULL;
281239 dev_info(&oxfw->unit->device,
282240 "Sound card registration failed: %d\n", err);
283241 }
....@@ -291,14 +249,13 @@
291249 return -ENODEV;
292250
293251 /* Allocate this independent of sound card instance. */
294
- oxfw = kzalloc(sizeof(struct snd_oxfw), GFP_KERNEL);
295
- if (oxfw == NULL)
252
+ oxfw = devm_kzalloc(&unit->device, sizeof(struct snd_oxfw), GFP_KERNEL);
253
+ if (!oxfw)
296254 return -ENOMEM;
297
-
298
- oxfw->entry = entry;
299255 oxfw->unit = fw_unit_get(unit);
300256 dev_set_drvdata(&unit->device, oxfw);
301257
258
+ oxfw->entry = entry;
302259 mutex_init(&oxfw->mutex);
303260 spin_lock_init(&oxfw->lock);
304261 init_waitqueue_head(&oxfw->hwdep_wait);
....@@ -320,13 +277,11 @@
320277 fcp_bus_reset(oxfw->unit);
321278
322279 if (oxfw->registered) {
323
- mutex_lock(&oxfw->mutex);
324
-
325
- snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
326
- if (oxfw->has_output)
327
- snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
328
-
329
- mutex_unlock(&oxfw->mutex);
280
+ if (oxfw->has_output || oxfw->has_input) {
281
+ mutex_lock(&oxfw->mutex);
282
+ snd_oxfw_stream_update_duplex(oxfw);
283
+ mutex_unlock(&oxfw->mutex);
284
+ }
330285
331286 if (oxfw->entry->vendor_id == OUI_STANTON)
332287 snd_oxfw_scs1x_update(oxfw);
....@@ -345,12 +300,12 @@
345300 cancel_delayed_work_sync(&oxfw->dwork);
346301
347302 if (oxfw->registered) {
348
- /* No need to wait for releasing card object in this context. */
349
- snd_card_free_when_closed(oxfw->card);
350
- } else {
351
- /* Don't forget this case. */
352
- oxfw_free(oxfw);
303
+ // Block till all of ALSA character devices are released.
304
+ snd_card_free(oxfw->card);
353305 }
306
+
307
+ mutex_destroy(&oxfw->mutex);
308
+ fw_unit_put(oxfw->unit);
354309 }
355310
356311 static const struct compat_info griffin_firewave = {