Skip to content

Commit 8bb4d9c

Browse files
committed
ALSA: Fix card refcount unbalance
There are uncovered cases whether the card refcount introduced by the commit a0830db 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>
1 parent 19a6282 commit 8bb4d9c

5 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎sound/core/oss/mixer_oss.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
7676
snd_card_unref(card);
7777
return -EFAULT;
7878
}
79+
snd_card_unref(card);
7980
return 0;
8081
}
8182

‎sound/core/oss/pcm_oss.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,7 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
24542454
mutex_unlock(&pcm->open_mutex);
24552455
if (err < 0)
24562456
goto __error;
2457+
snd_card_unref(pcm->card);
24572458
return err;
24582459

24592460
__error:

‎sound/core/pcm_native.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,8 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
21222122
pcm = snd_lookup_minor_data(iminor(inode),
21232123
SNDRV_DEVICE_TYPE_PCM_PLAYBACK);
21242124
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);
21262127
return err;
21272128
}
21282129

@@ -2135,7 +2136,8 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file)
21352136
pcm = snd_lookup_minor_data(iminor(inode),
21362137
SNDRV_DEVICE_TYPE_PCM_CAPTURE);
21372138
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);
21392141
return err;
21402142
}
21412143

‎sound/core/sound.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
114114
mreg = snd_minors[minor];
115115
if (mreg && mreg->type == type) {
116116
private_data = mreg->private_data;
117-
if (mreg->card_ptr)
117+
if (private_data && mreg->card_ptr)
118118
atomic_inc(&mreg->card_ptr->refcount);
119119
} else
120120
private_data = NULL;

‎sound/core/sound_oss.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)
5454
mreg = snd_oss_minors[minor];
5555
if (mreg && mreg->type == type) {
5656
private_data = mreg->private_data;
57-
if (mreg->card_ptr)
57+
if (private_data && mreg->card_ptr)
5858
atomic_inc(&mreg->card_ptr->refcount);
5959
} else
6060
private_data = NULL;

0 commit comments

Comments
 (0)