]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ALSA: seq: oss: Fix unbalanced use lock for synth MIDI device
authorTakashi Iwai <tiwai@suse.de>
Tue, 24 Apr 2018 05:26:59 +0000 (07:26 +0200)
committerSasha Levin <alexander.levin@microsoft.com>
Wed, 23 May 2018 01:36:38 +0000 (21:36 -0400)
[ Upstream commit f5e94b4c6ebdabe0f602d796e0430180927521a0 ]

When get_synthdev() is called for a MIDI device, it returns the fixed
midi_synth_dev without the use refcounting.  OTOH, the caller is
supposed to unreference unconditionally after the usage, so this would
lead to unbalanced refcount.

This patch corrects the behavior and keep up the refcount balance also
for the MIDI synth device.

Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
sound/core/seq/oss/seq_oss_synth.c

index f38cf91b4faf3979ac7a6c5740613c11ed956dc2..e30a43efb2ad8720e587d8df12c41f604346a420 100644 (file)
@@ -363,10 +363,14 @@ get_synthdev(struct seq_oss_devinfo *dp, int dev)
                return NULL;
        if (! dp->synths[dev].opened)
                return NULL;
-       if (dp->synths[dev].is_midi)
-               return &midi_synth_dev;
-       if ((rec = get_sdev(dev)) == NULL)
-               return NULL;
+       if (dp->synths[dev].is_midi) {
+               rec = &midi_synth_dev;
+               snd_use_lock_use(&rec->use_lock);
+       } else {
+               rec = get_sdev(dev);
+               if (!rec)
+                       return NULL;
+       }
        if (! rec->opened) {
                snd_use_lock_free(&rec->use_lock);
                return NULL;