Skip to content

Commit b95bd3a

Browse files
committed
ALSA: pcm: Don't add internal PCMs to PCM device list
An internal PCM object shouldn't be added to the PCM device list, as it's never accessed directly from the user-space, and it has no proc or any similar accesses. Currently, it's excluded in snd_pcm_get() and snd_pcm_next(), but it's easier not to add such an object to the list. Actually, the whole snd_pcm_dev_register() can be skipped for an internal PCM. So this patch changes the code there, but also addresses the uninitialized list_head access. Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent ad876c8 commit b95bd3a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

sound/core/pcm.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ static struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
4949
struct snd_pcm *pcm;
5050

5151
list_for_each_entry(pcm, &snd_pcm_devices, list) {
52-
if (pcm->internal)
53-
continue;
5452
if (pcm->card == card && pcm->device == device)
5553
return pcm;
5654
}
@@ -62,8 +60,6 @@ static int snd_pcm_next(struct snd_card *card, int device)
6260
struct snd_pcm *pcm;
6361

6462
list_for_each_entry(pcm, &snd_pcm_devices, list) {
65-
if (pcm->internal)
66-
continue;
6763
if (pcm->card == card && pcm->device > device)
6864
return pcm->device;
6965
else if (pcm->card->number > card->number)
@@ -76,6 +72,9 @@ static int snd_pcm_add(struct snd_pcm *newpcm)
7672
{
7773
struct snd_pcm *pcm;
7874

75+
if (newpcm->internal)
76+
return 0;
77+
7978
list_for_each_entry(pcm, &snd_pcm_devices, list) {
8079
if (pcm->card == newpcm->card && pcm->device == newpcm->device)
8180
return -EBUSY;
@@ -782,6 +781,9 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
782781
pcm->card = card;
783782
pcm->device = device;
784783
pcm->internal = internal;
784+
mutex_init(&pcm->open_mutex);
785+
init_waitqueue_head(&pcm->open_wait);
786+
INIT_LIST_HEAD(&pcm->list);
785787
if (id)
786788
strlcpy(pcm->id, id, sizeof(pcm->id));
787789
if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
@@ -792,8 +794,6 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
792794
snd_pcm_free(pcm);
793795
return err;
794796
}
795-
mutex_init(&pcm->open_mutex);
796-
init_waitqueue_head(&pcm->open_wait);
797797
if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
798798
snd_pcm_free(pcm);
799799
return err;
@@ -1075,15 +1075,16 @@ static int snd_pcm_dev_register(struct snd_device *device)
10751075
if (snd_BUG_ON(!device || !device->device_data))
10761076
return -ENXIO;
10771077
pcm = device->device_data;
1078+
if (pcm->internal)
1079+
return 0;
1080+
10781081
mutex_lock(&register_mutex);
10791082
err = snd_pcm_add(pcm);
1080-
if (err) {
1081-
mutex_unlock(&register_mutex);
1082-
return err;
1083-
}
1083+
if (err)
1084+
goto unlock;
10841085
for (cidx = 0; cidx < 2; cidx++) {
10851086
int devtype = -1;
1086-
if (pcm->streams[cidx].substream == NULL || pcm->internal)
1087+
if (pcm->streams[cidx].substream == NULL)
10871088
continue;
10881089
switch (cidx) {
10891090
case SNDRV_PCM_STREAM_PLAYBACK:
@@ -1098,9 +1099,8 @@ static int snd_pcm_dev_register(struct snd_device *device)
10981099
&snd_pcm_f_ops[cidx], pcm,
10991100
&pcm->streams[cidx].dev);
11001101
if (err < 0) {
1101-
list_del(&pcm->list);
1102-
mutex_unlock(&register_mutex);
1103-
return err;
1102+
list_del_init(&pcm->list);
1103+
goto unlock;
11041104
}
11051105

11061106
for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
@@ -1110,8 +1110,9 @@ static int snd_pcm_dev_register(struct snd_device *device)
11101110
list_for_each_entry(notify, &snd_pcm_notify_list, list)
11111111
notify->n_register(pcm);
11121112

1113+
unlock:
11131114
mutex_unlock(&register_mutex);
1114-
return 0;
1115+
return err;
11151116
}
11161117

11171118
static int snd_pcm_dev_disconnect(struct snd_device *device)

0 commit comments

Comments
 (0)