aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-11-08 08:36:18 -0500
committerTakashi Iwai <tiwai@suse.de>2012-11-08 08:36:18 -0500
commit8bb4d9ce08b0a92ca174e41d92c180328f86173f (patch)
treeed2d1ed4e401736de2cc67f8660d43b156d3a0b4 /sound/core
parent19a62823eae453619604636082085812c14ee391 (diff)
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: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/oss/mixer_oss.c1
-rw-r--r--sound/core/oss/pcm_oss.c1
-rw-r--r--sound/core/pcm_native.c6
-rw-r--r--sound/core/sound.c2
-rw-r--r--sound/core/sound_oss.c2
5 files changed, 8 insertions, 4 deletions
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index a9a2e63c0222..e8a1d18774b2 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -76,6 +76,7 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
76 snd_card_unref(card); 76 snd_card_unref(card);
77 return -EFAULT; 77 return -EFAULT;
78 } 78 }
79 snd_card_unref(card);
79 return 0; 80 return 0;
80} 81}
81 82
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index f337b66a020b..4c1cc51772e6 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -2454,6 +2454,7 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
2454 mutex_unlock(&pcm->open_mutex); 2454 mutex_unlock(&pcm->open_mutex);
2455 if (err < 0) 2455 if (err < 0)
2456 goto __error; 2456 goto __error;
2457 snd_card_unref(pcm->card);
2457 return err; 2458 return err;
2458 2459
2459 __error: 2460 __error:
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 6e8872de5ba0..f9ddecf2f4cd 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -2122,7 +2122,8 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
2122 pcm = snd_lookup_minor_data(iminor(inode), 2122 pcm = snd_lookup_minor_data(iminor(inode),
2123 SNDRV_DEVICE_TYPE_PCM_PLAYBACK); 2123 SNDRV_DEVICE_TYPE_PCM_PLAYBACK);
2124 err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK); 2124 err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK);
2125 snd_card_unref(pcm->card); 2125 if (pcm)
2126 snd_card_unref(pcm->card);
2126 return err; 2127 return err;
2127} 2128}
2128 2129
@@ -2135,7 +2136,8 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file)
2135 pcm = snd_lookup_minor_data(iminor(inode), 2136 pcm = snd_lookup_minor_data(iminor(inode),
2136 SNDRV_DEVICE_TYPE_PCM_CAPTURE); 2137 SNDRV_DEVICE_TYPE_PCM_CAPTURE);
2137 err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE); 2138 err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE);
2138 snd_card_unref(pcm->card); 2139 if (pcm)
2140 snd_card_unref(pcm->card);
2139 return err; 2141 return err;
2140} 2142}
2141 2143
diff --git a/sound/core/sound.c b/sound/core/sound.c
index 89780c323f19..70ccdab74153 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -114,7 +114,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
114 mreg = snd_minors[minor]; 114 mreg = snd_minors[minor];
115 if (mreg && mreg->type == type) { 115 if (mreg && mreg->type == type) {
116 private_data = mreg->private_data; 116 private_data = mreg->private_data;
117 if (mreg->card_ptr) 117 if (private_data && mreg->card_ptr)
118 atomic_inc(&mreg->card_ptr->refcount); 118 atomic_inc(&mreg->card_ptr->refcount);
119 } else 119 } else
120 private_data = NULL; 120 private_data = NULL;
diff --git a/sound/core/sound_oss.c b/sound/core/sound_oss.c
index e1d79ee35906..726a49ac9725 100644
--- a/sound/core/sound_oss.c
+++ b/sound/core/sound_oss.c
@@ -54,7 +54,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)
54 mreg = snd_oss_minors[minor]; 54 mreg = snd_oss_minors[minor];
55 if (mreg && mreg->type == type) { 55 if (mreg && mreg->type == type) {
56 private_data = mreg->private_data; 56 private_data = mreg->private_data;
57 if (mreg->card_ptr) 57 if (private_data && mreg->card_ptr)
58 atomic_inc(&mreg->card_ptr->refcount); 58 atomic_inc(&mreg->card_ptr->refcount);
59 } else 59 } else
60 private_data = NULL; 60 private_data = NULL;