hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/sound/core/seq/seq_timer.c
....@@ -1,23 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ALSA sequencer Timer
34 * Copyright (c) 1998-1999 by Frank van de Pol <fvdpol@coil.demon.nl>
45 * Jaroslav Kysela <perex@perex.cz>
5
- *
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU General Public License
18
- * along with this program; if not, write to the Free Software
19
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
- *
216 */
227
238 #include <sound/core.h>
....@@ -287,7 +272,13 @@
287272 return -EINVAL;
288273 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE)
289274 tmr->alsa_id.dev_sclass = SNDRV_TIMER_SCLASS_SEQUENCER;
290
- err = snd_timer_open(&t, str, &tmr->alsa_id, q->queue);
275
+ t = snd_timer_instance_new(str);
276
+ if (!t)
277
+ return -ENOMEM;
278
+ t->callback = snd_seq_timer_interrupt;
279
+ t->callback_data = q;
280
+ t->flags |= SNDRV_TIMER_IFLG_AUTO;
281
+ err = snd_timer_open(t, &tmr->alsa_id, q->queue);
291282 if (err < 0 && tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_SLAVE) {
292283 if (tmr->alsa_id.dev_class != SNDRV_TIMER_CLASS_GLOBAL ||
293284 tmr->alsa_id.device != SNDRV_TIMER_GLOBAL_SYSTEM) {
....@@ -297,19 +288,25 @@
297288 tid.dev_sclass = SNDRV_TIMER_SCLASS_SEQUENCER;
298289 tid.card = -1;
299290 tid.device = SNDRV_TIMER_GLOBAL_SYSTEM;
300
- err = snd_timer_open(&t, str, &tid, q->queue);
291
+ err = snd_timer_open(t, &tid, q->queue);
301292 }
302293 }
303294 if (err < 0) {
304295 pr_err("ALSA: seq fatal error: cannot create timer (%i)\n", err);
296
+ snd_timer_instance_free(t);
305297 return err;
306298 }
307
- t->callback = snd_seq_timer_interrupt;
308
- t->callback_data = q;
309
- t->flags |= SNDRV_TIMER_IFLG_AUTO;
310299 spin_lock_irq(&tmr->lock);
311
- tmr->timeri = t;
300
+ if (tmr->timeri)
301
+ err = -EBUSY;
302
+ else
303
+ tmr->timeri = t;
312304 spin_unlock_irq(&tmr->lock);
305
+ if (err < 0) {
306
+ snd_timer_close(t);
307
+ snd_timer_instance_free(t);
308
+ return err;
309
+ }
313310 return 0;
314311 }
315312
....@@ -325,8 +322,10 @@
325322 t = tmr->timeri;
326323 tmr->timeri = NULL;
327324 spin_unlock_irq(&tmr->lock);
328
- if (t)
325
+ if (t) {
329326 snd_timer_close(t);
327
+ snd_timer_instance_free(t);
328
+ }
330329 return 0;
331330 }
332331