提交 8bb4d9ce 编写于 作者: T Takashi Iwai

ALSA: Fix card refcount unbalance

There are uncovered cases whether the card refcount introduced by the
commit a0830dbd isn't properly increased or decreased:
- OSS PCM and mixer success paths
- When lookup function gets NULL

This patch fixes these places.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=50251

Cc: <stable@vger.kernel.org>
Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 19a62823
...@@ -76,6 +76,7 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file) ...@@ -76,6 +76,7 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
snd_card_unref(card); snd_card_unref(card);
return -EFAULT; return -EFAULT;
} }
snd_card_unref(card);
return 0; return 0;
} }
......
...@@ -2454,6 +2454,7 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file) ...@@ -2454,6 +2454,7 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
mutex_unlock(&pcm->open_mutex); mutex_unlock(&pcm->open_mutex);
if (err < 0) if (err < 0)
goto __error; goto __error;
snd_card_unref(pcm->card);
return err; return err;
__error: __error:
......
...@@ -2122,7 +2122,8 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file) ...@@ -2122,7 +2122,8 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
pcm = snd_lookup_minor_data(iminor(inode), pcm = snd_lookup_minor_data(iminor(inode),
SNDRV_DEVICE_TYPE_PCM_PLAYBACK); SNDRV_DEVICE_TYPE_PCM_PLAYBACK);
err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK); err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK);
snd_card_unref(pcm->card); if (pcm)
snd_card_unref(pcm->card);
return err; return err;
} }
...@@ -2135,7 +2136,8 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file) ...@@ -2135,7 +2136,8 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file)
pcm = snd_lookup_minor_data(iminor(inode), pcm = snd_lookup_minor_data(iminor(inode),
SNDRV_DEVICE_TYPE_PCM_CAPTURE); SNDRV_DEVICE_TYPE_PCM_CAPTURE);
err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE); err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE);
snd_card_unref(pcm->card); if (pcm)
snd_card_unref(pcm->card);
return err; return err;
} }
......
...@@ -114,7 +114,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type) ...@@ -114,7 +114,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
mreg = snd_minors[minor]; mreg = snd_minors[minor];
if (mreg && mreg->type == type) { if (mreg && mreg->type == type) {
private_data = mreg->private_data; private_data = mreg->private_data;
if (mreg->card_ptr) if (private_data && mreg->card_ptr)
atomic_inc(&mreg->card_ptr->refcount); atomic_inc(&mreg->card_ptr->refcount);
} else } else
private_data = NULL; private_data = NULL;
......
...@@ -54,7 +54,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type) ...@@ -54,7 +54,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)
mreg = snd_oss_minors[minor]; mreg = snd_oss_minors[minor];
if (mreg && mreg->type == type) { if (mreg && mreg->type == type) {
private_data = mreg->private_data; private_data = mreg->private_data;
if (mreg->card_ptr) if (private_data && mreg->card_ptr)
atomic_inc(&mreg->card_ptr->refcount); atomic_inc(&mreg->card_ptr->refcount);
} else } else
private_data = NULL; private_data = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册