.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * oxfw.c - a part of driver for OXFW970/971 based devices |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
---|
5 | | - * Licensed under the terms of the GNU General Public License, version 2. |
---|
6 | 6 | */ |
---|
7 | 7 | |
---|
8 | 8 | #include "oxfw.h" |
---|
.. | .. |
---|
114 | 114 | return err; |
---|
115 | 115 | } |
---|
116 | 116 | |
---|
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 | | - */ |
---|
143 | 117 | static void oxfw_card_free(struct snd_card *card) |
---|
144 | 118 | { |
---|
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); |
---|
146 | 123 | } |
---|
147 | 124 | |
---|
148 | 125 | static int detect_quirks(struct snd_oxfw *oxfw) |
---|
.. | .. |
---|
206 | 183 | static void do_registration(struct work_struct *work) |
---|
207 | 184 | { |
---|
208 | 185 | struct snd_oxfw *oxfw = container_of(work, struct snd_oxfw, dwork.work); |
---|
209 | | - int i; |
---|
210 | 186 | int err; |
---|
211 | 187 | |
---|
212 | 188 | if (oxfw->registered) |
---|
.. | .. |
---|
216 | 192 | &oxfw->card); |
---|
217 | 193 | if (err < 0) |
---|
218 | 194 | return; |
---|
| 195 | + oxfw->card->private_free = oxfw_card_free; |
---|
| 196 | + oxfw->card->private_data = oxfw; |
---|
219 | 197 | |
---|
220 | 198 | err = name_card(oxfw); |
---|
221 | 199 | if (err < 0) |
---|
.. | .. |
---|
229 | 207 | if (err < 0) |
---|
230 | 208 | goto error; |
---|
231 | 209 | |
---|
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); |
---|
237 | 226 | if (err < 0) |
---|
238 | 227 | goto error; |
---|
239 | 228 | } |
---|
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; |
---|
254 | 229 | |
---|
255 | 230 | err = snd_card_register(oxfw->card); |
---|
256 | 231 | if (err < 0) |
---|
257 | 232 | goto error; |
---|
258 | 233 | |
---|
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; |
---|
265 | 234 | oxfw->registered = true; |
---|
266 | 235 | |
---|
267 | 236 | return; |
---|
268 | 237 | 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 | | - } |
---|
278 | 238 | snd_card_free(oxfw->card); |
---|
279 | | - kfree(oxfw->spec); |
---|
280 | | - oxfw->spec = NULL; |
---|
281 | 239 | dev_info(&oxfw->unit->device, |
---|
282 | 240 | "Sound card registration failed: %d\n", err); |
---|
283 | 241 | } |
---|
.. | .. |
---|
291 | 249 | return -ENODEV; |
---|
292 | 250 | |
---|
293 | 251 | /* 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) |
---|
296 | 254 | return -ENOMEM; |
---|
297 | | - |
---|
298 | | - oxfw->entry = entry; |
---|
299 | 255 | oxfw->unit = fw_unit_get(unit); |
---|
300 | 256 | dev_set_drvdata(&unit->device, oxfw); |
---|
301 | 257 | |
---|
| 258 | + oxfw->entry = entry; |
---|
302 | 259 | mutex_init(&oxfw->mutex); |
---|
303 | 260 | spin_lock_init(&oxfw->lock); |
---|
304 | 261 | init_waitqueue_head(&oxfw->hwdep_wait); |
---|
.. | .. |
---|
320 | 277 | fcp_bus_reset(oxfw->unit); |
---|
321 | 278 | |
---|
322 | 279 | 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 | + } |
---|
330 | 285 | |
---|
331 | 286 | if (oxfw->entry->vendor_id == OUI_STANTON) |
---|
332 | 287 | snd_oxfw_scs1x_update(oxfw); |
---|
.. | .. |
---|
345 | 300 | cancel_delayed_work_sync(&oxfw->dwork); |
---|
346 | 301 | |
---|
347 | 302 | 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); |
---|
353 | 305 | } |
---|
| 306 | + |
---|
| 307 | + mutex_destroy(&oxfw->mutex); |
---|
| 308 | + fw_unit_put(oxfw->unit); |
---|
354 | 309 | } |
---|
355 | 310 | |
---|
356 | 311 | static const struct compat_info griffin_firewave = { |
---|