forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/sound/core/seq/oss/seq_oss_midi.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * OSS compatible sequencer driver
34 *
45 * MIDI device handlers
56 *
67 * Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218 */
229
2310 #include <sound/asoundef.h>
....@@ -50,6 +37,7 @@
5037 struct snd_midi_event *coder; /* MIDI event coder */
5138 struct seq_oss_devinfo *devinfo; /* assigned OSSseq device */
5239 snd_use_lock_t use_lock;
40
+ struct mutex open_mutex;
5341 };
5442
5543
....@@ -184,6 +172,7 @@
184172 mdev->flags = pinfo->capability;
185173 mdev->opened = 0;
186174 snd_use_lock_init(&mdev->use_lock);
175
+ mutex_init(&mdev->open_mutex);
187176
188177 /* copy and truncate the name of synth device */
189178 strlcpy(mdev->name, pinfo->name, sizeof(mdev->name));
....@@ -280,7 +269,9 @@
280269 void
281270 snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp)
282271 {
272
+ spin_lock_irq(&register_lock);
283273 dp->max_mididev = max_midi_devs;
274
+ spin_unlock_irq(&register_lock);
284275 }
285276
286277 /*
....@@ -330,14 +321,16 @@
330321 int perm;
331322 struct seq_oss_midi *mdev;
332323 struct snd_seq_port_subscribe subs;
324
+ int err;
333325
334326 if ((mdev = get_mididev(dp, dev)) == NULL)
335327 return -ENODEV;
336328
329
+ mutex_lock(&mdev->open_mutex);
337330 /* already used? */
338331 if (mdev->opened && mdev->devinfo != dp) {
339
- snd_use_lock_free(&mdev->use_lock);
340
- return -EBUSY;
332
+ err = -EBUSY;
333
+ goto unlock;
341334 }
342335
343336 perm = 0;
....@@ -347,14 +340,14 @@
347340 perm |= PERM_READ;
348341 perm &= mdev->flags;
349342 if (perm == 0) {
350
- snd_use_lock_free(&mdev->use_lock);
351
- return -ENXIO;
343
+ err = -ENXIO;
344
+ goto unlock;
352345 }
353346
354347 /* already opened? */
355348 if ((mdev->opened & perm) == perm) {
356
- snd_use_lock_free(&mdev->use_lock);
357
- return 0;
349
+ err = 0;
350
+ goto unlock;
358351 }
359352
360353 perm &= ~mdev->opened;
....@@ -379,13 +372,17 @@
379372 }
380373
381374 if (! mdev->opened) {
382
- snd_use_lock_free(&mdev->use_lock);
383
- return -ENXIO;
375
+ err = -ENXIO;
376
+ goto unlock;
384377 }
385378
386379 mdev->devinfo = dp;
380
+ err = 0;
381
+
382
+ unlock:
383
+ mutex_unlock(&mdev->open_mutex);
387384 snd_use_lock_free(&mdev->use_lock);
388
- return 0;
385
+ return err;
389386 }
390387
391388 /*
....@@ -399,10 +396,9 @@
399396
400397 if ((mdev = get_mididev(dp, dev)) == NULL)
401398 return -ENODEV;
402
- if (! mdev->opened || mdev->devinfo != dp) {
403
- snd_use_lock_free(&mdev->use_lock);
404
- return 0;
405
- }
399
+ mutex_lock(&mdev->open_mutex);
400
+ if (!mdev->opened || mdev->devinfo != dp)
401
+ goto unlock;
406402
407403 memset(&subs, 0, sizeof(subs));
408404 if (mdev->opened & PERM_WRITE) {
....@@ -421,6 +417,8 @@
421417 mdev->opened = 0;
422418 mdev->devinfo = NULL;
423419
420
+ unlock:
421
+ mutex_unlock(&mdev->open_mutex);
424422 snd_use_lock_free(&mdev->use_lock);
425423 return 0;
426424 }