aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/rawmidi.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-10-16 13:05:59 +0200
committerBen Hutchings <ben@decadent.org.uk>2012-11-16 16:46:50 +0000
commit3b4a36722e5e518e4bdd3a215d8a1c5adc18e911 (patch)
tree3db0ebb96a886ce6ff3c91e60510a03b561a20bc /sound/core/rawmidi.c
parentf6415ce55f2430e38f674d8421511e489b2c71b0 (diff)
downloadkernel_samsung_smdk4412-3b4a36722e5e518e4bdd3a215d8a1c5adc18e911.zip
kernel_samsung_smdk4412-3b4a36722e5e518e4bdd3a215d8a1c5adc18e911.tar.gz
kernel_samsung_smdk4412-3b4a36722e5e518e4bdd3a215d8a1c5adc18e911.tar.bz2
ALSA: Add a reference counter to card instance
commit a0830dbd4e42b38aefdf3fb61ba5019a1a99ea85 upstream. For more strict protection for wild disconnections, a refcount is introduced to the card instance, and let it up/down when an object is referred via snd_lookup_*() in the open ops. The free-after-last-close check is also changed to check this refcount instead of the empty list, too. Reported-by: Matthieu CASTET <matthieu.castet@parrot.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'sound/core/rawmidi.c')
-rw-r--r--sound/core/rawmidi.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index ebf6e49..7d4f62a 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -379,8 +379,10 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
if (rmidi == NULL)
return -ENODEV;
- if (!try_module_get(rmidi->card->module))
+ if (!try_module_get(rmidi->card->module)) {
+ snd_card_unref(rmidi->card);
return -ENXIO;
+ }
mutex_lock(&rmidi->open_mutex);
card = rmidi->card;
@@ -440,6 +442,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
#endif
file->private_data = rawmidi_file;
mutex_unlock(&rmidi->open_mutex);
+ snd_card_unref(rmidi->card);
return 0;
__error:
@@ -447,6 +450,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
__error_card:
mutex_unlock(&rmidi->open_mutex);
module_put(rmidi->card->module);
+ snd_card_unref(rmidi->card);
return err;
}