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/hwdep.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/hwdep.c')
-rw-r--r-- | sound/core/hwdep.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c index 75ea16f35b1a..53a6ba5ad615 100644 --- a/sound/core/hwdep.c +++ b/sound/core/hwdep.c | |||
@@ -100,8 +100,10 @@ static int snd_hwdep_open(struct inode *inode, struct file * file) | |||
100 | if (hw == NULL) | 100 | if (hw == NULL) |
101 | return -ENODEV; | 101 | return -ENODEV; |
102 | 102 | ||
103 | if (!try_module_get(hw->card->module)) | 103 | if (!try_module_get(hw->card->module)) { |
104 | snd_card_unref(hw->card); | ||
104 | return -EFAULT; | 105 | return -EFAULT; |
106 | } | ||
105 | 107 | ||
106 | init_waitqueue_entry(&wait, current); | 108 | init_waitqueue_entry(&wait, current); |
107 | add_wait_queue(&hw->open_wait, &wait); | 109 | add_wait_queue(&hw->open_wait, &wait); |
@@ -148,6 +150,7 @@ static int snd_hwdep_open(struct inode *inode, struct file * file) | |||
148 | mutex_unlock(&hw->open_mutex); | 150 | mutex_unlock(&hw->open_mutex); |
149 | if (err < 0) | 151 | if (err < 0) |
150 | module_put(hw->card->module); | 152 | module_put(hw->card->module); |
153 | snd_card_unref(hw->card); | ||
151 | return err; | 154 | return err; |
152 | } | 155 | } |
153 | 156 | ||