diff options
author | Takashi Iwai <tiwai@suse.de> | 2012-10-16 07:05:59 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2012-10-30 06:07:10 -0400 |
commit | a0830dbd4e42b38aefdf3fb61ba5019a1a99ea85 (patch) | |
tree | 4dc74b708a07b56d12ed72a34d0a2e0cb8c8b9d4 /sound/core/rawmidi.c | |
parent | 888ea7d5ac6815ba16b3b3a20f665a92c7af6724 (diff) |
ALSA: Add a reference counter to card instance
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>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core/rawmidi.c')
-rw-r--r-- | sound/core/rawmidi.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index ebf6e49ad3d4..7d4f62ab6711 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) | |||
379 | if (rmidi == NULL) | 379 | if (rmidi == NULL) |
380 | return -ENODEV; | 380 | return -ENODEV; |
381 | 381 | ||
382 | if (!try_module_get(rmidi->card->module)) | 382 | if (!try_module_get(rmidi->card->module)) { |
383 | snd_card_unref(rmidi->card); | ||
383 | return -ENXIO; | 384 | return -ENXIO; |
385 | } | ||
384 | 386 | ||
385 | mutex_lock(&rmidi->open_mutex); | 387 | mutex_lock(&rmidi->open_mutex); |
386 | card = rmidi->card; | 388 | card = rmidi->card; |
@@ -440,6 +442,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file) | |||
440 | #endif | 442 | #endif |
441 | file->private_data = rawmidi_file; | 443 | file->private_data = rawmidi_file; |
442 | mutex_unlock(&rmidi->open_mutex); | 444 | mutex_unlock(&rmidi->open_mutex); |
445 | snd_card_unref(rmidi->card); | ||
443 | return 0; | 446 | return 0; |
444 | 447 | ||
445 | __error: | 448 | __error: |
@@ -447,6 +450,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file) | |||
447 | __error_card: | 450 | __error_card: |
448 | mutex_unlock(&rmidi->open_mutex); | 451 | mutex_unlock(&rmidi->open_mutex); |
449 | module_put(rmidi->card->module); | 452 | module_put(rmidi->card->module); |
453 | snd_card_unref(rmidi->card); | ||
450 | return err; | 454 | return err; |
451 | } | 455 | } |
452 | 456 | ||