aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/pcm_native.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-10-16 07:05:59 -0400
committerTakashi Iwai <tiwai@suse.de>2012-10-30 06:07:10 -0400
commita0830dbd4e42b38aefdf3fb61ba5019a1a99ea85 (patch)
tree4dc74b708a07b56d12ed72a34d0a2e0cb8c8b9d4 /sound/core/pcm_native.c
parent888ea7d5ac6815ba16b3b3a20f665a92c7af6724 (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/pcm_native.c')
-rw-r--r--sound/core/pcm_native.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 8753c89f3290..48c6a70ad69e 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1642,6 +1642,7 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
1642 write_unlock_irq(&snd_pcm_link_rwlock); 1642 write_unlock_irq(&snd_pcm_link_rwlock);
1643 up_write(&snd_pcm_link_rwsem); 1643 up_write(&snd_pcm_link_rwsem);
1644 _nolock: 1644 _nolock:
1645 snd_card_unref(substream1->pcm->card);
1645 fput_light(file, fput_needed); 1646 fput_light(file, fput_needed);
1646 if (res < 0) 1647 if (res < 0)
1647 kfree(group); 1648 kfree(group);
@@ -2116,7 +2117,9 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
2116 return err; 2117 return err;
2117 pcm = snd_lookup_minor_data(iminor(inode), 2118 pcm = snd_lookup_minor_data(iminor(inode),
2118 SNDRV_DEVICE_TYPE_PCM_PLAYBACK); 2119 SNDRV_DEVICE_TYPE_PCM_PLAYBACK);
2119 return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK); 2120 err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK);
2121 snd_card_unref(pcm->card);
2122 return err;
2120} 2123}
2121 2124
2122static int snd_pcm_capture_open(struct inode *inode, struct file *file) 2125static int snd_pcm_capture_open(struct inode *inode, struct file *file)
@@ -2127,7 +2130,9 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file)
2127 return err; 2130 return err;
2128 pcm = snd_lookup_minor_data(iminor(inode), 2131 pcm = snd_lookup_minor_data(iminor(inode),
2129 SNDRV_DEVICE_TYPE_PCM_CAPTURE); 2132 SNDRV_DEVICE_TYPE_PCM_CAPTURE);
2130 return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE); 2133 err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE);
2134 snd_card_unref(pcm->card);
2135 return err;
2131} 2136}
2132 2137
2133static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) 2138static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream)