Skip to content

Commit a8ff48c

Browse files
committed
ALSA: pcm: Free chmap at PCM free callback, too
The chmap ctls assigned to PCM streams are freed in the PCM disconnect callback. However, since the disconnect callback isn't called when the card gets freed before registering, the chmap ctls may still be left assigned. They are eventually freed together with other ctls, but it may cause an Oops at pcm_chmap_ctl_private_free(), as the function refers to the assigned PCM stream, while the PCM objects have been already freed beforehand. The fix is to free the chmap ctls also at PCM free callback, not only at PCM disconnect. Reported-by: Laxminath Kasam <[email protected]> Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent f388cdc commit a8ff48c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

sound/core/pcm.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,14 @@ int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
849849
}
850850
EXPORT_SYMBOL(snd_pcm_new_internal);
851851

852+
static void free_chmap(struct snd_pcm_str *pstr)
853+
{
854+
if (pstr->chmap_kctl) {
855+
snd_ctl_remove(pstr->pcm->card, pstr->chmap_kctl);
856+
pstr->chmap_kctl = NULL;
857+
}
858+
}
859+
852860
static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
853861
{
854862
struct snd_pcm_substream *substream, *substream_next;
@@ -871,6 +879,7 @@ static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
871879
kfree(setup);
872880
}
873881
#endif
882+
free_chmap(pstr);
874883
if (pstr->substream_count)
875884
put_device(&pstr->dev);
876885
}
@@ -1135,10 +1144,7 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
11351144
for (cidx = 0; cidx < 2; cidx++) {
11361145
if (!pcm->internal)
11371146
snd_unregister_device(&pcm->streams[cidx].dev);
1138-
if (pcm->streams[cidx].chmap_kctl) {
1139-
snd_ctl_remove(pcm->card, pcm->streams[cidx].chmap_kctl);
1140-
pcm->streams[cidx].chmap_kctl = NULL;
1141-
}
1147+
free_chmap(&pcm->streams[cidx]);
11421148
}
11431149
mutex_unlock(&pcm->open_mutex);
11441150
mutex_unlock(&register_mutex);

0 commit comments

Comments
 (0)